feat: Removed CPython separate compilation

+ Upgraded to Python 3.13
+ Added constants to g2o library for auto-completion
This commit is contained in:
AURUMVORXX
2024-11-25 04:56:46 +03:00
parent 8efb8c2125
commit d779d0a661
21 changed files with 175 additions and 109 deletions

View File

@@ -34,19 +34,17 @@ jobs:
- name: Install Python - name: Install Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.12' python-version: '3.13'
- name: Install CMake - name: Install CMake
uses: lukka/get-cmake@latest uses: lukka/get-cmake@latest
- name: Init submodules - name: Init submodules
run: git submodule update --init --recursive run: git submodule update --init --recursive
- name: Build CPython libraries
run: dependencies/cpython/PCbuild/build.bat
- name: CMake - Configure - name: CMake - Configure
run: cmake . --preset Windows-x64-Release -DCMAKE_BUILD_TYPE="Release" -DCOUT_FILE_SUFFIX="x64" run: cmake . --preset Windows-x64-Release -DCMAKE_BUILD_TYPE="Release" -DCOUT_FILE_SUFFIX="x64"
- name: CMake - Build - name: CMake - Build
run: cmake --build --preset Windows-x64-Release run: cmake --build --preset Windows-x64-Release
- name: Archive output files - name: Archive output files
run: Compress-Archive -Path "out/build/Windows-x64-Release/lib", "g2o", "out/build/Windows-x64-Release/PyG2O.x64.dll", "out/build/Windows-x64-Release/python312.dll" -Destination Windows-x64-Release.zip run: Compress-Archive -Path "g2o", "out/build/Windows-x64-Release/PyG2O.x64.dll" -Destination Windows-x64-Release.zip
- name: Upload release - name: Upload release
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:
@@ -67,7 +65,7 @@ jobs:
- name: Install Python - name: Install Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.12-dev' python-version: '3.13'
- name: Install CMake - name: Install CMake
uses: lukka/get-cmake@latest uses: lukka/get-cmake@latest
- name: Init submodules - name: Init submodules
@@ -76,15 +74,10 @@ jobs:
run: cmake . --preset Linux-x64-Release -DCMAKE_BUILD_TYPE="Release" -DCOUT_FILE_SUFFIX="x64" run: cmake . --preset Linux-x64-Release -DCMAKE_BUILD_TYPE="Release" -DCOUT_FILE_SUFFIX="x64"
- name: CMake - Build - name: CMake - Build
run: cmake --build --preset Linux-x64-Release run: cmake --build --preset Linux-x64-Release
- name: Move release files
run: |
mv out/build/Linux-x64-Release/lib ./
mv out/build/Linux-x64-Release/PyG2O.x64.so ./
mv out/build/Linux-x64-Release/libpython3.12.so ./
- name: Archive files - name: Archive files
uses: montudor/action-zip@v1 uses: montudor/action-zip@v1
with: with:
args: zip -r Linux-x64-Release.zip g2o lib PyG2O.x64.so libpython3.12.so args: zip -r Linux-x64-Release.zip g2o out/build/Linux-x64-Release/PyG2O.x64.so
- name: Upload release - name: Upload release
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:

6
.gitmodules vendored
View File

@@ -5,8 +5,4 @@
[submodule "dependencies/pybind11"] [submodule "dependencies/pybind11"]
path = dependencies/pybind11 path = dependencies/pybind11
url = https://github.com/pybind/pybind11.git url = https://github.com/pybind/pybind11.git
branch = master branch = master
[submodule "dependencies/cpython"]
path = dependencies/cpython
url = https://github.com/python/cpython
branch = 3.12

View File

@@ -5,62 +5,6 @@ project(PyG2O)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Specify build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(CPYTHON_BUILD_TYPE Debug)
else ()
set(CPYTHON_BUILD_TYPE Release)
endif()
# Add the cpython as an external project that will be included in the build
if(MSVC)
if(CMAKE_CL_64)
set(CPYTHON_PLATFORM x64)
set(CPYTHON_BUILD_DIR amd64)
else()
set(CPYTHON_PLATFORM x86)
set(CPYTHON_BUILD_DIR win32)
endif()
ExternalProject_Add(CPYTHON
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CMAKE_SOURCE_DIR}/dependencies/cpython
CONFIGURE_COMMAND ""
BUILD_COMMAND cd ${CMAKE_SOURCE_DIR}/dependencies/cpython && MSBuild.exe /p:Configuration=${CPYTHON_BUILD_TYPE} /property:Platform=${CPYTHON_PLATFORM} "PCBuild/python.vcxproj" /nologo /verbosity:minimal /consoleloggerparameters:summar
INSTALL_COMMAND ""
TEST_COMMAND ""
)
else()
ExternalProject_Add(CPYTHON
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CMAKE_SOURCE_DIR}/dependencies/cpython
CONFIGURE_COMMAND cd ${CMAKE_SOURCE_DIR}/dependencies/cpython && ./configure --disable-static --enable-shared
BUILD_COMMAND cd ${CMAKE_SOURCE_DIR}/dependencies/cpython && make
INSTALL_COMMAND ""
TEST_COMMAND ""
)
endif()
set(CPYTHON_STDLIB_DIR ${CMAKE_SOURCE_DIR}/dependencies/cpython/Lib)
if(MSVC)
set(CPYTHON_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dependencies/cpython/Include ${CMAKE_SOURCE_DIR}/dependencies/cpython/PC)
set(CPYTHON_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/dependencies/cpython/PCBuild/${CPYTHON_BUILD_DIR})
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(CPYTHON_BIN ${CMAKE_SOURCE_DIR}/dependencies/cpython/PCBuild/${CPYTHON_BUILD_DIR}/python312_d.dll)
else()
set(CPYTHON_BIN ${CMAKE_SOURCE_DIR}/dependencies/cpython/PCBuild/${CPYTHON_BUILD_DIR}/python312.dll)
endif()
else()
set(CPYTHON_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dependencies/cpython/Include ${CMAKE_SOURCE_DIR}/dependencies/cpython)
set(CPYTHON_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/dependencies/cpython)
set(CPYTHON_LIBRARY python3.12)
set(CPYTHON_BIN /opt/hostedtoolcache/Python/3.12.7/x64/lib/libpython3.12.so)
endif()
file(GLOB_RECURSE SOURCE file(GLOB_RECURSE SOURCE
"include/*.h" "include/*.h"
@@ -82,14 +26,8 @@ file(GLOB_RECURSE SOURCE
"src/events/*.cpp" "src/events/*.cpp"
) )
# Linking directories
link_directories(${CPYTHON_LIBRARY_DIR})
add_library(${PROJECT_NAME} SHARED ${SOURCE}) add_library(${PROJECT_NAME} SHARED ${SOURCE})
# Dependencies
add_dependencies(${PROJECT_NAME} CPYTHON)
target_compile_definitions(${PROJECT_NAME} target_compile_definitions(${PROJECT_NAME}
PRIVATE PRIVATE
SCRAT_EXPORT SCRAT_EXPORT
@@ -111,29 +49,4 @@ if(DEFINED OUT_FILE_SUFFIX)
endif() endif()
add_subdirectory(dependencies) add_subdirectory(dependencies)
target_link_libraries(${PROJECT_NAME} PRIVATE ${CPYTHON_LIBRARY}) target_link_libraries(${PROJECT_NAME} PRIVATE pybind11::embed)
target_link_libraries(${PROJECT_NAME} PRIVATE pybind11::embed)
# Copy Python DLL to the build folder if different
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_if_different ${CPYTHON_BIN} $<TARGET_FILE_DIR:${PROJECT_NAME}>
)
# Copy the Python stdlib into the build folder (needed by the embedded python)
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_directory ${CPYTHON_STDLIB_DIR} $<TARGET_FILE_DIR:${PROJECT_NAME}>/lib
)
# Copy the PyG2O library into the build/lib folder
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_directory ${CMAKE_SOURCE_DIR}/g2o $<TARGET_FILE_DIR:${PROJECT_NAME}>/lib/g2o
)

Submodule dependencies/cpython deleted from b59269961f

View File

@@ -1,6 +1,8 @@
## How to use ## How to use
1. Install [Python 3.13](https://www.python.org/downloads/release/python-3130/)
*Optionally, for Windows instead of installing Python, you can download Windows embeddable package from Python download page, and extract ZIP into your server folder*
1. Download latest module version from the **Release** page 1. Download latest module version from the **Release** page
2. Unzip downloaded archive into your server directory (you should now have **PyG2O.xYY.dll**, **python312.dll**, **libs/** and **g2o/** in your root server directory, or similar `.so` files if you're using linux) 2. Unzip downloaded archive into your server directory (you should now have **PyG2O.xYY.dll** and **g2o/** in your root server directory, or similar `.so` file if you're using linux)
3. Place .DLL module in the place you want and connect it with **config.xml** 3. Place .DLL module in the place you want and connect it with **config.xml**
```xml ```xml
<module src="PyG2O.x64.dll" type="server" /> <module src="PyG2O.x64.dll" type="server" />

View File

@@ -1,9 +1,9 @@
## QnA ## QnA
### 1. Do I need to install Python to use it? ### 1. Do I need to install Python to use it?
No, Python interpreter is already inside the module and will run your code as normal, if you installed and connected the module properly. Yes.
### 2. Can I use external Python libraries? ### 2. Can I use external Python libraries?
Yes, but you need to put them inside ``lib/`` folder in your server root directory. Yes, you can install it as usual (for example, via *pip*)
### 3. Can I use it as client-side module? ### 3. Can I use it as client-side module?
No, it doesn't support any client-side functionality, and there's no plans to add it for now due to security reasons and technical difficulties with client-side C++ modules. No, it doesn't support any client-side functionality, and there's no plans to add it for now due to security reasons and technical difficulties with client-side C++ modules.

View File

@@ -152,4 +152,4 @@ from g2o.functions.streamer import getSpawnedPlayersForPlayer
from g2o.functions.waypoint import getNearestWaypoint from g2o.functions.waypoint import getNearestWaypoint
from g2o.functions.waypoint import getWaypoint from g2o.functions.waypoint import getWaypoint
from sqg2oconst import * from g2o.constants import *

13
g2o/constants/__init__.py Normal file
View File

@@ -0,0 +1,13 @@
from .anticheat import *
from .context import *
from .damage import *
from .general import *
from .hand import *
from .item import *
from .network import *
from .npc import *
from .reliability import *
from .skillweapon import *
from .talent import *
from .weaponmode import *
from .weather import *

View File

@@ -0,0 +1,3 @@
import sqg2oconst
AC_SPEED_HACK = sqg2oconst.AC_SPEED_HACK

4
g2o/constants/context.py Normal file
View File

@@ -0,0 +1,4 @@
import sqg2oconst
DAMAGE_CTX = sqg2oconst.DAMAGE_CTX
EQUIPMENT_CTX = sqg2oconst.EQUIPMENT_CTX

11
g2o/constants/damage.py Normal file
View File

@@ -0,0 +1,11 @@
import sqg2oconst
DAMAGE_UNKNOWN = sqg2oconst.DAMAGE_UNKNOWN
DAMAGE_BARRIER = sqg2oconst.DAMAGE_BARRIER
DAMAGE_BLUNT = sqg2oconst.DAMAGE_BLUNT
DAMAGE_EDGE = sqg2oconst.DAMAGE_EDGE
DAMAGE_FIRE = sqg2oconst.DAMAGE_FIRE
DAMAGE_FLY = sqg2oconst.DAMAGE_FLY
DAMAGE_MAGIC = sqg2oconst.DAMAGE_MAGIC
DAMAGE_POINT = sqg2oconst.DAMAGE_POINT
DAMAGE_FALL = sqg2oconst.DAMAGE_FALL

5
g2o/constants/general.py Normal file
View File

@@ -0,0 +1,5 @@
import sqg2oconst
DEBUG_MODE = sqg2oconst.DEBUG_MODE
CLIENT_SIDE = sqg2oconst.CLIENT_SIDE
SERVER_SIDE = sqg2oconst.SERVER_SIDE

4
g2o/constants/hand.py Normal file
View File

@@ -0,0 +1,4 @@
import sqg2oconst
HAND_LEFT = sqg2oconst.HAND_LEFT
HAND_RIGHT = sqg2oconst.HAND_RIGHT

38
g2o/constants/item.py Normal file
View File

@@ -0,0 +1,38 @@
import sqg2oconst
ITEM_CAT_NONE = sqg2oconst.ITEM_CAT_NONE
ITEM_CAT_NF = sqg2oconst.ITEM_CAT_NF
ITEM_CAT_FF = sqg2oconst.ITEM_CAT_FF
ITEM_CAT_MUN = sqg2oconst.ITEM_CAT_MUN
ITEM_CAT_ARMOR = sqg2oconst.ITEM_CAT_ARMOR
ITEM_CAT_FOOD = sqg2oconst.ITEM_CAT_FOOD
ITEM_CAT_DOCS = sqg2oconst.ITEM_CAT_DOCS
ITEM_CAT_POTION = sqg2oconst.ITEM_CAT_POTION
ITEM_CAT_LIGHT = sqg2oconst.ITEM_CAT_LIGHT
ITEM_CAT_RUNE = sqg2oconst.ITEM_CAT_RUNE
ITEM_CAT_MAGIC = sqg2oconst.ITEM_CAT_MAGIC
ITEM_FLAG_DAG = sqg2oconst.ITEM_FLAG_DAG
ITEM_FLAG_SWD = sqg2oconst.ITEM_FLAG_SWD
ITEM_FLAG_AXE = sqg2oconst.ITEM_FLAG_AXE
ITEM_FLAG_2HD_SWD = sqg2oconst.ITEM_FLAG_2HD_SWD
ITEM_FLAG_2HD_AXE = sqg2oconst.ITEM_FLAG_2HD_AXE
ITEM_FLAG_SHIELD = sqg2oconst.ITEM_FLAG_SHIELD
ITEM_FLAG_BOW = sqg2oconst.ITEM_FLAG_BOW
ITEM_FLAG_CROSSBOW = sqg2oconst.ITEM_FLAG_CROSSBOW
ITEM_FLAG_RING = sqg2oconst.ITEM_FLAG_RING
ITEM_FLAG_AMULET = sqg2oconst.ITEM_FLAG_AMULET
ITEM_FLAG_BELT = sqg2oconst.ITEM_FLAG_BELT
ITEM_FLAG_DROPPED = sqg2oconst.ITEM_FLAG_DROPPED
ITEM_FLAG_MI = sqg2oconst.ITEM_FLAG_MI
ITEM_FLAG_MULTI = sqg2oconst.ITEM_FLAG_MULTI
ITEM_FLAG_NFOCUS = sqg2oconst.ITEM_FLAG_NFOCUS
ITEM_FLAG_CREATEAMMO = sqg2oconst.ITEM_FLAG_CREATEAMMO
ITEM_FLAG_NSPLIT = sqg2oconst.ITEM_FLAG_NSPLIT
ITEM_FLAG_DRINK = sqg2oconst.ITEM_FLAG_DRINK
ITEM_FLAG_TORCH = sqg2oconst.ITEM_FLAG_TORCH
ITEM_FLAG_THROW = sqg2oconst.ITEM_FLAG_THROW
ITEM_FLAG_ACTIVE = sqg2oconst.ITEM_FLAG_ACTIVE
ITEM_WEAR_NO = sqg2oconst.ITEM_WEAR_NO
ITEM_WEAR_TORSO = sqg2oconst.ITEM_WEAR_TORSO
ITEM_WEAR_HEAD = sqg2oconst.ITEM_WEAR_HEAD
ITEM_WEAR_LIGHT = sqg2oconst.ITEM_WEAR_LIGHT

5
g2o/constants/network.py Normal file
View File

@@ -0,0 +1,5 @@
import sqg2oconst
DISCONNECTED = sqg2oconst.DISCONNECTED
LOST_CONNECTION = sqg2oconst.LOST_CONNECTION
HAS_CRASHED = sqg2oconst.HAS_CRASHED

28
g2o/constants/npc.py Normal file
View File

@@ -0,0 +1,28 @@
import sqg2oconst
ATTACK_RUN = sqg2oconst.ATTACK_RUN
ATTACK_FORWARD = sqg2oconst.ATTACK_FORWARD
ATTACK_LEFT = sqg2oconst.ATTACK_LEFT
ATTACK_RIGHT = sqg2oconst.ATTACK_RIGHT
ACTION_CLEAR_QUEUE = sqg2oconst.ACTION_CLEAR_QUEUE
ACTION_APPLY_OVERLAY = sqg2oconst.ACTION_APPLY_OVERLAY
ACTION_REMOVE_OVERLAY = sqg2oconst.ACTION_REMOVE_OVERLAY
ACTION_PLAY_ANI = sqg2oconst.ACTION_PLAY_ANI
ACTION_STOP_ANI = sqg2oconst.ACTION_STOP_ANI
ACTION_EQUIP_ITEM = sqg2oconst.ACTION_EQUIP_ITEM
ACTION_UNEQUIP_ITEM = sqg2oconst.ACTION_UNEQUIP_ITEM
ACTION_WEAPON_MODE = sqg2oconst.ACTION_WEAPON_MODE
ACTION_DRAW_WEAPON = sqg2oconst.ACTION_DRAW_WEAPON
ACTION_REMOVE_WEAPON = sqg2oconst.ACTION_REMOVE_WEAPON
ACTION_USE_ITEM = sqg2oconst.ACTION_USE_ITEM
ACTION_USE_ITEM_TO_STATE = sqg2oconst.ACTION_USE_ITEM_TO_STATE
ACTION_READY_SPELL = sqg2oconst.ACTION_READY_SPELL
ACTION_UNREADY_SPELL = sqg2oconst.ACTION_UNREADY_SPELL
ACTION_ATTACK_MELEE_WEAPON = sqg2oconst.ACTION_ATTACK_MELEE_WEAPON
ACTION_ATTACK_RANGED_WEAPON = sqg2oconst.ACTION_ATTACK_RANGED_WEAPON
ACTION_SPELL_CAST = sqg2oconst.ACTION_SPELL_CAST
ACTION_USE_MOB_SCHEME = sqg2oconst.ACTION_USE_MOB_SCHEME
ACTION_SHOOT_AT = sqg2oconst.ACTION_SHOOT_AT
ACTION_START_AIM_AT = sqg2oconst.ACTION_START_AIM_AT
ACTION_STOP_AIM_AT = sqg2oconst.ACTION_STOP_AIM_AT
ACTION_SCRIPT = sqg2oconst.ACTION_SCRIPT

View File

@@ -0,0 +1,7 @@
import sqg2oconst
UNRELIABLE = sqg2oconst.UNRELIABLE
UNRELIABLE_SEQUENCED = sqg2oconst.UNRELIABLE_SEQUENCED
RELIABLE = sqg2oconst.RELIABLE
RELIABLE_ORDERED = sqg2oconst.RELIABLE_ORDERED
RELIABLE_SEQUENCED = sqg2oconst.RELIABLE_SEQUENCED

View File

@@ -0,0 +1,6 @@
import sqg2oconst
WEAPON_1H = sqg2oconst.WEAPON_1H
WEAPON_2H = sqg2oconst.WEAPON_2H
WEAPON_BOW = sqg2oconst.WEAPON_BOW
WEAPON_CBOW = sqg2oconst.WEAPON_CBOW

24
g2o/constants/talent.py Normal file
View File

@@ -0,0 +1,24 @@
import sqg2oconst
TALENT_1H = sqg2oconst.TALENT_1H
TALENT_2H = sqg2oconst.TALENT_2H
TALENT_BOW = sqg2oconst.TALENT_BOW
TALENT_CROSSBOW = sqg2oconst.TALENT_CROSSBOW
TALENT_PICK_LOCKS = sqg2oconst.TALENT_PICK_LOCKS
TALENT_PICKPOCKET = sqg2oconst.TALENT_PICKPOCKET
TALENT_MAGE = sqg2oconst.TALENT_MAGE
TALENT_SNEAK = sqg2oconst.TALENT_SNEAK
TALENT_REGENERATE = sqg2oconst.TALENT_REGENERATE
TALENT_FIREMASTER = sqg2oconst.TALENT_FIREMASTER
TALENT_ACROBATIC = sqg2oconst.TALENT_ACROBATIC
TALENT_PICKPOCKET_UNUSED = sqg2oconst.TALENT_PICKPOCKET_UNUSED
TALENT_SMITH = sqg2oconst.TALENT_SMITH
TALENT_RUNES = sqg2oconst.TALENT_RUNES
TALENT_ALCHEMY = sqg2oconst.TALENT_ALCHEMY
TALENT_THROPHY = sqg2oconst.TALENT_THROPHY
TALENT_A = sqg2oconst.TALENT_A
TALENT_B = sqg2oconst.TALENT_B
TALENT_C = sqg2oconst.TALENT_C
TALENT_D = sqg2oconst.TALENT_D
TALENT_E = sqg2oconst.TALENT_E
TALENT_MAX = sqg2oconst.TALENT_MAX

View File

@@ -0,0 +1,11 @@
import sqg2oconst
WEAPONMODE_NONE = sqg2oconst.WEAPONMODE_NONE
WEAPONMODE_FIST = sqg2oconst.WEAPONMODE_FIST
WEAPONMODE_DAG = sqg2oconst.WEAPONMODE_DAG
WEAPONMODE_1HS = sqg2oconst.WEAPONMODE_1HS
WEAPONMODE_2HS = sqg2oconst.WEAPONMODE_2HS
WEAPONMODE_BOW = sqg2oconst.WEAPONMODE_BOW
WEAPONMODE_CBOW = sqg2oconst.WEAPONMODE_CBOW
WEAPONMODE_MAG = sqg2oconst.WEAPONMODE_MAG
WEAPONMODE_MAX = sqg2oconst.WEAPONMODE_MAX

4
g2o/constants/weather.py Normal file
View File

@@ -0,0 +1,4 @@
import sqg2oconst
WEATHER_SNOW = sqg2oconst.WEATHER_SNOW
WEATHER_RAIN = sqg2oconst.WEATHER_RAIN