diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5573d9d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +name: Build PyLoader +on: push +jobs: + build: + runs-on: windows-latest + strategy: + matrix: + project: [PyLoader] + buildtype: [Release] + python-ver: ["3.10.4"] + + steps: + - name: Checkout + uses: actions/checkout@v3.0.0 + - name: Setup premake + uses: abel0b/setup-premake@v2 + with: + version: "5.0.0-beta1" + - name: Configure build + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: Win32 + - name: Setup python + uses: actions/setup-python@v3 + with: + python-version: ${{matrix.python-ver}} + architecture: x86 + - name: Move python + run: mv "C:/hostedtoolcache/windows/Python/3.10.4/x86/" "C:/Program Files (x86)/Python310-32" + - name: Build plugin + run: | + cd tools + premake5 vs2022 + cd ../build + MsBuild ${{matrix.project}}.sln /property:Configuration=${{matrix.buildtype}} /p:Platform=Win32 /t:${{matrix.project}} + - name: Upload plugin + uses: actions/upload-artifact@v3 + with: + name: ${{matrix.project}} + path: build\bin\${{matrix.buildtype}}.asi + diff --git a/src/opcodehandler.hpp b/src/opcodehandler.hpp index 8b7bd2f..7709168 100644 --- a/src/opcodehandler.hpp +++ b/src/opcodehandler.hpp @@ -110,23 +110,40 @@ class ScriptBuffer { _resize(_size + sizeof(T) + 1); // +1 for type descriptor + if (std::is_same_v || std::is_same_v || std::is_same_v) + { + memset(&_buf[_size], 0x4, 1); + _size += 1; + } if (std::is_same_v || std::is_same_v) { memset(&_buf[_size], 0x1, 1); + _size += 1; } if (std::is_same_v || std::is_same_v) { memset(&_buf[_size], 0x5, 1); + _size += 1; } if (std::is_same_v) { memset(&_buf[_size], 0x6, 1); + _size += 1; } - if (std::is_same_v) - { + if (std::is_same_v || std::is_same_v || std::is_same_v) + { memset(&_buf[_size], 0x4, 1); + _size += 1; + } + if (std::is_same_v || std::is_same_v || std::is_same_v) + { + memset(&_buf[_size], 0xE, 1); + _size += 1; + const char * str = reinterpret_cast(&value); + memset(&_buf[_size], strlen(str), 1); + _size += 1; } - _size += 1; + memcpy(&_buf[_size], &value, sizeof(value)); _size += sizeof(value); } @@ -137,7 +154,7 @@ class OpcodeHandler private: // Calls CRunningScript on a memory buffer - static bool call_script_on_buf(unsigned int command_id, unsigned char* buf) + static bool call_script_on_buf(unsigned int command_id, ScriptBuffer& buf) { static CRunningScriptSA script; memset(&script, 0, sizeof(CRunningScriptSA)); @@ -151,7 +168,7 @@ class OpcodeHandler static unsigned short &commands_executed = *reinterpret_cast(0xA447F4); typedef char (__thiscall* opcodeTable)(CRunningScriptSA*, int); - script.m_pBaseIP = script.m_pCurrentIP = buf; + script.m_pBaseIP = script.m_pCurrentIP = buf.get(); // Calling CRunningScript::ProcessOneCommand directly seems to crash ++commands_executed; @@ -171,7 +188,7 @@ class OpcodeHandler } template - static void mem_cpy(ScriptBuffer& buf, T value) + static void pack_param(ScriptBuffer& buf, T value) { buf.add_bytes(value); } @@ -186,12 +203,6 @@ class OpcodeHandler OpcodeHandler() = delete; OpcodeHandler(const OpcodeHandler&) = delete; - // call opcodes using a external buffer - static bool call(unsigned int command_id, unsigned char* buf) - { - return call_script_on_buf(command_id, buf); - } - // call opcode using a python tuple static bool call(PyObject* args) { @@ -241,14 +252,13 @@ class OpcodeHandler } else { - // TODO: handle strings - // char *val = PyBytes_AsString(PyUnicode_AsUTF8String(ptemp)); - // memcpy((void*)(int(pArr) + i*4), &val, 4); + char *val = PyBytes_AsString(PyUnicode_AsUTF8String(ptemp)); + buf.add_bytes(val); } } } - return call_script_on_buf(command_id, buf.get()); + return call_script_on_buf(command_id, buf); } // call opcode using param pack @@ -257,6 +267,6 @@ class OpcodeHandler { ScriptBuffer buf(command_id); pack_param(buf, arguments...); - return call_script_on_buf(command_id, buf.get()); + return call_script_on_buf(command_id, buf); } }; \ No newline at end of file diff --git a/tools/Setup.bat b/tools/Setup.bat index 1a6f7b0..0963e9b 100644 --- a/tools/Setup.bat +++ b/tools/Setup.bat @@ -9,4 +9,4 @@ set "III_DIR="E:\GTA3"" cd tools premake5.exe vs2022 cd ../build -call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" +call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" diff --git a/tools/premake5.lua b/tools/premake5.lua index 18974a2..01e95fb 100644 --- a/tools/premake5.lua +++ b/tools/premake5.lua @@ -32,7 +32,7 @@ project "PyLoader" } includedirs { "../depend/", - PYTHON_DIR .. "/include/" + PYTHON_DIR .. "/include/", } libdirs {