2021-12-25 22:36:38 +01:00
|
|
|
#pragma once
|
2022-03-29 22:27:56 +02:00
|
|
|
#include "squirrel/sqtype.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
/* ==== SQUIRREL ======================================================================================================================================================== */
|
2022-03-30 22:54:33 +02:00
|
|
|
ADDRESS p_sq_pushroottable = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x83\xEC\x28\x8B\x51\x00\x44\x8B\xC2", "xxxxxx?xxx");
|
|
|
|
SQRESULT(*v_sq_pushroottable)(HSQUIRRELVM v) = (SQRESULT(*)(HSQUIRRELVM))p_sq_pushroottable.GetPtr(); /*48 83 EC 28 8B 51 ?? 44 8B C2*/
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ADDRESS p_sq_pushbool = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x83\xEC\x38\x33\xC0\x48\xC7\x44\x24\x20\x08\x00\x00\x01\x48", "xxxxxxxxxxxxxxxx");
|
2022-03-30 22:54:33 +02:00
|
|
|
void (*v_sq_pushbool)(HSQUIRRELVM v, SQBool b) = (void (*)(HSQUIRRELVM, SQBool))p_sq_pushbool.GetPtr(); /*48 83 EC 38 33 C0 48 C7 44 24 20 08 00 00 01 48*/
|
2021-12-25 22:36:38 +01:00
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2)
|
|
|
|
ADDRESS p_sq_pushstring = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x56\x48\x83\xEC\x30\x48\x8B\xF1\x48\x85\xD2\x0F\x84\x8C\x00", "xxxxxxxxxxxxxxxx");
|
2022-03-31 02:26:05 +02:00
|
|
|
void (*v_sq_pushstring)(HSQUIRRELVM v, const SQChar* string, SQInteger len) = (void (*)(HSQUIRRELVM, const SQChar*, SQInteger))p_sq_pushstring.GetPtr(); /*40 56 48 83 EC 30 48 8B F1 48 85 D2 0F 84 8C 00*/
|
2021-12-25 22:36:38 +01:00
|
|
|
#elif defined (GAMEDLL_S3)
|
|
|
|
ADDRESS p_sq_pushstring = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x56\x48\x83\xEC\x30\x48\x8B\xF1\x48\x85\xD2\x0F\x84\x8F\x00", "xxxxxxxxxxxxxxxx");
|
2022-03-30 22:54:33 +02:00
|
|
|
void (*v_sq_pushstring)(HSQUIRRELVM v, const SQChar* string, SQInteger len) = (void (*)(HSQUIRRELVM, const SQChar*, SQInteger))p_sq_pushstring.GetPtr(); /*40 56 48 83 EC 30 48 8B F1 48 85 D2 0F 84 8F 00*/
|
2021-12-25 22:36:38 +01:00
|
|
|
#endif
|
|
|
|
ADDRESS p_sq_pushinteger = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x83\xEC\x38\x33\xC0\x48\xC7\x44\x24\x20\x02\x00\x00\x05\x48", "xxxxxxxxxxxxxxxx");
|
2022-03-30 22:54:33 +02:00
|
|
|
void (*v_sq_pushinteger)(HSQUIRRELVM v, SQInteger val) = (void (*)(HSQUIRRELVM, SQInteger))p_sq_pushinteger.GetPtr(); /*48 83 EC 38 33 C0 48 C7 44 24 20 02 00 00 05 48*/
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-03-28 02:19:54 +02:00
|
|
|
ADDRESS p_sq_pushconstant = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x30\x4C\x8B", "xxxx?xxxx?xxxx?xxxxxxx");
|
2022-03-30 22:54:33 +02:00
|
|
|
void (*v_sq_pushconstant)(HSQUIRRELVM v, const SQChar* name, SQInteger val) = (void (*)(HSQUIRRELVM, const SQChar*, SQInteger))p_sq_pushconstant.GetPtr(); /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 30 4C 8B*/
|
2022-03-28 02:19:54 +02:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ADDRESS p_sq_newarray = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x08\x57\x48\x83\xEC\x30\x48\x8B\xD9\x48\xC7\x44\x24\x20\x40", "xxxxxxxxxxxxxxxxxxx");
|
2022-03-30 22:54:33 +02:00
|
|
|
void (*v_sq_newarray)(HSQUIRRELVM v, SQInteger size) = (void (*)(HSQUIRRELVM, SQInteger))p_sq_newarray.GetPtr(); /*48 89 5C 24 08 57 48 83 EC 30 48 8B D9 48 C7 44 24 20 40*/
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ADDRESS p_sq_newtable = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x08\x57\x48\x83\xEC\x30\x48\x8B\xD9\x48\xC7\x44\x24\x20\x20", "xxxxxxxxxxxxxxxxxxx");
|
2022-03-30 22:54:33 +02:00
|
|
|
void (*v_sq_newtable)(HSQUIRRELVM v) = (void (*)(HSQUIRRELVM))p_sq_newtable.GetPtr(); /*48 89 5C 24 08 57 48 83 EC 30 48 8B D9 48 C7 44 24 20 20*/
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ADDRESS p_sq_newslot = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x53\x48\x83\xEC\x30\x44\x8B\x49\x00\x48\x8B\xD9\x41\x8B\xC1", "xxxxxxxxx?xxxxxx");
|
2022-03-31 02:26:05 +02:00
|
|
|
SQRESULT(*v_sq_newslot)(HSQUIRRELVM v, SQInteger idx) = (SQRESULT(*)(HSQUIRRELVM, SQInteger))p_sq_newslot.GetPtr(); /*40 53 48 83 EC 20 8B 41 ?? 48 8B D9 2B 41 ?? 83 F8 02 7D*/
|
|
|
|
|
|
|
|
ADDRESS p_sq_arrayappend = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x53\x48\x83\xEC\x20\x8B\x41\x00\x48\x8B\xD9\x2B\x41\x00\x83\xF8\x02\x7D", "xxxxxxxx?xxxxx?xxxx");
|
|
|
|
SQRESULT(*v_sq_arrayappend)(HSQUIRRELVM v, SQInteger idx) = (SQRESULT(*)(HSQUIRRELVM, SQInteger))p_sq_arrayappend.GetPtr(); /*40 53 48 83 EC 20 8B 41 ?? 48 8B D9 2B 41 ?? 83 F8 02 7D*/
|
2022-03-28 19:34:51 +02:00
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2)
|
|
|
|
ADDRESS p_sq_pushstructure = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x4C\x89\x4C\x24\x00\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8B\xEC", "xxxx?xxxx?xxxx?xxxx?xxxxxxxxxxxx");
|
2022-03-31 02:26:05 +02:00
|
|
|
SQRESULT(*v_sq_pushstructure)(HSQUIRRELVM v, const SQChar* name, const SQChar* member, const SQChar* codeclass1, const SQChar* codeclass2) = (SQRESULT(*)(HSQUIRRELVM, const SQChar*, const SQChar*, const SQChar*, const SQChar*))p_sq_pushstructure.GetPtr(); /*48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 4C 89 4C 24 ? 55 41 54 41 55 41 56 41 57 48 8B EC*/
|
2022-03-28 19:34:51 +02:00
|
|
|
#elif defined (GAMEDLL_S3)
|
|
|
|
ADDRESS p_sq_pushstructure = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8B\xEC\x48\x83\xEC\x60\x48\x8B\x59\x60", "xxxx?xxxx?xxxx?xxxxxxxxxxxxxxxxxxxx");
|
2022-03-31 02:26:05 +02:00
|
|
|
SQRESULT (*v_sq_pushstructure)(HSQUIRRELVM v, const SQChar* name, const SQChar* member, const SQChar* codeclass1, const SQChar* codeclass2) = (SQRESULT(*)(HSQUIRRELVM, const SQChar*, const SQChar*, const SQChar*, const SQChar*))p_sq_pushstructure.GetPtr(); /*48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 55 41 54 41 55 41 56 41 57 48 8B EC 48 83 EC 60 48 8B 59 60*/
|
2022-03-28 19:34:51 +02:00
|
|
|
#endif
|
2022-03-30 00:06:52 +02:00
|
|
|
ADDRESS p_sq_compilebuffer = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x57\x41\x56\x41\x57\x48\x83\xEC\x50\x41\x8B\xE9\x49\x8B\xF8", "xxxx?xxxx?xxxx?xxxxxxxxxxxxxxx");
|
2022-03-30 22:54:33 +02:00
|
|
|
SQRESULT (*v_sq_compilebuffer)(HSQUIRRELVM v, SQBufState* bufferState, const SQChar* buffer, SQInteger level) = (SQRESULT (*)(HSQUIRRELVM, SQBufState*, const SQChar*, SQInteger))p_sq_compilebuffer.GetPtr(); /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC 50 41 8B E9 49 8B F8*/
|
|
|
|
|
|
|
|
ADDRESS p_sq_call = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x4C\x8B\xDC\x49\x89\x5B\x08\x49\x89\x6B\x10\x49\x89\x73\x18\x57\x48\x83\xEC\x50\x8B\xF2", "xxxxxxxxxxxxxxxxxxxxxx");
|
|
|
|
SQRESULT (*v_sq_call)(HSQUIRRELVM v, SQInteger params, SQBool retval, SQBool raiseerror) = (SQRESULT (*)(HSQUIRRELVM, SQInteger, SQBool, SQBool))p_sq_call.GetPtr(); /*4C 8B DC 49 89 5B 08 49 89 6B 10 49 89 73 18 57 48 83 EC 50 8B F2*/
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-03-30 22:54:33 +02:00
|
|
|
SQRESULT sq_pushroottable(HSQUIRRELVM v);
|
|
|
|
SQChar* sq_getstring(HSQUIRRELVM v, SQInteger i);
|
|
|
|
SQInteger sq_getinteger(HSQUIRRELVM v, SQInteger i);
|
|
|
|
SQRESULT sq_pushroottable(HSQUIRRELVM v);
|
|
|
|
void sq_pushbool(HSQUIRRELVM v, SQBool b);
|
|
|
|
void sq_pushstring(HSQUIRRELVM v, const SQChar* string, SQInteger len);
|
|
|
|
void sq_pushinteger(HSQUIRRELVM v, SQInteger val);
|
|
|
|
void sq_pushconstant(HSQUIRRELVM v, const SQChar* name, SQInteger val);
|
|
|
|
void sq_newarray(HSQUIRRELVM v, SQInteger size);
|
|
|
|
void sq_newtable(HSQUIRRELVM v);
|
2022-03-31 02:26:05 +02:00
|
|
|
SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx);
|
|
|
|
SQRESULT sq_arrayappend(HSQUIRRELVM v, SQInteger idx);
|
|
|
|
SQRESULT sq_pushstructure(HSQUIRRELVM v, const SQChar* name, const SQChar* member, const SQChar* codeclass1, const SQChar* codeclass2);
|
2022-03-30 22:54:33 +02:00
|
|
|
SQRESULT sq_compilebuffer(HSQUIRRELVM v, SQBufState* bufferState, const SQChar* buffer, SQInteger context);
|
|
|
|
SQRESULT sq_call(HSQUIRRELVM v, SQInteger params, SQBool retval, SQBool raiseerror);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
void SQAPI_Attach();
|
|
|
|
void SQAPI_Detach();
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class HSqapi : public IDetour
|
|
|
|
{
|
|
|
|
virtual void debugp()
|
|
|
|
{
|
2022-03-30 22:54:33 +02:00
|
|
|
std::cout << "| FUN: sq_pushroottable : 0x" << std::hex << std::uppercase << p_sq_pushroottable.GetPtr() << std::setw(npad) << " |" << std::endl;
|
2022-03-28 19:34:51 +02:00
|
|
|
std::cout << "| FUN: sq_pushbool : 0x" << std::hex << std::uppercase << p_sq_pushbool.GetPtr() << std::setw(npad) << " |" << std::endl;
|
|
|
|
std::cout << "| FUN: sq_pushstring : 0x" << std::hex << std::uppercase << p_sq_pushstring.GetPtr() << std::setw(npad) << " |" << std::endl;
|
|
|
|
std::cout << "| FUN: sq_pushinteger : 0x" << std::hex << std::uppercase << p_sq_pushinteger.GetPtr() << std::setw(npad) << " |" << std::endl;
|
|
|
|
std::cout << "| FUN: sq_pushconstant : 0x" << std::hex << std::uppercase << p_sq_pushconstant.GetPtr() << std::setw(npad) << " |" << std::endl;
|
|
|
|
std::cout << "| FUN: sq_newarray : 0x" << std::hex << std::uppercase << p_sq_newarray.GetPtr() << std::setw(npad) << " |" << std::endl;
|
|
|
|
std::cout << "| FUN: sq_arrayappend : 0x" << std::hex << std::uppercase << p_sq_arrayappend.GetPtr() << std::setw(npad) << " |" << std::endl;
|
|
|
|
std::cout << "| FUN: sq_newtable : 0x" << std::hex << std::uppercase << p_sq_newtable.GetPtr() << std::setw(npad) << " |" << std::endl;
|
|
|
|
std::cout << "| FUN: sq_newslot : 0x" << std::hex << std::uppercase << p_sq_newslot.GetPtr() << std::setw(npad) << " |" << std::endl;
|
|
|
|
std::cout << "| FUN: sq_pushstructure : 0x" << std::hex << std::uppercase << p_sq_pushstructure.GetPtr() << std::setw(npad) << " |" << std::endl;
|
2022-03-30 00:06:52 +02:00
|
|
|
std::cout << "| FUN: sq_compilebuffer : 0x" << std::hex << std::uppercase << p_sq_compilebuffer.GetPtr() << std::setw(npad) << " |" << std::endl;
|
2022-03-30 22:54:33 +02:00
|
|
|
std::cout << "| FUN: sq_call : 0x" << std::hex << std::uppercase << p_sq_call.GetPtr() << std::setw(npad) << " |" << std::endl;
|
2021-12-25 22:36:38 +01:00
|
|
|
std::cout << "+----------------------------------------------------------------+" << std::endl;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
REGISTER(HSqapi);
|