Skip to content

Commit

Permalink
Add github actions #1, char* support in opcodehandler
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Apr 6, 2022
1 parent 2cbfd1f commit 847a91b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 19 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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

44 changes: 27 additions & 17 deletions src/opcodehandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,40 @@ class ScriptBuffer
{
_resize(_size + sizeof(T) + 1); // +1 for type descriptor

if (std::is_same_v<T, char> || std::is_same_v<T, unsigned char> || std::is_same_v<T, bool>)
{
memset(&_buf[_size], 0x4, 1);
_size += 1;
}
if (std::is_same_v<T, int> || std::is_same_v<T, unsigned int>)
{
memset(&_buf[_size], 0x1, 1);
_size += 1;
}
if (std::is_same_v<T, short> || std::is_same_v<T, unsigned short>)
{
memset(&_buf[_size], 0x5, 1);
_size += 1;
}
if (std::is_same_v<T, float>)
{
memset(&_buf[_size], 0x6, 1);
_size += 1;
}
if (std::is_same_v<T, bool>)
{
if (std::is_same_v<T, char> || std::is_same_v<T, unsigned char> || std::is_same_v<T, bool>)
{
memset(&_buf[_size], 0x4, 1);
_size += 1;
}
if (std::is_same_v<T, char*> || std::is_same_v<T, unsigned char&> || std::is_same_v<T, const char*>)
{
memset(&_buf[_size], 0xE, 1);
_size += 1;
const char * str = reinterpret_cast<const char*>(&value);
memset(&_buf[_size], strlen(str), 1);
_size += 1;
}
_size += 1;

memcpy(&_buf[_size], &value, sizeof(value));
_size += sizeof(value);
}
Expand All @@ -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));
Expand All @@ -151,7 +168,7 @@ class OpcodeHandler
static unsigned short &commands_executed = *reinterpret_cast<unsigned short*>(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;
Expand All @@ -171,7 +188,7 @@ class OpcodeHandler
}

template <typename T>
static void mem_cpy(ScriptBuffer& buf, T value)
static void pack_param(ScriptBuffer& buf, T value)
{
buf.add_bytes(value);
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
};
2 changes: 1 addition & 1 deletion tools/Setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tools/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ project "PyLoader"
}
includedirs {
"../depend/",
PYTHON_DIR .. "/include/"
PYTHON_DIR .. "/include/",
}

libdirs {
Expand Down

0 comments on commit 847a91b

Please sign in to comment.