More SQ types and 'sq_compilebuffer()' AOB + prototype

Added signature and prototype for 'sq_compilebuffer()'.
Added 'SQBufState' structure to sqtypes.
Adapt entirely to SQ types for all sqapi functions.
This commit is contained in:
Kawe Mazidjatari 2022-03-30 00:06:52 +02:00
parent 28b1718cb1
commit ecb2bc54ad
4 changed files with 66 additions and 41 deletions

View File

@ -8,46 +8,46 @@
#include "squirrel/sqapi.h"
#include "squirrel/sqtype.h"
char* sq_getstring(HSQUIRRELVM* v, int i)
char* sq_getstring(HSQUIRRELVM* v, SQInteger i)
{
std::uintptr_t thisptr = reinterpret_cast<std::uintptr_t>(v);
return *(char**)(*(std::int64_t*)(thisptr + 0x58) + 0x10 * i + 0x8) + 0x40;
}
int sq_getinteger(HSQUIRRELVM* v, int i)
int sq_getinteger(HSQUIRRELVM* v, SQInteger i)
{
std::uintptr_t thisptr = reinterpret_cast<std::uintptr_t>(v);
return *(int*)(*(std::int64_t*)(thisptr + 0x58) + 0x10 * i + 0x8);
}
void sq_pushbool(HSQUIRRELVM* v, int val)
void sq_pushbool(HSQUIRRELVM* v, SQBool b)
{
v_sq_pushbool(v, val);
v_sq_pushbool(v, b);
}
void sq_pushstring(HSQUIRRELVM* v, const char* string, int len)
void sq_pushstring(HSQUIRRELVM* v, const SQChar* s, SQInteger len)
{
v_sq_pushstring(v, const_cast<char*>(string), len);
v_sq_pushstring(v, s, len);
}
void sq_pushinteger(HSQUIRRELVM* v, int val)
void sq_pushinteger(HSQUIRRELVM* v, SQInteger val)
{
v_sq_pushinteger(v, val);
}
void sq_pushconstant(HSQUIRRELVM* v, const char* name, int val)
void sq_pushconstant(HSQUIRRELVM* v, const SQChar* name, SQInteger val)
{
v_sq_pushconstant(v, name, val);
}
void sq_newarray(HSQUIRRELVM* v, int size)
void sq_newarray(HSQUIRRELVM* v, SQInteger size)
{
v_sq_newarray(v, size);
}
void sq_arrayappend(HSQUIRRELVM* v, int idx)
void sq_arrayappend(HSQUIRRELVM* v, SQInteger idx)
{
v_sq_arrayappend(v, idx);
}
@ -57,16 +57,21 @@ void sq_newtable(HSQUIRRELVM* v)
v_sq_newtable(v);
}
void sq_newslot(HSQUIRRELVM* v, int idx)
void sq_newslot(HSQUIRRELVM* v, SQInteger idx)
{
v_sq_newslot(v, idx);
}
void sq_pushstructure(HSQUIRRELVM* v, const char* name, const char* member, const char* codeclass1, const char* codeclass2)
void sq_pushstructure(HSQUIRRELVM* v, const SQChar* name, const SQChar* member, const SQChar* codeclass1, const SQChar* codeclass2)
{
v_sq_pushstructure(v, name, member, codeclass1, codeclass2);
}
SQRESULT sq_compilebuffer(HSQUIRRELVM v, SQBufState bufferState, const SQChar* buffer, SQCONTEXT context)
{
return v_sq_compilebuffer(v, bufferState, buffer, context);
}
void SQAPI_Attach()
{
DetourAttach((LPVOID*)&v_sq_pushbool, &sq_pushbool);
@ -78,6 +83,7 @@ void SQAPI_Attach()
DetourAttach((LPVOID*)&v_sq_newtable, &sq_newtable);
DetourAttach((LPVOID*)&v_sq_newslot, &sq_newslot);
DetourAttach((LPVOID*)&v_sq_pushstructure, &sq_pushstructure);
DetourAttach((LPVOID*)&v_sq_compilebuffer, &sq_compilebuffer);
}
void SQAPI_Detach()
@ -91,4 +97,5 @@ void SQAPI_Detach()
DetourDetach((LPVOID*)&v_sq_newtable, &sq_newtable);
DetourDetach((LPVOID*)&v_sq_newslot, &sq_newslot);
DetourDetach((LPVOID*)&v_sq_pushstructure, &sq_pushstructure);
DetourDetach((LPVOID*)&v_sq_compilebuffer, &sq_compilebuffer);
}

View File

@ -5,62 +5,58 @@ namespace
{
/* ==== SQUIRREL ======================================================================================================================================================== */
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");
void (*v_sq_pushbool)(HSQUIRRELVM* v, int val) = (void (*)(HSQUIRRELVM*, int))p_sq_pushbool.GetPtr(); /*48 83 EC 38 33 C0 48 C7 44 24 20 08 00 00 01 48*/
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*/
#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");
void (*v_sq_pushstring)(HSQUIRRELVM* v, const char* string, int len) = (void (*)(HSQUIRRELVM*, const char*, int))p_sq_pushstring.GetPtr(); /*40 56 48 83 EC 30 48 8B F1 48 85 D2 0F 84 8C 00*/
void (*v_sq_pushstring)(HSQUIRRELVM* v, const SQChar* string, int len) = (void (*)(HSQUIRRELVM*, const SQChar*, int))p_sq_pushstring.GetPtr(); /*40 56 48 83 EC 30 48 8B F1 48 85 D2 0F 84 8C 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");
void (*v_sq_pushstring)(HSQUIRRELVM* v, const char* string, int len) = (void (*)(HSQUIRRELVM*, const char*, int))p_sq_pushstring.GetPtr(); /*40 56 48 83 EC 30 48 8B F1 48 85 D2 0F 84 8F 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*/
#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");
void (*v_sq_pushinteger)(HSQUIRRELVM* v, int val) = (void (*)(HSQUIRRELVM*, int))p_sq_pushinteger.GetPtr(); /*48 83 EC 38 33 C0 48 C7 44 24 20 02 00 00 05 48*/
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*/
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");
void (*v_sq_pushconstant)(HSQUIRRELVM* v, const char* name, int val) = (void (*)(HSQUIRRELVM*, const char*, int))p_sq_pushconstant.GetPtr(); /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 30 4C 8B*/
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*/
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");
void (*v_sq_newarray)(HSQUIRRELVM* v, int size) = (void (*)(HSQUIRRELVM*, int))p_sq_newarray.GetPtr(); /*48 89 5C 24 08 57 48 83 EC 30 48 8B D9 48 C7 44 24 20 40*/
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*/
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");
void (*v_sq_arrayappend)(HSQUIRRELVM* v, int idx) = (void (*)(HSQUIRRELVM*, int))p_sq_arrayappend.GetPtr(); /*40 53 48 83 EC 20 8B 41 ?? 48 8B D9 2B 41 ?? 83 F8 02 7D*/
void (*v_sq_arrayappend)(HSQUIRRELVM* v, SQInteger idx) = (void (*)(HSQUIRRELVM*, SQInteger))p_sq_arrayappend.GetPtr(); /*40 53 48 83 EC 20 8B 41 ?? 48 8B D9 2B 41 ?? 83 F8 02 7D*/
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");
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*/
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");
void (*v_sq_newslot)(HSQUIRRELVM* v, int idx) = (void (*)(HSQUIRRELVM*, int))p_sq_newslot.GetPtr(); /*40 53 48 83 EC 20 8B 41 ?? 48 8B D9 2B 41 ?? 83 F8 02 7D*/
void (*v_sq_newslot)(HSQUIRRELVM* v, SQInteger idx) = (void (*)(HSQUIRRELVM*, SQInteger))p_sq_newslot.GetPtr(); /*40 53 48 83 EC 20 8B 41 ?? 48 8B D9 2B 41 ?? 83 F8 02 7D*/
#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");
void (*v_sq_pushstructure)(HSQUIRRELVM* v, const char* name, const char* member, const char* codeclass1, const char* codeclass2) = (void (*)(HSQUIRRELVM*, const char*, const char*, const char*, const char*))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*/
void (*v_sq_pushstructure)(HSQUIRRELVM* v, const SQChar* name, const SQChar* member, const SQChar* codeclass1, const SQChar* codeclass2) = (void (*)(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*/
#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");
void (*v_sq_pushstructure)(HSQUIRRELVM* v, const char* name, const char* member, const char* codeclass1, const char* codeclass2) = (void (*)(HSQUIRRELVM*, const char*, const char*, const char*, const char*))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*/
void (*v_sq_pushstructure)(HSQUIRRELVM* v, const SQChar* name, const SQChar* member, const SQChar* codeclass1, const SQChar* codeclass2) = (void (*)(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*/
#endif
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");
SQRESULT (*v_sq_compilebuffer)(HSQUIRRELVM v, SQBufState bufferState, const SQChar* buffer, SQCONTEXT context) = (SQRESULT (*)(HSQUIRRELVM, SQBufState, const SQChar*, SQCONTEXT))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 */
}
///////////////////////////////////////////////////////////////////////////////
char* sq_getstring(HSQUIRRELVM* v, int i);
int sq_getinteger(HSQUIRRELVM* v, int i);
void sq_pushbool(HSQUIRRELVM* v, int val);
void sq_pushstring(HSQUIRRELVM* v, const char* string, int len);
void sq_pushinteger(HSQUIRRELVM* v, int val);
void sq_pushconstant(HSQUIRRELVM* v, const char* name, int val);
void sq_newarray(HSQUIRRELVM* v, int size);
void sq_arrayappend(HSQUIRRELVM* v, int idx);
char* sq_getstring(HSQUIRRELVM* v, SQInteger i);
int sq_getinteger(HSQUIRRELVM* v, SQInteger i);
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_arrayappend(HSQUIRRELVM* v, SQInteger idx);
void sq_newtable(HSQUIRRELVM* v);
void sq_newslot(HSQUIRRELVM* v, int idx);
void sq_pushstructure(HSQUIRRELVM* v, const char* name, const char* member, const char* codeclass1, const char* codeclass2);
void sq_newslot(HSQUIRRELVM* v, SQInteger idx);
void sq_pushstructure(HSQUIRRELVM* v, const SQChar* name, const SQChar* member, const SQChar* codeclass1, const SQChar* codeclass2);
void SQAPI_Attach();
void SQAPI_Detach();
typedef int SQRESULT;
#define SQ_OK (1)
#define SQ_ERROR (-1)
#define SQ_FAILED(res) (res<0)
#define SQ_SUCCEEDED(res) (res>=0)
///////////////////////////////////////////////////////////////////////////////
class HSqapi : public IDetour
{
@ -75,6 +71,7 @@ class HSqapi : public IDetour
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;
std::cout << "| FUN: sq_compilebuffer : 0x" << std::hex << std::uppercase << p_sq_compilebuffer.GetPtr() << std::setw(npad) << " |" << std::endl;
std::cout << "+----------------------------------------------------------------+" << std::endl;
}
};

View File

@ -266,7 +266,7 @@ namespace VSquirrel
if (svIpAddr.empty() || svEncKey.empty())
return SQ_OK;
DevMsg(eDLL_T::UI, "Connecting to server with connection string '%s' and encryption key '%s'\n", svIpAddr.c_str(), svEncKey.c_str());
DevMsg(eDLL_T::UI, "Connecting to server with ip-address '%s' and encryption key '%s'\n", svIpAddr.c_str(), svEncKey.c_str());
g_pIBrowser->ConnectToServer(svIpAddr, svEncKey);
@ -282,7 +282,7 @@ namespace VSquirrel
if (vsvMapList.empty())
{
DevMsg(eDLL_T::UI, "Available maps is empty!!!\n");
Warning(eDLL_T::UI, "%s: Available maps is empty!\n", __FUNCTION__);
return SQ_OK;
}

View File

@ -6,9 +6,30 @@
#define SQ_FAILED(res) (res<0)
#define SQ_SUCCEEDED(res) (res>=0)
typedef int SQRESULT;
typedef char SQChar;
typedef float SQFloat;
typedef long SQInteger;
typedef unsigned long SQUnsignedInteger;
typedef SQUnsignedInteger SQBool;
typedef SQInteger SQRESULT;
typedef struct SQVM* HSQUIRRELVM;
struct SQBufState
{
const SQChar* buf;
const SQChar* bufTail;
const SQChar* bufCopy;
SQBufState(const std::string& code)
{
buf = code.c_str();
bufTail = code.c_str() + code.size();
bufCopy = code.c_str();
}
};
enum class SQCONTEXT : int
{
SERVER = 0,