Skip to content

Commit

Permalink
windows, rewrite project
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanclouser committed Apr 24, 2023
1 parent d2ab550 commit 5e56d06
Show file tree
Hide file tree
Showing 21 changed files with 1,440 additions and 245 deletions.
1,046 changes: 1,046 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions CMakeLists.txt

This file was deleted.

24 changes: 0 additions & 24 deletions LICENSE

This file was deleted.

7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 ProjectHax LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
101 changes: 33 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,48 @@
pySilkroadSecurity
==================
===

pySilkroadSecurity exposes Drew's SilkroadSecurity API to Python 3.2 and above. It does not implement the API in Python code.

Requirements
------------
Windows
---

1. Linux or Mac OSX
2. Python 3.2+
3. boost
4. git
5. cmake
Precompiled Boost.Python 1.82 and pySilkroadSecurity libs for Python 3.11.2 x64 are included for Windows in the `python` directory. You will need [vcredist x64](https://aka.ms/vs/17/release/vc_redist.x64.exe) if VS 2022 is not installed.

Debian 7
--------
1. Download and install [Python 3.x x64](https://www.python.org/downloads/)
1. Download and extract [boost](https://www.boost.org/)
1. Open `x86 Native Tools Command Prompt for VS 2022`
1. Change to the extract boost directory
1. Run `bootstrap.bat`
1. Run `b2 -j8 --build-type=complete stage`

1. apt-get update && apt-get upgrade
2. apt-get install build-essential python3.2 python3.2-dev libboost-all-dev git cmake
**Compiling**

Ubuntu 14.04
------------

1. apt-get update && apt-get upgrade
2. apt-get install build-essential python3-dev libboost-dev git cmake

Fedora 20
---------

1. yum update
2. yum install gcc-c++ boost boost-devel boost-python3 boost-python3-devel python3-devel cmake

Arch
----

Make sure you have `base-devel` already installed.

1. pacman -Syu
2. pacman -S python3 boost git cmake

RaspberryPi (Raspbian)
----------------------

1. Follow the Debian 7 guide.
2. Use a single thread to compile

Mac OSX 10.11
-------------
1. `git clone https://github.com/ProjectHax/pySilkroadSecurity.git`
1. Open `pySilkroadSecurity.sln`
1. Edit the VC++ directories for boost and Python
1. Compile
1. Copy `boost_python311-vc143-mt-x64-1_82.dll` from `boost/stage/lib` to the Python script folder
1. Copy `x64/Release/pySilkroadSecurity.pyd` to your Python script folder

This will be a complete guide since the steps are quite different for compiling. You will need to update the Python version in the cmake string when 3.5+ is released.
*nix
---

1. `brew install boost`
2. `brew install python3`
3. `brew install boost-python --with-python3 --c++11`
4. `git clone https://github.com/ProjectHax/pySilkroadSecurity.git`
5. `cd pySilkroadSecurity/`
6. ```cmake -DPYTHON_INCLUDE_DIR=`python3-config --prefix`/include/python3.5m -DPYTHON_LIBRARY=`python3-config --prefix`/lib/libpython3.5m.dylib -DPython_FRAMEWORKS=`python3-config --prefix````
7. `make -j4`
8. `cd python/`
9. `python3 pySilkroadStats.py`
1. Install cmake, boost, python3 dev packages
1. `git clone https://github.com/ProjectHax/pySilkroadSecurity.git`
1. `cd src`
1. `mkdir build && cd build`
1. `cmake ..`
1. `make`

Compiling
=========
macOS
---

1. `git clone https://github.com/ProjectHax/pySilkroadSecurity.git`
2. `cd pySilkroadSecurity/`
3. `cmake .`
4. `make -j4`
5. `cd python/`
6. `python3 pySilkroadStats.py`
1. Install [Homebrew](https://brew.sh/)
1. `brew install python3 boost boost-python3 cmake`
1. Follow the `*nix` steps

Examples
========
---

**pySilkroadStats.py**

Expand All @@ -81,18 +53,11 @@ This small project shows you how the SilkroadSecurity API is to be used from Pyt
This project accepts connections on TCP port 15779 and will create a proxy between the Silkroad client and the Silkroad game servers. This will allow you to view all packets going to and from Silkroad. This project can also be easily modified to filter packets for a private server; although, I would recommend rewriting the network code to not use select() if you end up needing to handle more than 100 simultaneous connections.

Usage in Your Own Project
-------------------------
---

Copy pySilkroadSecurity.so and stream.py to your own project folder and import them like so:

```
from pySilkroadSecurity import SilkroadSecurity
from stream import *
```

Warnings
========

* iSRO/SilkroadR client will crash after loading the game world if HackShield is disabled using edxSilkroadLoader5 (it's missing one client patch that was added recently)
* Stream classes have not been extensively tested/used and may have bugs
* With some modifications it can work under Python 2.7.X (it was originally written for 2.7.X)
```
Binary file added python/boost_python311-vc143-mt-x64-1_82.dll
Binary file not shown.
Binary file added python/pySilkroadSecurity.pyd
Binary file not shown.
19 changes: 7 additions & 12 deletions python/pySilkroadStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def HandlePacket(security, packet):
w.write_uint8(18)
w.write_uint16(9)
w.write_ascii('SR_Client')
w.write_uint32(432)
w.write_uint32(600)
security.Send(0x6100, w.tolist(), True)

elif packet['opcode'] == 0xA100:
Expand All @@ -30,25 +30,20 @@ def HandlePacket(security, packet):

elif packet['opcode'] == 0xA101:

entry = r.read_uint8()
while entry == 1:
while r.read_uint8() == 1:
r.read_uint8()
print(r.read_ascii(r.read_uint16()))
entry = r.read_uint8()

print('')
print()

entry = r.read_uint8()
while entry == 1:
while r.read_uint8() == 1:
server_id = r.read_uint16()

name = r.read_ascii(r.read_uint16())
capacity = r.read_float()
state = r.read_uint8()
open = r.read_uint8()

print('[%s] %f' % (name, capacity * 100))

entry = r.read_uint8()
print('[{}] {}'.format(name, 'Open' if open == 1 else 'Closed'))

def main():
security = SilkroadSecurity()
Expand Down Expand Up @@ -92,7 +87,7 @@ def main():
else:
raise e
except KeyboardInterrupt:
''''''
pass

# Cleanup
s.shutdown(socket.SHUT_RDWR)
Expand Down
28 changes: 28 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.2)

project(pySilkroadSecurity)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../../python/)

set(CMAKE_C_FLAGS "-std=c++17 -O3 -fPIC")
set(CMAKE_CXX__FLAGS "-std=c++17 -O3 -fPIC")

find_package(Python3 COMPONENTS Interpreter Development)
find_package(Boost 1.70 COMPONENTS python REQUIRED)

include_directories(${Python3_INCLUDE_DIRS})
link_directories(${Python3_LIBRARIES})

set(HEADER_FILES pch.h)
set(SOURCE_FILES main.cpp security/blowfish.cpp security/stream_utility.cpp security/silkroad_security.cpp)
include_directories(. security)

add_library(pySilkroadSecurity SHARED ${SOURCE_FILES})
target_link_libraries(pySilkroadSecurity ${Boost_LIBRARIES} ${Python3_LIBRARIES})

set_target_properties(pySilkroadSecurity PROPERTIES PREFIX "")

if (APPLE)
set_property(TARGET pySilkroadSecurity PROPERTY OUTPUT_NAME "pySilkroadSecurity.so")
set_property(TARGET pySilkroadSecurity PROPERTY SUFFIX "")
endif()
Loading

0 comments on commit 5e56d06

Please sign in to comment.