fetch ui sqvm and register ui script functions (#61)

* create ui vm hook and fetching ui vm global ptr

* an actually functional hook for registering ui funcs
This commit is contained in:
r-ex 2021-12-28 18:11:32 +00:00 committed by GitHub
parent 421d5e3c73
commit 47dc117cff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include "squirrel/sqvm.h"
#include "vgui/CEngineVGui.h"
#include "gameui/IConsole.h"
#include "serverbrowser/serverbrowser.h"
//---------------------------------------------------------------------------------
// Purpose: prints the output of each VM to the console
@ -284,6 +285,17 @@ void RegisterServerScriptFunctions(void* sqvm)
HSQVM_RegisterFunction(sqvm, "ServerNativeTest", "native server function", "void", "", &HSQVM_NativeTest);
}
ADDRESS UIVM = (void*)p_SQVM_CreateUIVM.FollowNearCall().FindPatternSelf("48 8B 1D", ADDRESS::Direction::DOWN, 50).ResolveRelativeAddressSelf(0x3, 0x7).GetPtr();
void HSQVM_RegisterOriginFuncs(void* sqvm)
{
if (sqvm == *UIVM.RCast<void**>())
RegisterUIScriptFunctions(sqvm);
else
RegisterClientScriptFunctions(sqvm);
return SQVM_RegisterOriginFuncs(sqvm);
}
void SQVM_Attach()
{
DetourAttach((LPVOID*)&SQVM_PrintFunc, &HSQVM_PrintFunc);
@ -291,6 +303,7 @@ void SQVM_Attach()
DetourAttach((LPVOID*)&SQVM_WarningCmd, &HSQVM_WarningCmd);
DetourAttach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson);
DetourAttach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript);
DetourAttach((LPVOID*)&SQVM_RegisterOriginFuncs, &HSQVM_RegisterOriginFuncs);
}
void SQVM_Detach()
@ -300,6 +313,7 @@ void SQVM_Detach()
DetourDetach((LPVOID*)&SQVM_WarningCmd, &HSQVM_WarningCmd);
DetourDetach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson);
DetourDetach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript);
DetourDetach((LPVOID*)&SQVM_RegisterOriginFuncs, &HSQVM_RegisterOriginFuncs);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -50,6 +50,17 @@ namespace
ADDRESS p_SQVM_RegisterFunc = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x83\xEC\x38\x45\x0F\xB6\xC8", "xxxxxxxx"); /*48 83 EC 38 45 0F B6 C8*/
void* (*SQVM_RegisterFunc)(void* sqvm, SQFuncRegistration* sqFunc, int a1) = (void* (*)(void*, SQFuncRegistration*, int))p_SQVM_RegisterFunc.GetPtr();
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
ADDRESS p_SQVM_CreateUIVM = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\xE8\x00\x00\x00\x00\x84\xC0\x74\x18\xE8\x00\x00\x00\x00", "x????xxxxx????")
bool (*SQVM_CreateUIVM)() = (bool(*)())p_SQVM_CreateUIVM.FollowNearCall().GetPtr();
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
ADDRESS p_SQVM_CreateUIVM = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\xE8\x00\x00\x00\x00\x84\xC0\x74\xE0\x44\x38\x25\x00\x00\x00\x00", "x????xxxxxxx????");
bool (*SQVM_CreateUIVM)() = (bool(*)())p_SQVM_CreateUIVM.FollowNearCall().GetPtr();
#endif
ADDRESS p_SQVM_RegisterOriginFuncs = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\xE8\x00\x00\x00\x00\x48\x8B\x0D\x00\x00\x00\x00\x48\x8D\x15\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x48\x8B\x05\x00\x00\x00\x00\xC7\x05\x00\x00\x00\x00\x00\x00\x00\x00", "x????xxx????xxx????x????xxx????xx????????");
void (*SQVM_RegisterOriginFuncs)(void* sqvm) = (void(*)(void*))p_SQVM_RegisterOriginFuncs.FollowNearCall().GetPtr();
}
void* HSQVM_PrintFunc(void* sqvm, char* fmt, ...);
@ -59,6 +70,7 @@ bool HSQVM_LoadScript(void* sqvm, const char* szScriptPath, const char* szScript
void HSQVM_RegisterFunction(void* sqvm, const char* szName, const char* szHelpString, const char* szRetValType, const char* szArgTypes, void* pFunction);
int HSQVM_NativeTest(void* sqvm);
void HSQVM_RegisterOriginFuncs(void* sqvm);
void SQVM_Attach();
void SQVM_Detach();