From 984825fe511dcb0e54fc0b0944727d569fbda684 Mon Sep 17 00:00:00 2001 From: ineedbots Date: Tue, 29 Jun 2021 12:26:09 -0600 Subject: [PATCH] Some custom scruipt loading hooks --- src/Components/Modules/Script.cpp | 25 ++++++++++++--- src/Components/Modules/Script.hpp | 4 +++ src/Game/Game.cpp | 52 +++++++++++++++++++++++++++++-- src/Game/Game.hpp | 13 ++++++++ 4 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index 0ab73be..a1d6a01 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -5,25 +5,24 @@ namespace Components { std::unordered_map Script::CustomScrFunctions; std::unordered_map Script::CustomScrMethods; + std::vector Script::CustomScrHandles; void Script::AddFunction(const char* name, Game::xfunction_t func, int type) { Game::scr_function_t toAdd; toAdd.call = func; - toAdd.name = name; toAdd.developer = type; - CustomScrFunctions.insert_or_assign(name, toAdd); + CustomScrFunctions.insert_or_assign(Utils::String::ToLower(name), toAdd); } void Script::AddMethod(const char* name, Game::xmethod_t func, int type) { Game::scr_method_t toAdd; toAdd.call = func; - toAdd.name = name; toAdd.developer = type; - CustomScrMethods.insert_or_assign(name, toAdd); + CustomScrMethods.insert_or_assign(Utils::String::ToLower(name), toAdd); } Game::xmethod_t Script::Player_GetMethod_Hook(const char** name) @@ -36,6 +35,16 @@ namespace Components return got->second.call; } + void Script::GScr_LoadGameTypeScript_Hook() + { + Game::GScr_LoadGameTypeScript(); + } + + void Script::G_LoadStructs_Hook() + { + Game::G_LoadStructs(); + } + Game::xfunction_t Script::Scr_GetFunction_Hook(const char** name, int* isDev) { auto got = CustomScrFunctions.find(*name); @@ -43,18 +52,26 @@ namespace Components if (got == CustomScrFunctions.end()) return Game::Scr_GetFunction(name, isDev); + *isDev = got->second.developer; return got->second.call; } Script::Script() { + // custom gsc calls Utils::Hook(0x46E9CB, Player_GetMethod_Hook, HOOK_CALL).install()->quick(); Utils::Hook(0x46E7BF, Scr_GetFunction_Hook, HOOK_CALL).install()->quick(); + + // load custom scripts + Utils::Hook(0x4FC75F, G_LoadStructs_Hook, HOOK_CALL).install()->quick(); + Utils::Hook(0x5043FA, GScr_LoadGameTypeScript_Hook, HOOK_CALL).install()->quick(); + } Script::~Script() { CustomScrFunctions.clear(); CustomScrMethods.clear(); + CustomScrHandles.clear(); } } diff --git a/src/Components/Modules/Script.hpp b/src/Components/Modules/Script.hpp index c82a90b..539dc87 100644 --- a/src/Components/Modules/Script.hpp +++ b/src/Components/Modules/Script.hpp @@ -12,8 +12,12 @@ namespace Components private: static std::unordered_map CustomScrFunctions; static std::unordered_map CustomScrMethods; + static std::vector CustomScrHandles; static Game::xmethod_t Player_GetMethod_Hook(const char**); static Game::xfunction_t Scr_GetFunction_Hook(const char**, int*); + + static void GScr_LoadGameTypeScript_Hook(); + static void G_LoadStructs_Hook(); }; } diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 80f5876..f74c8a3 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -28,14 +28,19 @@ namespace Game bgs_s** bgs_ptr; - - Player_GetMethod_t* Player_GetMethod; + Scr_LoadScript_t* Scr_LoadScript; Scr_GetFunction_t* Scr_GetFunction; + Player_GetMethod_t* Player_GetMethod; + GScr_LoadGameTypeScript_t* GScr_LoadGameTypeScript; + G_LoadStructs_t* G_LoadStructs; void Init(GAMEEXE) { Player_GetMethod = ASSIGN(Player_GetMethod_t*, 0x52E050); Scr_GetFunction = ASSIGN(Scr_GetFunction_t*, 0x50D280); + Scr_LoadScript = ASSIGN(Scr_LoadScript_t*, 0x474D80); + GScr_LoadGameTypeScript = ASSIGN(GScr_LoadGameTypeScript_t*, 0x503F90); + G_LoadStructs = ASSIGN(G_LoadStructs_t*, 0x5118A0); cls = ASSIGN(clientStatic_t*, 0x68A408); @@ -65,6 +70,49 @@ namespace Game bgs_ptr = ASSIGN(bgs_s**, 0x19A1C78); } + unsigned int Scr_GetFunctionHandle(char* filename, const char* funcHandle) + { + int func_loc = 0x474950; + unsigned int answer; + + __asm + { + push funcHandle; + mov eax, filename; + call func_loc; + add esp, 4; + mov answer, eax; + } + + return answer; + } + + __int16 Scr_ExecThread(int handle) + { + int func_loc = 0x482080; + __int16 answer; + + __asm + { + mov eax, handle; + call func_loc; + mov answer, ax; + } + + return answer; + } + + void RemoveRefToObject(int obj) + { + int func_loc = 0x479660; + + __asm + { + mov eax, obj; + call func_loc; + } + } + void G_SelectWeaponIndex(int wpIdx, int clNum) { int func_loc = 0x5282E0; diff --git a/src/Game/Game.hpp b/src/Game/Game.hpp index dbe3107..0288d1e 100644 --- a/src/Game/Game.hpp +++ b/src/Game/Game.hpp @@ -32,6 +32,19 @@ namespace Game extern stringIndex_t* scr_const; extern bgs_s** bgs_ptr; + + typedef int (Scr_LoadScript_t)(char*); + extern Scr_LoadScript_t* Scr_LoadScript; + + typedef void (GScr_LoadGameTypeScript_t)(); + extern GScr_LoadGameTypeScript_t* GScr_LoadGameTypeScript; + + typedef void (G_LoadStructs_t)(); + extern G_LoadStructs_t* G_LoadStructs; + + extern unsigned int Scr_GetFunctionHandle(char*, const char*); + extern __int16 Scr_ExecThread(int); + extern void RemoveRefToObject(int); typedef Game::xmethod_t (Player_GetMethod_t)(const char**); extern Player_GetMethod_t* Player_GetMethod;