From 00dcc0e424a7b9472c148685a0f90648e49500bf Mon Sep 17 00:00:00 2001 From: ineed bots Date: Thu, 31 Aug 2023 13:10:44 -0600 Subject: [PATCH] added more detours --- .../clientscript_public - Copy.hpp | 2 - .../decomp/clientscript/re_cscr_main.cpp | 8 +- .../clientscript/re_cscr_memorytree.cpp | 308 ++ .../decomp/clientscript/re_cscr_parser.cpp | 590 ++++ .../decomp/clientscript/re_cscr_parsetree.cpp | 198 ++ .../decomp/clientscript/re_cscr_readwrite.cpp | 79 + .../clientscript/re_cscr_stringlist.cpp | 653 +++++ .../decomp/clientscript/re_cscr_variable.cpp | 2527 +++++++++++++++++ .../decomp/clientscript/re_cscr_vm.cpp | 1684 +++++++++++ src/game/clientscript/cscr_vm.hpp | 3 +- 10 files changed, 6044 insertions(+), 8 deletions(-) delete mode 100644 src/codsrc/clientscript/clientscript_public - Copy.hpp create mode 100644 src/component/decomp/clientscript/re_cscr_memorytree.cpp create mode 100644 src/component/decomp/clientscript/re_cscr_parser.cpp create mode 100644 src/component/decomp/clientscript/re_cscr_parsetree.cpp create mode 100644 src/component/decomp/clientscript/re_cscr_readwrite.cpp create mode 100644 src/component/decomp/clientscript/re_cscr_stringlist.cpp create mode 100644 src/component/decomp/clientscript/re_cscr_variable.cpp create mode 100644 src/component/decomp/clientscript/re_cscr_vm.cpp diff --git a/src/codsrc/clientscript/clientscript_public - Copy.hpp b/src/codsrc/clientscript/clientscript_public - Copy.hpp deleted file mode 100644 index 2644169..0000000 --- a/src/codsrc/clientscript/clientscript_public - Copy.hpp +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "clientscript_public.hpp" diff --git a/src/component/decomp/clientscript/re_cscr_main.cpp b/src/component/decomp/clientscript/re_cscr_main.cpp index ee943c6..cff8836 100644 --- a/src/component/decomp/clientscript/re_cscr_main.cpp +++ b/src/component/decomp/clientscript/re_cscr_main.cpp @@ -3,7 +3,7 @@ #include "utils/hook.hpp" #include "codsrc/clientscript/cscr_main.hpp" -//#define RE_CSCR_MAIN_USE_WRAPPERS +#define RE_CSCR_MAIN_USE_WRAPPERS namespace re_cscr_main @@ -275,13 +275,13 @@ namespace re_cscr_main void post_unpack() override { Scr_IsIdentifier_hook.create(game::Scr_IsIdentifier_ADDR(), Scr_IsIdentifier_stub); - //Scr_GetFunctionHandle_hook.create(game::Scr_GetFunctionHandle_ADDR(), Scr_GetFunctionHandle_stub); + Scr_GetFunctionHandle_hook.create(game::Scr_GetFunctionHandle_ADDR(), Scr_GetFunctionHandle_stub); SL_TransferToCanonicalString_hook.create(game::SL_TransferToCanonicalString_ADDR(), SL_TransferToCanonicalString_stub); SL_GetCanonicalString_hook.create(game::SL_GetCanonicalString_ADDR(), SL_GetCanonicalString_stub); - //Scr_BeginLoadScripts_hook.create(game::Scr_BeginLoadScripts_ADDR(), Scr_BeginLoadScripts_stub); + Scr_BeginLoadScripts_hook.create(game::Scr_BeginLoadScripts_ADDR(), Scr_BeginLoadScripts_stub); Scr_BeginLoadAnimTrees_hook.create(game::Scr_BeginLoadAnimTrees_ADDR(), Scr_BeginLoadAnimTrees_stub); Scr_ScanFile_hook.create(game::Scr_ScanFile_ADDR(), Scr_ScanFile_stub); - //Scr_LoadScriptInternal_hook.create(game::Scr_LoadScriptInternal.get(), Scr_LoadScriptInternal_stub); + Scr_LoadScriptInternal_hook.create(game::Scr_LoadScriptInternal.get(), Scr_LoadScriptInternal_stub); Scr_LoadScript_hook.create(game::Scr_LoadScript_ADDR(), Scr_LoadScript_stub); Scr_EndLoadScripts_hook.create(game::Scr_EndLoadScripts.get(), Scr_EndLoadScripts_stub); Scr_PrecacheAnimTrees_hook.create(game::Scr_PrecacheAnimTrees.get(), Scr_PrecacheAnimTrees_stub); diff --git a/src/component/decomp/clientscript/re_cscr_memorytree.cpp b/src/component/decomp/clientscript/re_cscr_memorytree.cpp new file mode 100644 index 0000000..b3ca261 --- /dev/null +++ b/src/component/decomp/clientscript/re_cscr_memorytree.cpp @@ -0,0 +1,308 @@ +#include +#include "loader/component_loader.hpp" +#include "utils/hook.hpp" +//#include "codsrc/clientscript/cscr_memorytree.hpp" + +#define RE_CSCR_MEMORYTREE_USE_WRAPPERS + +namespace re_cscr_memorytree +{ + utils::hook::detour MT_GetSubTreeSize_hook; + utils::hook::detour MT_DumpTree_hook; + utils::hook::detour MT_InitBits_hook; + utils::hook::detour MT_GetScore_hook; + utils::hook::detour MT_AddMemoryNode_hook; + utils::hook::detour MT_RemoveMemoryNode_hook; + utils::hook::detour MT_RemoveHeadMemoryNode_hook; + utils::hook::detour MT_Init_hook; + utils::hook::detour MT_Error_hook; + utils::hook::detour MT_GetSize_hook; + utils::hook::detour MT_AllocIndex_hook; + utils::hook::detour MT_FreeIndex_hook; + utils::hook::detour MT_Alloc_hook; + utils::hook::detour MT_Free_hook; + + void* MT_GetSubTreeSize_original; + void* MT_DumpTree_original; + void* MT_InitBits_original; + void* MT_GetScore_original; + void* MT_AddMemoryNode_original; + void* MT_RemoveMemoryNode_original; + void* MT_RemoveHeadMemoryNode_original; + void* MT_Init_original; + void* MT_Error_original; + void* MT_GetSize_original; + void* MT_AllocIndex_original; + void* MT_FreeIndex_original; + void* MT_Alloc_original; + void* MT_Free_original; + + namespace + { + int MT_GetSubTreeSize_stub(game::scriptInstance_t inst, int nodeNum, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + return MT_GetSubTreeSize_hook.invoke(inst, nodeNum); +#else + return codsrc::MT_GetSubTreeSize(inst, nodeNum); +#endif + } + + void MT_DumpTree_stub(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + MT_DumpTree_hook.invoke(a1); +#else + codsrc::MT_DumpTree(a1); +#endif + } + + void MT_InitBits_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + game::MT_InitBits(a1, MT_InitBits_original); +#else + codsrc::MT_InitBits(a1); +#endif + } + + // void __usercall MT_InitBits(scriptInstance_t a1@) + NAKED void MT_InitBits_stub() + { + _asm + { + push ecx; + call MT_InitBits_call; + add esp, 0x4; + ret; + } + } + + int MT_GetScore_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, int num) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + return game::MT_GetScore(a1, num, MT_GetScore_original); +#else + return codsrc::MT_GetScore(a1, num); +#endif + } + + + // int __usercall MT_GetScore@(scriptInstance_t a1@, int num) + NAKED int MT_GetScore_stub() + { + _asm + { + push edx; + call MT_GetScore_call; + add esp, 0x4; + ret; + } + } + + void MT_AddMemoryNode_stub(game::scriptInstance_t inst, int newNode, int size, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + MT_AddMemoryNode_hook.invoke(inst, newNode, size); +#else + codsrc::MT_AddMemoryNode(inst, newNode, size); +#endif + } + + char MT_RemoveMemoryNode_stub(game::scriptInstance_t inst, int oldNode, int size, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + return MT_RemoveMemoryNode_hook.invoke(inst, oldNode, size); +#else + return codsrc::MT_RemoveMemoryNode(inst, oldNode, size); +#endif + } + + void MT_RemoveHeadMemoryNode_stub(game::scriptInstance_t inst, int size, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + MT_RemoveHeadMemoryNode_hook.invoke(inst, size); +#else + codsrc::MT_RemoveHeadMemoryNode(inst, size); +#endif + } + + void MT_Init_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + game::MT_Init(a1, MT_Init_original); +#else + codsrc::MT_Init(a1); +#endif + } + + // void __usercall MT_Init(scriptInstance_t a1@) + NAKED void MT_Init_stub() + { + _asm + { + push edi; + call MT_Init_call; + add esp, 0x4; + ret; + } + } + + void MT_Error_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, const char* funcName, int numBytes) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + game::MT_Error(a1, funcName, numBytes, MT_Error_original); +#else + codsrc::MT_Error(a1, funcName, numBytes); +#endif + } + + // void __usercall MT_Error(scriptInstance_t a1@, const char *funcName, int numBytes) + NAKED void MT_Error_stub() + { + _asm + { + push eax; + call MT_Error_call; + add esp, 0x4; + ret; + } + } + + int MT_GetSize_call(int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + return game::MT_GetSize(numBytes, inst, MT_GetSize_original); +#else + return codsrc::MT_GetSize(numBytes, inst); +#endif + } + + // int __usercall MT_GetSize@(int numBytes@, scriptInstance_t inst@) + NAKED int MT_GetSize_stub() + { + _asm + { + push ecx; + push eax; + call MT_GetSize_call; + add esp, 0x8; + ret; + } + } + + unsigned __int16 MT_AllocIndex_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int size_) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + return game::MT_AllocIndex(inst, size_, MT_AllocIndex_original); +#else + return codsrc::MT_AllocIndex(inst, size_); +#endif + } + + // unsigned __int16 __usercall MT_AllocIndex@(scriptInstance_t inst@, int size) + NAKED unsigned __int16 MT_AllocIndex_stub() + { + _asm + { + push edi; + call MT_AllocIndex_call; + add esp, 0x4; + ret; + } + } + + void MT_FreeIndex_call(int numBytes, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a1, int nodeNum) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + game::MT_FreeIndex(numBytes, a1, nodeNum, MT_FreeIndex_original); +#else + codsrc::MT_FreeIndex(numBytes, a1, nodeNum); +#endif + } + + // void __usercall MT_FreeIndex(int numBytes@, scriptInstance_t a1, int nodeNum) + NAKED void MT_FreeIndex_stub() + { + _asm + { + push eax; + call MT_FreeIndex_call; + add esp, 0x4; + ret; + } + } + + char* MT_Alloc_call(int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + return game::MT_Alloc(numBytes, inst, MT_Alloc_original); +#else + return codsrc::MT_Alloc(numBytes, inst); +#endif + } + + // char *__usercall MT_Alloc@(int numBytes@, scriptInstance_t a2@) + NAKED char * MT_Alloc_stub() + { + _asm + { + push ecx; + push eax; + call MT_Alloc_call; + add esp, 0x8; + ret; + } + } + + void MT_Free_stub(void* p, int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS + MT_Free_hook.invoke(p, numBytes, inst); +#else + codsrc::MT_Free(p, numBytes, inst); +#endif + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + MT_GetSubTreeSize_hook.create(game::MT_GetSubTreeSize.get(), MT_GetSubTreeSize_stub); + MT_DumpTree_hook.create(game::MT_DumpTree.get(), MT_DumpTree_stub); + MT_InitBits_hook.create(game::MT_InitBits_ADDR(), MT_InitBits_stub); + MT_GetScore_hook.create(game::MT_GetScore_ADDR(), MT_GetScore_stub); + MT_AddMemoryNode_hook.create(game::MT_AddMemoryNode.get(), MT_AddMemoryNode_stub); + MT_RemoveMemoryNode_hook.create(game::MT_RemoveMemoryNode.get(), MT_RemoveMemoryNode_stub); + MT_RemoveHeadMemoryNode_hook.create(game::MT_RemoveHeadMemoryNode.get(), MT_RemoveHeadMemoryNode_stub); + MT_Init_hook.create(game::MT_Init_ADDR(), MT_Init_stub); + MT_Error_hook.create(game::MT_Error_ADDR(), MT_Error_stub); + MT_GetSize_hook.create(game::MT_GetSize_ADDR(), MT_GetSize_stub); + MT_AllocIndex_hook.create(game::MT_AllocIndex_ADDR(), MT_AllocIndex_stub); + MT_FreeIndex_hook.create(game::MT_FreeIndex_ADDR(), MT_FreeIndex_stub); + MT_Alloc_hook.create(game::MT_Alloc_ADDR(), MT_Alloc_stub); + MT_Free_hook.create(game::MT_Free.get(), MT_Free_stub); + + //Original hook function addresses + MT_GetSubTreeSize_original = MT_GetSubTreeSize_hook.get_original(); + MT_DumpTree_original = MT_DumpTree_hook.get_original(); + MT_InitBits_original = MT_InitBits_hook.get_original(); + MT_GetScore_original = MT_GetScore_hook.get_original(); + MT_AddMemoryNode_original = MT_AddMemoryNode_hook.get_original(); + MT_RemoveMemoryNode_original = MT_RemoveMemoryNode_hook.get_original(); + MT_RemoveHeadMemoryNode_original = MT_RemoveHeadMemoryNode_hook.get_original(); + MT_Init_original = MT_Init_hook.get_original(); + MT_Error_original = MT_Error_hook.get_original(); + MT_GetSize_original = MT_GetSize_hook.get_original(); + MT_AllocIndex_original = MT_AllocIndex_hook.get_original(); + MT_FreeIndex_original = MT_FreeIndex_hook.get_original(); + MT_Alloc_original = MT_Alloc_hook.get_original(); + MT_Free_original = MT_Free_hook.get_original(); + } + + private: + }; +} +REGISTER_COMPONENT(re_cscr_memorytree::component) \ No newline at end of file diff --git a/src/component/decomp/clientscript/re_cscr_parser.cpp b/src/component/decomp/clientscript/re_cscr_parser.cpp new file mode 100644 index 0000000..ab277f2 --- /dev/null +++ b/src/component/decomp/clientscript/re_cscr_parser.cpp @@ -0,0 +1,590 @@ +#include +#include "loader/component_loader.hpp" +#include "utils/hook.hpp" +//#include "codsrc/clientscript/cscr_parser.hpp" + +#define RE_CSCR_PARSER_USE_WRAPPERS + +namespace re_cscr_parser +{ + utils::hook::detour Scr_InitOpcodeLookup_hook; + utils::hook::detour Scr_ShutdownOpcodeLookup_hook; + utils::hook::detour AddOpcodePos_hook; + utils::hook::detour RemoveOpcodePos_hook; + utils::hook::detour AddThreadStartOpcodePos_hook; + utils::hook::detour Scr_GetSourceBuffer_hook; + utils::hook::detour Scr_GetLineNumInternal_hook; + utils::hook::detour Scr_GetNewSourceBuffer_hook; + utils::hook::detour Scr_AddSourceBufferInternal_hook; + utils::hook::detour Scr_ReadFile_FastFile_hook; + utils::hook::detour Scr_ReadFile_LoadObj_hook; + utils::hook::detour Scr_ReadFile_hook; + utils::hook::detour Scr_AddSourceBuffer_hook; + utils::hook::detour Scr_CopyFormattedLine_hook; + utils::hook::detour Scr_GetLineInfo_hook; + utils::hook::detour Scr_PrintSourcePos_hook; + utils::hook::detour Scr_GetPrevSourcePosOpcodeLookup_hook; + utils::hook::detour Scr_GetTextSourcePos_hook; + utils::hook::detour Scr_PrintPrevCodePos_hook; + utils::hook::detour CompileError_hook; + utils::hook::detour CompileError2_hook; + utils::hook::detour RuntimeErrorInternal_hook; + utils::hook::detour RuntimeError_hook; + + void* Scr_InitOpcodeLookup_original; + void* Scr_ShutdownOpcodeLookup_original; + void* AddOpcodePos_original; + void* RemoveOpcodePos_original; + void* AddThreadStartOpcodePos_original; + void* Scr_GetSourceBuffer_original; + void* Scr_GetLineNumInternal_original; + void* Scr_GetNewSourceBuffer_original; + void* Scr_AddSourceBufferInternal_original; + void* Scr_ReadFile_FastFile_original; + void* Scr_ReadFile_LoadObj_original; + void* Scr_ReadFile_original; + void* Scr_AddSourceBuffer_original; + void* Scr_CopyFormattedLine_original; + void* Scr_GetLineInfo_original; + void* Scr_PrintSourcePos_original; + void* Scr_GetPrevSourcePosOpcodeLookup_original; + void* Scr_GetTextSourcePos_original; + void* Scr_PrintPrevCodePos_original; + void* CompileError_original; + void* CompileError2_original; + void* RuntimeErrorInternal_original; + void* RuntimeError_original; + + namespace + { + + void Scr_InitOpcodeLookup_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::Scr_InitOpcodeLookup(a1, Scr_InitOpcodeLookup_original); +#else + codsrc::Scr_InitOpcodeLookup(a1); +#endif + } + + // void __usercall Scr_InitOpcodeLookup(game::scriptInstance_t a1@) + NAKED void Scr_InitOpcodeLookup_stub() + { + _asm + { + push eax; + call Scr_InitOpcodeLookup_call; + add esp, 0x4; + ret; + } + } + + void Scr_ShutdownOpcodeLookup_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::Scr_ShutdownOpcodeLookup(a1, Scr_ShutdownOpcodeLookup_original); +#else + codsrc::Scr_ShutdownOpcodeLookup(a1); +#endif + } + + // void __usercall Scr_ShutdownOpcodeLookup(game::scriptInstance_t a1@) + NAKED void Scr_ShutdownOpcodeLookup_stub() + { + _asm + { + push ecx; + call Scr_ShutdownOpcodeLookup_call; + add esp, 0x4; + ret; + } + } + + void AddOpcodePos_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int sourcePos, int type_) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::AddOpcodePos(a1, sourcePos, type_, AddOpcodePos_original); +#else + codsrc::AddOpcodePos(a1, sourcePos, type_); +#endif + } + + // void __usercall AddOpcodePos(game::scriptInstance_t a1@, unsigned int sourcePos, int type) + NAKED void AddOpcodePos_stub() + { + _asm + { + push eax; + call AddOpcodePos_call; + add esp, 0x4; + ret; + } + } + + void RemoveOpcodePos_call(game::scriptInstance_t result, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::RemoveOpcodePos(result, RemoveOpcodePos_original); +#else + codsrc::RemoveOpcodePos(result); +#endif + } + + // void __usercall RemoveOpcodePos(game::scriptInstance_t result@) + NAKED void RemoveOpcodePos_stub() + { + _asm + { + push eax; + call RemoveOpcodePos_call; + add esp, 0x4; + ret; + } + } + + void AddThreadStartOpcodePos_call(game::scriptInstance_t result, [[maybe_unused]] void* caller_addr, unsigned int sourcePos) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::AddThreadStartOpcodePos(result, sourcePos, AddThreadStartOpcodePos_original); +#else + codsrc::AddThreadStartOpcodePos(result, sourcePos); +#endif + } + + // void __usercall AddThreadStartOpcodePos(game::scriptInstance_t result@, unsigned int sourcePos) + NAKED void AddThreadStartOpcodePos_stub() + { + _asm + { + push eax; + call AddThreadStartOpcodePos_call; + add esp, 0x4; + ret; + } + } + + unsigned int Scr_GetSourceBuffer_call(game::scriptInstance_t a1, const char * codePos, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return game::Scr_GetSourceBuffer(a1, codePos, Scr_GetSourceBuffer_original); +#else + return codsrc::Scr_GetSourceBuffer(a1, codePos); +#endif + } + + // unsigned int __usercall Scr_GetSourceBuffer@(game::scriptInstance_t inst@, const char *codePos@) + NAKED unsigned int Scr_GetSourceBuffer_stub() + { + _asm + { + push esi; + push eax; + call Scr_GetSourceBuffer_call; + add esp, 0x8; + ret; + } + } + + unsigned int Scr_GetLineNumInternal_call(const char ** startLine, const char * buf, [[maybe_unused]] void* caller_addr, const char * sourcePos, int * col) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return game::Scr_GetLineNumInternal(startLine, buf, sourcePos, col, Scr_GetLineNumInternal_original); +#else + return codsrc::Scr_GetLineNumInternal(startLine, buf, sourcePos, col); +#endif + } + + // unsigned int __usercall Scr_GetLineNumInternal@(const char **startLine@, const char *buf@, const char *sourcePos, int *col) + NAKED unsigned int Scr_GetLineNumInternal_stub() + { + _asm + { + push ecx; + push edx; + call Scr_GetLineNumInternal_call; + add esp, 0x8; + ret; + } + } + + game::SourceBufferInfo * Scr_GetNewSourceBuffer_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return game::Scr_GetNewSourceBuffer(a1, Scr_GetNewSourceBuffer_original); +#else + return codsrc::Scr_GetNewSourceBuffer(a1); +#endif + } + + // SourceBufferInfo *__usercall Scr_GetNewSourceBuffer@(game::scriptInstance_t a1@) + NAKED game::SourceBufferInfo * Scr_GetNewSourceBuffer_stub() + { + _asm + { + push eax; + call Scr_GetNewSourceBuffer_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddSourceBufferInternal_call(const char * filename, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, const char * codepos, char * buffer, int len, int archive) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::Scr_AddSourceBufferInternal(filename, inst, codepos, buffer, len, archive, Scr_AddSourceBufferInternal_original); +#else + codsrc::Scr_AddSourceBufferInternal(filename, inst, codepos, buffer, len, archive); +#endif + } + + // void __usercall Scr_AddSourceBufferInternal(const char *filename@, game::scriptInstance_t inst, const char *codepos, char *buffer, int len, int archive) + NAKED void Scr_AddSourceBufferInternal_stub() + { + _asm + { + push eax; + call Scr_AddSourceBufferInternal_call; + add esp, 0x4; + ret; + } + } + + char * Scr_ReadFile_FastFile_stub(game::scriptInstance_t inst, int unused, char * filename, const char * codepos, int archive) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return Scr_ReadFile_FastFile_hook.invoke(inst, unused, filename, codepos, archive); +#else + return codsrc::Scr_ReadFile_FastFile(inst, unused, filename, codepos, archive); +#endif + } + + char * Scr_ReadFile_LoadObj_stub(game::scriptInstance_t inst, int unused_arg1, const char * filename, const char * codepos, int archive) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return Scr_ReadFile_LoadObj_hook.invoke(inst, unused_arg1, filename, codepos, archive); +#else + return codsrc::Scr_ReadFile_LoadObj(inst, unused_arg1, filename, codepos, archive); +#endif + } + + char * Scr_ReadFile_call(const char * codepos, char * filename, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, int unused) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return game::Scr_ReadFile(codepos, filename, inst, unused, Scr_ReadFile_original); +#else + return codsrc::Scr_ReadFile(codepos, filename, inst, unused); +#endif + } + + // char *__usercall Scr_ReadFile@(const char *codepos@, char *filename@, game::scriptInstance_t inst, int unused) + NAKED char * Scr_ReadFile_stub() + { + _asm + { + push esi; + push edi; + call Scr_ReadFile_call; + add esp, 0x8; + ret; + } + } + + char * Scr_AddSourceBuffer_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int unused_arg1, char * filename, const char * codepos) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return game::Scr_AddSourceBuffer(inst, unused_arg1, filename, codepos, Scr_AddSourceBuffer_original); +#else + return codsrc::Scr_AddSourceBuffer(inst, unused_arg1, filename, codepos); +#endif + } + + // char *__usercall Scr_AddSourceBuffer@(game::scriptInstance_t inst@, int unused_arg1, char *filename, const char *codepos) + NAKED char * Scr_AddSourceBuffer_stub() + { + _asm + { + push eax; + call Scr_AddSourceBuffer_call; + add esp, 0x4; + ret; + } + } + + void Scr_CopyFormattedLine_call(const char * rawLine, [[maybe_unused]] void* caller_addr, char * line) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::Scr_CopyFormattedLine(rawLine, line, Scr_CopyFormattedLine_original); +#else + codsrc::Scr_CopyFormattedLine(rawLine, line); +#endif + } + + // void __usercall Scr_CopyFormattedLine(const char *rawLine@, char *line) + NAKED void Scr_CopyFormattedLine_stub() + { + _asm + { + push eax; + call Scr_CopyFormattedLine_call; + add esp, 0x4; + ret; + } + } + + unsigned int Scr_GetLineInfo_call(int * col, const char * buf, [[maybe_unused]] void* caller_addr, unsigned int sourcePos, char * line) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return game::Scr_GetLineInfo(col, buf, sourcePos, line, Scr_GetLineInfo_original); +#else + return codsrc::Scr_GetLineInfo(col, buf, sourcePos, line); +#endif + } + + // unsigned int __usercall Scr_GetLineInfo@(int *col@, _BYTE *buf@, unsigned int sourcePos, char *line) + NAKED unsigned int Scr_GetLineInfo_stub() + { + _asm + { + push ecx; + push edx; + call Scr_GetLineInfo_call; + add esp, 0x8; + ret; + } + } + + void Scr_PrintSourcePos_call(unsigned int sourcePos, const char * buf, game::con_channel_e channel, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a4, const char * file) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::Scr_PrintSourcePos(sourcePos, buf, channel, a4, file, Scr_PrintSourcePos_original); +#else + codsrc::Scr_PrintSourcePos(sourcePos, buf, channel, a4, file); +#endif + } + + // void __usercall Scr_PrintSourcePos(unsigned int sourcePos@, const char *buf@, con_channel_e channel@, game::scriptInstance_t a4, const char *file) + NAKED void Scr_PrintSourcePos_stub() + { + _asm + { + push esi; + push ecx; + push edx; + call Scr_PrintSourcePos_call; + add esp, 0xC; + ret; + } + } + + game::OpcodeLookup * Scr_GetPrevSourcePosOpcodeLookup_call(game::scriptInstance_t a1, const char * codePos, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + return game::Scr_GetPrevSourcePosOpcodeLookup(a1, codePos, Scr_GetPrevSourcePosOpcodeLookup_original); +#else + return codsrc::Scr_GetPrevSourcePosOpcodeLookup(a1, codePos); +#endif + } + + // OpcodeLookup *__usercall Scr_GetPrevSourcePosOpcodeLookup@(game::scriptInstance_t a1@, const char *codePos@) + NAKED game::OpcodeLookup * Scr_GetPrevSourcePosOpcodeLookup_stub() + { + _asm + { + push edi; + push eax; + call Scr_GetPrevSourcePosOpcodeLookup_call; + add esp, 0x8; + ret; + } + } + + void Scr_GetTextSourcePos_call(char * line, const char * codePos, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::Scr_GetTextSourcePos(line, codePos, a3, Scr_GetTextSourcePos_original); +#else + codsrc::Scr_GetTextSourcePos(line, codePos, a3); +#endif + } + + // void __usercall Scr_GetTextSourcePos(char *line@, const char *codePos@, game::scriptInstance_t a3) + NAKED void Scr_GetTextSourcePos_stub() + { + _asm + { + push ecx; + push edx; + call Scr_GetTextSourcePos_call; + add esp, 0x8; + ret; + } + } + + void Scr_PrintPrevCodePos_call(const char * codepos, [[maybe_unused]] void* caller_addr, game::scriptInstance_t scriptInstance, game::con_channel_e channel, unsigned int index) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::Scr_PrintPrevCodePos(codepos, scriptInstance, channel, index, Scr_PrintPrevCodePos_original); +#else + codsrc::Scr_PrintPrevCodePos(codepos, scriptInstance, channel, index); +#endif + } + + // void __usercall Scr_PrintPrevCodePos(const char *codepos@, game::scriptInstance_t scriptInstance, con_channel_e channel, unsigned int index) + NAKED void Scr_PrintPrevCodePos_stub() + { + _asm + { + push eax; + call Scr_PrintPrevCodePos_call; + add esp, 0x4; + ret; + } + } + + void CompileError_stub(game::scriptInstance_t a1, unsigned int codePos, const char * msg, ...) + { + char Buffer[1024]; + va_list ArgList; + va_start(ArgList, msg); + + _vsnprintf(Buffer, 0x400u, msg, ArgList); + va_end(ArgList); +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + CompileError_hook.invoke(a1, codePos, "%s", Buffer); +#else + codsrc::CompileError(a1, codePos, "%s", Buffer); +#endif + } + + void CompileError2_call(const char * codePos, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, const char * msg, ...) + { + char Buffer[1024]; + va_list ArgList; + va_start(ArgList, msg); + + _vsnprintf(Buffer, 0x400u, msg, ArgList); + va_end(ArgList); +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::CompileError2(codePos, a2, CompileError2_original, "%s", Buffer); +#else + codsrc::CompileError2(codePos, a2, "%s", Buffer); +#endif + + } + + // void __usercall CompileError2(const char *codePos@, game::scriptInstance_t a2@, char *msg, ...) + NAKED void CompileError2_stub() + { + _asm + { + push esi; + push edi; + call CompileError2_call; + add esp, 0x8; + ret; + } + } + + void RuntimeErrorInternal_call(const char * msg, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::con_channel_e channel, const char * codepos, int index) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::RuntimeErrorInternal(msg, inst, channel, codepos, index, RuntimeErrorInternal_original); +#else + codsrc::RuntimeErrorInternal(msg, inst, channel, codepos, index); +#endif + } + + // void __usercall RuntimeErrorInternal(const char *msg@, game::scriptInstance_t inst@, con_channel_e channel, const char *codepos, int index) + NAKED void RuntimeErrorInternal_stub() + { + _asm + { + push edi; + push eax; + call RuntimeErrorInternal_call; + add esp, 0x8; + ret; + } + } + + void RuntimeError_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * pos, int error_index, const char * err, const char * err2) + { +#ifdef RE_CSCR_PARSER_USE_WRAPPERS + game::RuntimeError(inst, pos, error_index, err, err2, RuntimeError_original); +#else + codsrc::RuntimeError(inst, pos, error_index, err, err2); +#endif + } + + // void __usercall RuntimeError(game::scriptInstance_t inst@, const char *pos, int error_index, const char *err, const char *err2) + NAKED void RuntimeError_stub() + { + _asm + { + push eax; + call RuntimeError_call; + add esp, 0x4; + ret; + } + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + Scr_InitOpcodeLookup_hook.create(game::Scr_InitOpcodeLookup_ADDR(), Scr_InitOpcodeLookup_stub); + Scr_ShutdownOpcodeLookup_hook.create(game::Scr_ShutdownOpcodeLookup_ADDR(), Scr_ShutdownOpcodeLookup_stub); + AddOpcodePos_hook.create(game::AddOpcodePos_ADDR(), AddOpcodePos_stub); + RemoveOpcodePos_hook.create(game::RemoveOpcodePos_ADDR(), RemoveOpcodePos_stub); + AddThreadStartOpcodePos_hook.create(game::AddThreadStartOpcodePos_ADDR(), AddThreadStartOpcodePos_stub); + Scr_GetSourceBuffer_hook.create(game::Scr_GetSourceBuffer_ADDR(), Scr_GetSourceBuffer_stub); + Scr_GetLineNumInternal_hook.create(game::Scr_GetLineNumInternal_ADDR(), Scr_GetLineNumInternal_stub); + Scr_GetNewSourceBuffer_hook.create(game::Scr_GetNewSourceBuffer_ADDR(), Scr_GetNewSourceBuffer_stub); + Scr_AddSourceBufferInternal_hook.create(game::Scr_AddSourceBufferInternal_ADDR(), Scr_AddSourceBufferInternal_stub); + Scr_ReadFile_FastFile_hook.create(game::Scr_ReadFile_FastFile.get(), Scr_ReadFile_FastFile_stub); + Scr_ReadFile_LoadObj_hook.create(game::Scr_ReadFile_LoadObj.get(), Scr_ReadFile_LoadObj_stub); + Scr_ReadFile_hook.create(game::Scr_ReadFile_ADDR(), Scr_ReadFile_stub); + Scr_AddSourceBuffer_hook.create(game::Scr_AddSourceBuffer_ADDR(), Scr_AddSourceBuffer_stub); + Scr_CopyFormattedLine_hook.create(game::Scr_CopyFormattedLine_ADDR(), Scr_CopyFormattedLine_stub); + Scr_GetLineInfo_hook.create(game::Scr_GetLineInfo_ADDR(), Scr_GetLineInfo_stub); + Scr_PrintSourcePos_hook.create(game::Scr_PrintSourcePos_ADDR(), Scr_PrintSourcePos_stub); + Scr_GetPrevSourcePosOpcodeLookup_hook.create(game::Scr_GetPrevSourcePosOpcodeLookup_ADDR(), Scr_GetPrevSourcePosOpcodeLookup_stub); + Scr_GetTextSourcePos_hook.create(game::Scr_GetTextSourcePos_ADDR(), Scr_GetTextSourcePos_stub); + Scr_PrintPrevCodePos_hook.create(game::Scr_PrintPrevCodePos_ADDR(), Scr_PrintPrevCodePos_stub); + CompileError_hook.create(game::CompileError.get(), CompileError_stub); + CompileError2_hook.create(game::CompileError2_ADDR(), CompileError2_stub); + RuntimeErrorInternal_hook.create(game::RuntimeErrorInternal_ADDR(), RuntimeErrorInternal_stub); + RuntimeError_hook.create(game::RuntimeError_ADDR(), RuntimeError_stub); + + //Original hook function addresses + Scr_InitOpcodeLookup_original = Scr_InitOpcodeLookup_hook.get_original(); + Scr_ShutdownOpcodeLookup_original = Scr_ShutdownOpcodeLookup_hook.get_original(); + AddOpcodePos_original = AddOpcodePos_hook.get_original(); + RemoveOpcodePos_original = RemoveOpcodePos_hook.get_original(); + AddThreadStartOpcodePos_original = AddThreadStartOpcodePos_hook.get_original(); + Scr_GetSourceBuffer_original = Scr_GetSourceBuffer_hook.get_original(); + Scr_GetLineNumInternal_original = Scr_GetLineNumInternal_hook.get_original(); + Scr_GetNewSourceBuffer_original = Scr_GetNewSourceBuffer_hook.get_original(); + Scr_AddSourceBufferInternal_original = Scr_AddSourceBufferInternal_hook.get_original(); + Scr_ReadFile_FastFile_original = Scr_ReadFile_FastFile_hook.get_original(); + Scr_ReadFile_LoadObj_original = Scr_ReadFile_LoadObj_hook.get_original(); + Scr_ReadFile_original = Scr_ReadFile_hook.get_original(); + Scr_AddSourceBuffer_original = Scr_AddSourceBuffer_hook.get_original(); + Scr_CopyFormattedLine_original = Scr_CopyFormattedLine_hook.get_original(); + Scr_GetLineInfo_original = Scr_GetLineInfo_hook.get_original(); + Scr_PrintSourcePos_original = Scr_PrintSourcePos_hook.get_original(); + Scr_GetPrevSourcePosOpcodeLookup_original = Scr_GetPrevSourcePosOpcodeLookup_hook.get_original(); + Scr_GetTextSourcePos_original = Scr_GetTextSourcePos_hook.get_original(); + Scr_PrintPrevCodePos_original = Scr_PrintPrevCodePos_hook.get_original(); + CompileError_original = CompileError_hook.get_original(); + CompileError2_original = CompileError2_hook.get_original(); + RuntimeErrorInternal_original = RuntimeErrorInternal_hook.get_original(); + RuntimeError_original = RuntimeError_hook.get_original(); + } + + private: + }; +} +REGISTER_COMPONENT(re_cscr_parser::component) \ No newline at end of file diff --git a/src/component/decomp/clientscript/re_cscr_parsetree.cpp b/src/component/decomp/clientscript/re_cscr_parsetree.cpp new file mode 100644 index 0000000..118dc5d --- /dev/null +++ b/src/component/decomp/clientscript/re_cscr_parsetree.cpp @@ -0,0 +1,198 @@ +#include +#include "loader/component_loader.hpp" +#include "utils/hook.hpp" +//#include "codsrc/clientscript/cscr_parsetree.hpp" + +#define RE_CSCR_PARSETREE_USE_WRAPPERS + + +namespace re_cscr_parsetree +{ + utils::hook::detour Scr_InitAllocNode_hook; + utils::hook::detour node0_hook; + utils::hook::detour node1_hook; + utils::hook::detour node2_hook; + utils::hook::detour node3_hook; + utils::hook::detour node4_hook; + utils::hook::detour node5_hook; + utils::hook::detour node6_hook; + utils::hook::detour node7_hook; + utils::hook::detour node8_hook; + utils::hook::detour linked_list_end_hook; + utils::hook::detour prepend_node_hook; + utils::hook::detour append_node_hook; + + void* Scr_InitAllocNode_original; + void* node0_original; + void* node1_original; + void* node2_original; + void* node3_original; + void* node4_original; + void* node5_original; + void* node6_original; + void* node7_original; + void* node8_original; + void* linked_list_end_original; + void* prepend_node_original; + void* append_node_original; + + namespace + { + + void Scr_InitAllocNode_stub(game::scriptInstance_t inst) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + Scr_InitAllocNode_hook.invoke(inst); +#else + codsrc::Scr_InitAllocNode(inst); +#endif + } + + game::sval_u node0_stub() + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node0_hook.invoke(); +#else + return codsrc::node0(); +#endif + } + + game::sval_u node1_stub(game::scr_enum_t type, game::sval_u val1) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node1_hook.invoke(type, val1); +#else + return codsrc::node1(type, val1); +#endif + } + + game::sval_u node2_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node2_hook.invoke(type, val1, val2); +#else + return codsrc::node2(type, val1, val2); +#endif + } + + game::sval_u node3_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node3_hook.invoke(type, val1, val2, val3); +#else + return codsrc::node3(type, val1, val2, val3); +#endif + } + + game::sval_u node4_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node4_hook.invoke(type, val1, val2, val3, val4); +#else + return codsrc::node4(type, val1, val2, val3, val4); +#endif + } + + game::sval_u node5_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node5_hook.invoke(type, val1, val2, val3, val4, val5); +#else + return codsrc::node5(type, val1, val2, val3, val4, val5); +#endif + } + + game::sval_u node6_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node6_hook.invoke(val1, val2, val3, val4, val5, val6); +#else + return codsrc::node6(val1, val2, val3, val4, val5, val6); +#endif + } + + game::sval_u node7_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node7_hook.invoke(val1, val2, val3, val4, val5, val6, val7); +#else + return codsrc::node7(val1, val2, val3, val4, val5, val6, val7); +#endif + } + + game::sval_u node8_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7, game::sval_u val8) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return node8_hook.invoke(val1, val2, val3, val4, val5, val6, val7, val8); +#else + return codsrc::node8(val1, val2, val3, val4, val5, val6, val7, val8); +#endif + } + + game::sval_u linked_list_end_stub(game::sval_u val1) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return linked_list_end_hook.invoke(val1); +#else + return codsrc::linked_list_end(val1); +#endif + } + + game::sval_u prepend_node_stub(game::sval_u val1, game::sval_u val2) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return prepend_node_hook.invoke(val1, val2); +#else + return codsrc::prepend_node(val1, val2); +#endif + } + + game::sval_u append_node_stub(game::sval_u val1, game::sval_u val2) + { +#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS + return append_node_hook.invoke(val1, val2); +#else + return codsrc::append_node(val1, val2); +#endif + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + //Scr_InitAllocNode_hook.create(game::Scr_InitAllocNode.get(), Scr_InitAllocNode_stub); + node0_hook.create(game::node0.get(), node0_stub); + node1_hook.create(game::node1.get(), node1_stub); + node2_hook.create(game::node2.get(), node2_stub); + node3_hook.create(game::node3.get(), node3_stub); + node4_hook.create(game::node4.get(), node4_stub); + node5_hook.create(game::node5.get(), node5_stub); + node6_hook.create(game::node6.get(), node6_stub); + node7_hook.create(game::node7.get(), node7_stub); + node8_hook.create(game::node8.get(), node8_stub); + linked_list_end_hook.create(game::linked_list_end.get(), linked_list_end_stub); + prepend_node_hook.create(game::prepend_node.get(), prepend_node_stub); + append_node_hook.create(game::append_node.get(), append_node_stub); + + //Original hook function addresses + Scr_InitAllocNode_original = Scr_InitAllocNode_hook.get_original(); + node0_original = node0_hook.get_original(); + node1_original = node1_hook.get_original(); + node2_original = node2_hook.get_original(); + node3_original = node3_hook.get_original(); + node4_original = node4_hook.get_original(); + node5_original = node5_hook.get_original(); + node6_original = node6_hook.get_original(); + node7_original = node7_hook.get_original(); + node8_original = node8_hook.get_original(); + linked_list_end_original = linked_list_end_hook.get_original(); + prepend_node_original = prepend_node_hook.get_original(); + append_node_original = append_node_hook.get_original(); + } + + private: + }; +} +REGISTER_COMPONENT(re_cscr_parsetree::component) \ No newline at end of file diff --git a/src/component/decomp/clientscript/re_cscr_readwrite.cpp b/src/component/decomp/clientscript/re_cscr_readwrite.cpp new file mode 100644 index 0000000..3d8b6bb --- /dev/null +++ b/src/component/decomp/clientscript/re_cscr_readwrite.cpp @@ -0,0 +1,79 @@ +#include +#include "loader/component_loader.hpp" +#include "utils/hook.hpp" +//#include "codsrc/clientscript/cscr_readwrite.hpp" + +#define RE_CSCR_READWRITE_USE_WRAPPERS + +namespace re_cscr_readwrite +{ + utils::hook::detour FindVariableIndexInternal2_hook; + utils::hook::detour FindLastSibling_hook; + + void* FindVariableIndexInternal2_original; + void* FindLastSibling_original; + + namespace + { + + unsigned int FindVariableIndexInternal2_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int name, unsigned int index) + { +#ifdef RE_CSCR_READWRITE_USE_WRAPPERS + return game::FindVariableIndexInternal2(inst, name, index, FindVariableIndexInternal2_original); +#else + return codsrc::FindVariableIndexInternal2(inst, name, index); +#endif + } + + // unsigned int __usercall FindVariableIndexInternal2@(scriptInstance_t inst@, unsigned int name, unsigned int index) + NAKED unsigned int FindVariableIndexInternal2_stub() + { + _asm + { + push eax; + call FindVariableIndexInternal2_call; + add esp, 0x4; + ret; + } + } + + unsigned int FindLastSibling_call(unsigned int parentId, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_READWRITE_USE_WRAPPERS + return game::FindLastSibling(parentId, inst, FindLastSibling_original); +#else + return codsrc::FindLastSibling(parentId, inst); +#endif + } + + // unsigned int __usercall FindLastSibling@(unsigned int parentId@, scriptInstance_t inst@) + NAKED unsigned int FindLastSibling_stub() + { + _asm + { + push esi; + push edx; + call FindLastSibling_call; + add esp, 0x8; + ret; + } + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + FindVariableIndexInternal2_hook.create(game::FindVariableIndexInternal2_ADDR(), FindVariableIndexInternal2_stub); + FindLastSibling_hook.create(game::FindLastSibling_ADDR(), FindLastSibling_stub); + + //Original hook function addresses + FindVariableIndexInternal2_original = FindVariableIndexInternal2_hook.get_original(); + FindLastSibling_original = FindLastSibling_hook.get_original(); + } + + private: + }; +} +REGISTER_COMPONENT(re_cscr_readwrite::component) \ No newline at end of file diff --git a/src/component/decomp/clientscript/re_cscr_stringlist.cpp b/src/component/decomp/clientscript/re_cscr_stringlist.cpp new file mode 100644 index 0000000..a88604f --- /dev/null +++ b/src/component/decomp/clientscript/re_cscr_stringlist.cpp @@ -0,0 +1,653 @@ +#include +#include "loader/component_loader.hpp" +#include "utils/hook.hpp" +//#include "codsrc/clientscript/cscr_stringlist.hpp" + +#define RE_CSCR_STRINGLIST_USE_WRAPPERS + + +namespace re_cscr_stringlist +{ + utils::hook::detour SL_ConvertToString_hook; + utils::hook::detour SL_GetStringLen_hook; + utils::hook::detour GetHashCode_hook; + utils::hook::detour SL_Init_hook; + utils::hook::detour SL_FindStringOfSize_hook; + utils::hook::detour SL_FindString_hook; + utils::hook::detour SL_FindLowercaseString_hook; + utils::hook::detour SL_AddUserInternal_hook; + utils::hook::detour Mark_ScriptStringCustom_hook; + utils::hook::detour SL_GetStringOfSize_hook; + utils::hook::detour SL_GetString__hook; + utils::hook::detour SL_GetString__0_hook; + utils::hook::detour SL_GetLowercaseStringOfLen_hook; + utils::hook::detour SL_GetLowercaseString_hook; + utils::hook::detour SL_ConvertToLowercase_hook; + utils::hook::detour SL_TransferRefToUser_hook; + utils::hook::detour SL_FreeString_hook; + utils::hook::detour SL_RemoveRefToString_hook; + utils::hook::detour Scr_SetString_hook; + utils::hook::detour Scr_SetStringFromCharString_hook; + utils::hook::detour GScr_AllocString_hook; + utils::hook::detour SL_GetStringForFloat_hook; + utils::hook::detour SL_GetStringForInt_hook; + utils::hook::detour SL_GetStringForVector_hook; + utils::hook::detour SL_ShutdownSystem_hook; + utils::hook::detour SL_TransferSystem_hook; + utils::hook::detour SL_CreateCanonicalFilename_hook; + utils::hook::detour Scr_CreateCanonicalFilename_hook; + + void* SL_ConvertToString_original; + void* SL_GetStringLen_original; + void* GetHashCode_original; + void* SL_Init_original; + void* SL_FindStringOfSize_original; + void* SL_FindString_original; + void* SL_FindLowercaseString_original; + void* SL_AddUserInternal_original; + void* Mark_ScriptStringCustom_original; + void* SL_GetStringOfSize_original; + void* SL_GetString__original; + void* SL_GetString__0_original; + void* SL_GetLowercaseStringOfLen_original; + void* SL_GetLowercaseString_original; + void* SL_ConvertToLowercase_original; + void* SL_TransferRefToUser_original; + void* SL_FreeString_original; + void* SL_RemoveRefToString_original; + void* Scr_SetString_original; + void* Scr_SetStringFromCharString_original; + void* GScr_AllocString_original; + void* SL_GetStringForFloat_original; + void* SL_GetStringForInt_original; + void* SL_GetStringForVector_original; + void* SL_ShutdownSystem_original; + void* SL_TransferSystem_original; + void* SL_CreateCanonicalFilename_original; + void* Scr_CreateCanonicalFilename_original; + + namespace + { + + char* SL_ConvertToString_call(unsigned int id, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_ConvertToString(id, inst, SL_ConvertToString_original); +#else + return codsrc::SL_ConvertToString(id, inst); +#endif + } + + // char *__usercall SL_ConvertToString@(unsigned int id@, game::scriptInstance_t inst@) + NAKED char* SL_ConvertToString_stub() + { + _asm + { + push ecx; + push eax; + call SL_ConvertToString_call; + add esp, 0x8; + ret; + } + } + + int SL_GetStringLen_call(unsigned int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_GetStringLen(a1, a2, SL_GetStringLen_original); +#else + return codsrc::SL_GetStringLen(a1, a2); +#endif + } + + // int __usercall SL_GetStringLen@(unsigned int a1@, game::scriptInstance_t a2@) + NAKED int SL_GetStringLen_stub() + { + _asm + { + push ecx; + push eax; + call SL_GetStringLen_call; + add esp, 0x8; + ret; + } + } + + unsigned int GetHashCode_call(unsigned int a1, const char* a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::GetHashCode(a1, a2, GetHashCode_original); +#else + return codsrc::GetHashCode(a1, a2); +#endif + } + + // unsigned int __usercall GetHashCode@(unsigned int a1@, const char *a2@) + NAKED unsigned int GetHashCode_stub() + { + _asm + { + push edx; + push eax; + call GetHashCode_call; + add esp, 0x8; + ret; + } + } + + void SL_Init_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::SL_Init(a1, SL_Init_original); +#else + codsrc::SL_Init(a1); +#endif + } + + // void __usercall SL_Init(game::scriptInstance_t a1@) + NAKED void SL_Init_stub() + { + _asm + { + push eax; + call SL_Init_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_FindStringOfSize_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char* str_, unsigned int len) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_FindStringOfSize(inst, str_, len, SL_FindStringOfSize_original); +#else + return codsrc::SL_FindStringOfSize(inst, str_, len); +#endif + } + + // unsigned int __usercall SL_FindStringOfSize@(game::scriptInstance_t inst@, const char *str, unsigned int len) + NAKED unsigned int SL_FindStringOfSize_stub() + { + _asm + { + push eax; + call SL_FindStringOfSize_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_FindString_call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_FindString(a1, a2, SL_FindString_original); +#else + return codsrc::SL_FindString(a1, a2); +#endif + } + + // unsigned int __usercall SL_FindString@(const char *a1@, game::scriptInstance_t a2) + NAKED unsigned int SL_FindString_stub() + { + _asm + { + push edx; + call SL_FindString_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_FindLowercaseString_stub(const char* str, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return SL_FindLowercaseString_hook.invoke(str, inst); +#else + return codsrc::SL_FindLowercaseString(str, inst); +#endif + } + + void SL_AddUserInternal_call(unsigned int user, game::RefString* refStr, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::SL_AddUserInternal(user, refStr, SL_AddUserInternal_original); +#else + codsrc::SL_AddUserInternal(user, refStr); +#endif + } + + // void __usercall SL_AddUserInternal(unsigned int user@, RefString *refStr@) + NAKED void SL_AddUserInternal_stub() + { + _asm + { + push edx; + push eax; + call SL_AddUserInternal_call; + add esp, 0x8; + ret; + } + } + + void Mark_ScriptStringCustom_call(unsigned int a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::Mark_ScriptStringCustom(a1, Mark_ScriptStringCustom_original); +#else + codsrc::Mark_ScriptStringCustom(a1); +#endif + } + + // void __usercall Mark_ScriptStringCustom(unsigned __int16 *a1@) + NAKED void Mark_ScriptStringCustom_stub() + { + _asm + { + push eax; + call Mark_ScriptStringCustom_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_GetStringOfSize_stub(game::scriptInstance_t inst, const char* string, unsigned int user, unsigned int len) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return SL_GetStringOfSize_hook.invoke(inst, string, user, len); +#else + return codsrc::SL_GetStringOfSize(inst, string, user, len); +#endif + } + + unsigned int SL_GetString__call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2, unsigned int user) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_GetString_(a1, a2, user, SL_GetString__original); +#else + return codsrc::SL_GetString_(a1, a2, user); +#endif + } + + // unsigned int __usercall SL_GetString_@(const char *a1@, game::scriptInstance_t a2, unsigned int user) + NAKED unsigned int SL_GetString__stub() + { + _asm + { + push edx; + call SL_GetString__call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_GetString__0_call(const char* a1, [[maybe_unused]] void* caller_addr, unsigned int user, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_GetString__0(a1, user, a3, SL_GetString__0_original); +#else + return codsrc::SL_GetString__0(a1, user, a3); +#endif + } + + // unsigned int __usercall SL_GetString__0@(const char *a1@, unsigned int user, game::scriptInstance_t a3) + NAKED unsigned int SL_GetString__0_stub() + { + _asm + { + push edx; + call SL_GetString__0_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_GetLowercaseStringOfLen_stub(game::scriptInstance_t a1, const char* ArgList, unsigned int user, unsigned int len) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return SL_GetLowercaseStringOfLen_hook.invoke(a1, ArgList, user, len); +#else + return codsrc::SL_GetLowercaseStringOfLen(a1, ArgList, user, len); +#endif + } + + unsigned int SL_GetLowercaseString_call(const char* a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_GetLowercaseString(a2, SL_GetLowercaseString_original); +#else + return codsrc::SL_GetLowercaseString(a2); +#endif + } + + // unsigned int __usercall SL_GetLowercaseString@(const char *a2@) + NAKED unsigned int SL_GetLowercaseString_stub() + { + _asm + { + push edx; + call SL_GetLowercaseString_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_ConvertToLowercase_stub(game::scriptInstance_t inst, unsigned int stringVal, unsigned int user) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return SL_ConvertToLowercase_hook.invoke(inst, stringVal, user); +#else + return codsrc::SL_ConvertToLowercase(inst, stringVal, user); +#endif + } + + void SL_TransferRefToUser_call(unsigned int stringValue, unsigned int user, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::SL_TransferRefToUser(stringValue, user, inst, SL_TransferRefToUser_original); +#else + codsrc::SL_TransferRefToUser(stringValue, user, inst); +#endif + } + + // void __usercall SL_TransferRefToUser(unsigned int stringValue@, unsigned int user@, game::scriptInstance_t inst) + NAKED void SL_TransferRefToUser_stub() + { + _asm + { + push ecx; + push eax; + call SL_TransferRefToUser_call; + add esp, 0x8; + ret; + } + } + + void SL_FreeString_stub(game::scriptInstance_t a1, unsigned int a2, game::RefString* a3, unsigned int a4) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + SL_FreeString_hook.invoke(a1, a2, a3, a4); +#else + codsrc::SL_FreeString(a1, a2, a3, a4); +#endif + } + + void SL_RemoveRefToString_call(unsigned int stringVal, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::SL_RemoveRefToString(stringVal, inst, SL_RemoveRefToString_original); +#else + codsrc::SL_RemoveRefToString(stringVal, inst); +#endif + } + + // void __usercall SL_RemoveRefToString(unsigned int stringVal@, game::scriptInstance_t inst@) + NAKED void SL_RemoveRefToString_stub() + { + _asm + { + push esi; + push edx; + call SL_RemoveRefToString_call; + add esp, 0x8; + ret; + } + } + + void Scr_SetString_call(game::scriptInstance_t inst, unsigned int from, [[maybe_unused]] void* caller_addr, unsigned __int16* to) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::Scr_SetString(inst, from, to, Scr_SetString_original); +#else + codsrc::Scr_SetString(inst, from, to); +#endif + } + + // void __usercall Scr_SetString(game::scriptInstance_t inst@, unsigned int from@, unsigned __int16 *to) + NAKED void Scr_SetString_stub() + { + _asm + { + push edi; + push eax; + call Scr_SetString_call; + add esp, 0x8; + ret; + } + } + + void Scr_SetStringFromCharString_call(const char* a1, [[maybe_unused]] void* caller_addr, unsigned __int16* a2) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::Scr_SetStringFromCharString(a1, a2, Scr_SetStringFromCharString_original); +#else + codsrc::Scr_SetStringFromCharString(a1, a2); +#endif + } + + // unsigned int __usercall Scr_SetStringFromCharString@(const char *a1@, unsigned __int16 *a2) + NAKED void Scr_SetStringFromCharString_stub() + { + _asm + { + push edi; + call Scr_SetStringFromCharString_call; + add esp, 0x4; + ret; + } + } + + unsigned int GScr_AllocString_call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::GScr_AllocString(a1, inst, GScr_AllocString_original); +#else + return codsrc::GScr_AllocString(a1, inst); +#endif + } + + // unsigned int __usercall GScr_AllocString@(const char *a1@, game::scriptInstance_t inst) + NAKED unsigned int GScr_AllocString_stub() + { + _asm + { + push edx; + call GScr_AllocString_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_GetStringForFloat_call(float a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_GetStringForFloat(a1, a2, SL_GetStringForFloat_original); +#else + return codsrc::SL_GetStringForFloat(a1, a2); +#endif + } + + // unsigned int __usercall SL_GetStringForFloat@(float a1@, game::scriptInstance_t a2) + NAKED unsigned int SL_GetStringForFloat_stub() + { + _asm + { + movd eax, xmm0; + push eax; + call SL_GetStringForFloat_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_GetStringForInt_call(int a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_GetStringForInt(a1, a2, SL_GetStringForInt_original); +#else + return codsrc::SL_GetStringForInt(a1, a2); +#endif + } + + // unsigned int __usercall SL_GetStringForInt@(int a1@, game::scriptInstance_t a2) + NAKED unsigned int SL_GetStringForInt_stub() + { + _asm + { + push eax; + call SL_GetStringForInt_call; + add esp, 0x4; + ret; + } + } + + unsigned int SL_GetStringForVector_call(float* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return game::SL_GetStringForVector(a1, a2, SL_GetStringForVector_original); +#else + return codsrc::SL_GetStringForVector(a1, a2); +#endif + } + + // unsigned int __usercall SL_GetStringForVector@(float *a1@, game::scriptInstance_t a2) + NAKED unsigned int SL_GetStringForVector_stub() + { + _asm + { + push eax; + call SL_GetStringForVector_call; + add esp, 0x4; + ret; + } + } + + void SL_ShutdownSystem_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::SL_ShutdownSystem(a1, a2, SL_ShutdownSystem_original); +#else + codsrc::SL_ShutdownSystem(a1, a2); +#endif + } + + // void __usercall SL_ShutdownSystem(game::scriptInstance_t a1@, unsigned int a2) + NAKED void SL_ShutdownSystem_stub() + { + _asm + { + push edi; + call SL_ShutdownSystem_call; + add esp, 0x4; + ret; + } + } + + void SL_TransferSystem_stub() + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + SL_TransferSystem_hook.invoke(); +#else + codsrc::SL_TransferSystem(); +#endif + } + + void SL_CreateCanonicalFilename_call(const char* filename, [[maybe_unused]] void* caller_addr, char* newFilename) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + game::SL_CreateCanonicalFilename(filename, newFilename, SL_CreateCanonicalFilename_original); +#else + codsrc::SL_CreateCanonicalFilename(filename, newFilename); +#endif + } + + // void __usercall SL_CreateCanonicalFilename(const char *filename@, char *newFilename) + NAKED void SL_CreateCanonicalFilename_stub() + { + _asm + { + push eax; + call SL_CreateCanonicalFilename_call; + add esp, 0x4; + ret; + } + } + + unsigned int Scr_CreateCanonicalFilename_stub(game::scriptInstance_t a1, const char* a2) + { +#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS + return Scr_CreateCanonicalFilename_hook.invoke(a1, a2); +#else + return codsrc::Scr_CreateCanonicalFilename(a1, a2); +#endif + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + SL_ConvertToString_hook.create(game::SL_ConvertToString_ADDR(), SL_ConvertToString_stub); + SL_GetStringLen_hook.create(game::SL_GetStringLen_ADDR(), SL_GetStringLen_stub); + GetHashCode_hook.create(game::GetHashCode_ADDR(), GetHashCode_stub); + SL_Init_hook.create(game::SL_Init_ADDR(), SL_Init_stub); + SL_FindStringOfSize_hook.create(game::SL_FindStringOfSize_ADDR(), SL_FindStringOfSize_stub); + SL_FindString_hook.create(game::SL_FindString_ADDR(), SL_FindString_stub); + SL_FindLowercaseString_hook.create(game::SL_FindLowercaseString.get(), SL_FindLowercaseString_stub); + SL_AddUserInternal_hook.create(game::SL_AddUserInternal_ADDR(), SL_AddUserInternal_stub); + Mark_ScriptStringCustom_hook.create(game::Mark_ScriptStringCustom_ADDR(), Mark_ScriptStringCustom_stub); + SL_GetStringOfSize_hook.create(game::SL_GetStringOfSize.get(), SL_GetStringOfSize_stub); + SL_GetString__hook.create(game::SL_GetString__ADDR(), SL_GetString__stub); + SL_GetString__0_hook.create(game::SL_GetString__0_ADDR(), SL_GetString__0_stub); + SL_GetLowercaseStringOfLen_hook.create(game::SL_GetLowercaseStringOfLen.get(), SL_GetLowercaseStringOfLen_stub); + SL_GetLowercaseString_hook.create(game::SL_GetLowercaseString_ADDR(), SL_GetLowercaseString_stub); + SL_ConvertToLowercase_hook.create(game::SL_ConvertToLowercase.get(), SL_ConvertToLowercase_stub); + SL_TransferRefToUser_hook.create(game::SL_TransferRefToUser_ADDR(), SL_TransferRefToUser_stub); + SL_FreeString_hook.create(game::SL_FreeString.get(), SL_FreeString_stub); + SL_RemoveRefToString_hook.create(game::SL_RemoveRefToString_ADDR(), SL_RemoveRefToString_stub); + Scr_SetString_hook.create(game::Scr_SetString_ADDR(), Scr_SetString_stub); + Scr_SetStringFromCharString_hook.create(game::Scr_SetStringFromCharString_ADDR(), Scr_SetStringFromCharString_stub); + GScr_AllocString_hook.create(game::GScr_AllocString_ADDR(), GScr_AllocString_stub); + SL_GetStringForFloat_hook.create(game::SL_GetStringForFloat_ADDR(), SL_GetStringForFloat_stub); + SL_GetStringForInt_hook.create(game::SL_GetStringForInt_ADDR(), SL_GetStringForInt_stub); + SL_GetStringForVector_hook.create(game::SL_GetStringForVector_ADDR(), SL_GetStringForVector_stub); + SL_ShutdownSystem_hook.create(game::SL_ShutdownSystem_ADDR(), SL_ShutdownSystem_stub); + SL_TransferSystem_hook.create(game::SL_TransferSystem.get(), SL_TransferSystem_stub); + SL_CreateCanonicalFilename_hook.create(game::SL_CreateCanonicalFilename_ADDR(), SL_CreateCanonicalFilename_stub); + Scr_CreateCanonicalFilename_hook.create(game::Scr_CreateCanonicalFilename.get(), Scr_CreateCanonicalFilename_stub); + + //Original hook function addresses + SL_ConvertToString_original = SL_ConvertToString_hook.get_original(); + SL_GetStringLen_original = SL_GetStringLen_hook.get_original(); + GetHashCode_original = GetHashCode_hook.get_original(); + SL_Init_original = SL_Init_hook.get_original(); + SL_FindStringOfSize_original = SL_FindStringOfSize_hook.get_original(); + SL_FindString_original = SL_FindString_hook.get_original(); + SL_FindLowercaseString_original = SL_FindLowercaseString_hook.get_original(); + SL_AddUserInternal_original = SL_AddUserInternal_hook.get_original(); + Mark_ScriptStringCustom_original = Mark_ScriptStringCustom_hook.get_original(); + SL_GetStringOfSize_original = SL_GetStringOfSize_hook.get_original(); + SL_GetString__original = SL_GetString__hook.get_original(); + SL_GetString__0_original = SL_GetString__0_hook.get_original(); + SL_GetLowercaseStringOfLen_original = SL_GetLowercaseStringOfLen_hook.get_original(); + SL_GetLowercaseString_original = SL_GetLowercaseString_hook.get_original(); + SL_ConvertToLowercase_original = SL_ConvertToLowercase_hook.get_original(); + SL_TransferRefToUser_original = SL_TransferRefToUser_hook.get_original(); + SL_FreeString_original = SL_FreeString_hook.get_original(); + SL_RemoveRefToString_original = SL_RemoveRefToString_hook.get_original(); + Scr_SetString_original = Scr_SetString_hook.get_original(); + Scr_SetStringFromCharString_original = Scr_SetStringFromCharString_hook.get_original(); + GScr_AllocString_original = GScr_AllocString_hook.get_original(); + SL_GetStringForFloat_original = SL_GetStringForFloat_hook.get_original(); + SL_GetStringForInt_original = SL_GetStringForInt_hook.get_original(); + SL_GetStringForVector_original = SL_GetStringForVector_hook.get_original(); + SL_ShutdownSystem_original = SL_ShutdownSystem_hook.get_original(); + SL_TransferSystem_original = SL_TransferSystem_hook.get_original(); + SL_CreateCanonicalFilename_original = SL_CreateCanonicalFilename_hook.get_original(); + Scr_CreateCanonicalFilename_original = Scr_CreateCanonicalFilename_hook.get_original(); + } + + private: + }; +} +REGISTER_COMPONENT(re_cscr_stringlist::component) \ No newline at end of file diff --git a/src/component/decomp/clientscript/re_cscr_variable.cpp b/src/component/decomp/clientscript/re_cscr_variable.cpp new file mode 100644 index 0000000..84d03da --- /dev/null +++ b/src/component/decomp/clientscript/re_cscr_variable.cpp @@ -0,0 +1,2527 @@ +#include +#include "loader/component_loader.hpp" +#include "utils/hook.hpp" +//#include "codsrc/clientscript/cscr_variable.hpp" + +#define RE_CSCR_VARIABLE_USE_WRAPPERS + + +namespace re_cscr_variable +{ + utils::hook::detour ThreadInfoCompare_hook; + utils::hook::detour Scr_DumpScriptThreads_hook; + utils::hook::detour Scr_InitVariableRange_hook; + utils::hook::detour Scr_InitClassMap_hook; + utils::hook::detour GetNewVariableIndexInternal3_hook; + utils::hook::detour GetNewVariableIndexInternal2_hook; + utils::hook::detour GetNewVariableIndexReverseInternal2_hook; + utils::hook::detour MakeVariableExternal_hook; + utils::hook::detour FreeChildValue_hook; + utils::hook::detour ClearObjectInternal_hook; + utils::hook::detour ClearObject_hook; + utils::hook::detour Scr_StopThread_hook; + utils::hook::detour GetSafeParentLocalId_hook; + utils::hook::detour GetStartLocalId_hook; + utils::hook::detour Scr_KillThread_hook; + utils::hook::detour AllocVariable_hook; + utils::hook::detour FreeVariable_hook; + utils::hook::detour AllocValue_hook; + utils::hook::detour AllocEntity_hook; + utils::hook::detour Scr_AllocArray_hook; + utils::hook::detour AllocChildThread_hook; + utils::hook::detour FreeValue_hook; + utils::hook::detour RemoveRefToObject_hook; + utils::hook::detour Scr_AllocVector_hook; + utils::hook::detour RemoveRefToVector_hook; + utils::hook::detour AddRefToValue_hook; + utils::hook::detour RemoveRefToValueInternal_hook; + utils::hook::detour FindArrayVariable_hook; + utils::hook::detour FindVariable_hook; + utils::hook::detour GetArrayVariableIndex_hook; + utils::hook::detour Scr_GetVariableFieldIndex_hook; + utils::hook::detour Scr_FindVariableField_hook; + utils::hook::detour ClearVariableField_hook; + utils::hook::detour GetVariable_hook; + utils::hook::detour GetNewVariable_hook; + utils::hook::detour GetObjectVariable_hook; + utils::hook::detour GetNewObjectVariable_hook; + utils::hook::detour RemoveVariable_hook; + utils::hook::detour RemoveNextVariable_hook; + utils::hook::detour SafeRemoveVariable_hook; + utils::hook::detour CopyArray_hook; + utils::hook::detour SetVariableValue_hook; + utils::hook::detour SetVariableEntityFieldValue_hook; + utils::hook::detour Scr_EvalVariable_hook; + utils::hook::detour Scr_EvalVariableObject_hook; + utils::hook::detour Scr_EvalVariableEntityField_hook; + utils::hook::detour Scr_EvalVariableField_hook; + utils::hook::detour Scr_EvalSizeValue_hook; + utils::hook::detour GetObject_hook; + utils::hook::detour GetArray_hook; + utils::hook::detour Scr_EvalBoolComplement_hook; + utils::hook::detour Scr_CastBool_hook; + utils::hook::detour Scr_CastString_hook; + utils::hook::detour Scr_CastDebugString_hook; + utils::hook::detour Scr_ClearVector_hook; + utils::hook::detour Scr_CastVector_hook; + utils::hook::detour Scr_EvalFieldObject_hook; + utils::hook::detour Scr_UnmatchingTypesError_hook; + utils::hook::detour Scr_CastWeakerPair_hook; + utils::hook::detour Scr_CastWeakerStringPair_hook; + utils::hook::detour Scr_EvalOr_hook; + utils::hook::detour Scr_EvalExOr_hook; + utils::hook::detour Scr_EvalAnd_hook; + utils::hook::detour Scr_EvalEquality_hook; + utils::hook::detour Scr_EvalLess_hook; + utils::hook::detour Scr_EvalGreaterEqual_hook; + utils::hook::detour Scr_EvalGreater_hook; + utils::hook::detour Scr_EvalLessEqual_hook; + utils::hook::detour Scr_EvalShiftLeft_hook; + utils::hook::detour Scr_EvalShiftRight_hook; + utils::hook::detour Scr_EvalPlus_hook; + utils::hook::detour Scr_EvalMinus_hook; + utils::hook::detour Scr_EvalMultiply_hook; + utils::hook::detour Scr_EvalDivide_hook; + utils::hook::detour Scr_EvalMod_hook; + utils::hook::detour Scr_EvalBinaryOperator_hook; + utils::hook::detour Scr_FreeEntityNum_hook; + utils::hook::detour Scr_FreeEntityList_hook; + utils::hook::detour Scr_FreeObjects_hook; + utils::hook::detour Scr_SetClassMap_hook; + utils::hook::detour Scr_RemoveClassMap_hook; + utils::hook::detour Scr_AddClassField_hook; + utils::hook::detour Scr_GetOffset_hook; + utils::hook::detour FindEntityId_hook; + utils::hook::detour Scr_GetEntityId_hook; + utils::hook::detour Scr_FindArrayIndex_hook; + utils::hook::detour Scr_EvalArray_hook; + utils::hook::detour Scr_EvalArrayRef_hook; + utils::hook::detour ClearArray_hook; + utils::hook::detour SetEmptyArray_hook; + utils::hook::detour Scr_AddArrayKeys_hook; + utils::hook::detour Scr_GetEntityIdRef_hook; + utils::hook::detour CopyEntity_hook; + utils::hook::detour Scr_GetEndonUsage_hook; + utils::hook::detour Scr_GetObjectUsage_hook; + utils::hook::detour Scr_GetThreadUsage_hook; + utils::hook::detour Scr_FindField_hook; + utils::hook::detour Scr_GetSourceFile_LoadObj_hook; + utils::hook::detour Scr_GetSourceFile_FastFile_hook; + utils::hook::detour Scr_AddFieldsForFile_hook; + utils::hook::detour Scr_AddFields_LoadObj_hook; + utils::hook::detour Scr_AddFields_FastFile_hook; + utils::hook::detour Scr_MakeValuePrimitive_hook; + utils::hook::detour Scr_FreeGameVariable_hook; + utils::hook::detour Scr_SLHasLowercaseString_hook; + + void* ThreadInfoCompare_original; + void* Scr_DumpScriptThreads_original; + void* Scr_InitVariableRange_original; + void* Scr_InitClassMap_original; + void* GetNewVariableIndexInternal3_original; + void* GetNewVariableIndexInternal2_original; + void* GetNewVariableIndexReverseInternal2_original; + void* MakeVariableExternal_original; + void* FreeChildValue_original; + void* ClearObjectInternal_original; + void* ClearObject_original; + void* Scr_StopThread_original; + void* GetSafeParentLocalId_original; + void* GetStartLocalId_original; + void* Scr_KillThread_original; + void* AllocVariable_original; + void* FreeVariable_original; + void* AllocValue_original; + void* AllocEntity_original; + void* Scr_AllocArray_original; + void* AllocChildThread_original; + void* FreeValue_original; + void* RemoveRefToObject_original; + void* Scr_AllocVector_original; + void* RemoveRefToVector_original; + void* AddRefToValue_original; + void* RemoveRefToValueInternal_original; + void* FindArrayVariable_original; + void* FindVariable_original; + void* GetArrayVariableIndex_original; + void* Scr_GetVariableFieldIndex_original; + void* Scr_FindVariableField_original; + void* ClearVariableField_original; + void* GetVariable_original; + void* GetNewVariable_original; + void* GetObjectVariable_original; + void* GetNewObjectVariable_original; + void* RemoveVariable_original; + void* RemoveNextVariable_original; + void* SafeRemoveVariable_original; + void* CopyArray_original; + void* SetVariableValue_original; + void* SetVariableEntityFieldValue_original; + void* Scr_EvalVariable_original; + void* Scr_EvalVariableObject_original; + void* Scr_EvalVariableEntityField_original; + void* Scr_EvalVariableField_original; + void* Scr_EvalSizeValue_original; + void* GetObject_original; + void* GetArray_original; + void* Scr_EvalBoolComplement_original; + void* Scr_CastBool_original; + void* Scr_CastString_original; + void* Scr_CastDebugString_original; + void* Scr_ClearVector_original; + void* Scr_CastVector_original; + void* Scr_EvalFieldObject_original; + void* Scr_UnmatchingTypesError_original; + void* Scr_CastWeakerPair_original; + void* Scr_CastWeakerStringPair_original; + void* Scr_EvalOr_original; + void* Scr_EvalExOr_original; + void* Scr_EvalAnd_original; + void* Scr_EvalEquality_original; + void* Scr_EvalLess_original; + void* Scr_EvalGreaterEqual_original; + void* Scr_EvalGreater_original; + void* Scr_EvalLessEqual_original; + void* Scr_EvalShiftLeft_original; + void* Scr_EvalShiftRight_original; + void* Scr_EvalPlus_original; + void* Scr_EvalMinus_original; + void* Scr_EvalMultiply_original; + void* Scr_EvalDivide_original; + void* Scr_EvalMod_original; + void* Scr_EvalBinaryOperator_original; + void* Scr_FreeEntityNum_original; + void* Scr_FreeEntityList_original; + void* Scr_FreeObjects_original; + void* Scr_SetClassMap_original; + void* Scr_RemoveClassMap_original; + void* Scr_AddClassField_original; + void* Scr_GetOffset_original; + void* FindEntityId_original; + void* Scr_GetEntityId_original; + void* Scr_FindArrayIndex_original; + void* Scr_EvalArray_original; + void* Scr_EvalArrayRef_original; + void* ClearArray_original; + void* SetEmptyArray_original; + void* Scr_AddArrayKeys_original; + void* Scr_GetEntityIdRef_original; + void* CopyEntity_original; + void* Scr_GetEndonUsage_original; + void* Scr_GetObjectUsage_original; + void* Scr_GetThreadUsage_original; + void* Scr_FindField_original; + void* Scr_GetSourceFile_LoadObj_original; + void* Scr_GetSourceFile_FastFile_original; + void* Scr_AddFieldsForFile_original; + void* Scr_AddFields_LoadObj_original; + void* Scr_AddFields_FastFile_original; + void* Scr_MakeValuePrimitive_original; + void* Scr_FreeGameVariable_original; + void* Scr_SLHasLowercaseString_original; + + namespace + { + + int ThreadInfoCompare_stub(game::ThreadDebugInfo * a1, game::ThreadDebugInfo * a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return ThreadInfoCompare_hook.invoke(a1, a2); +#else + return codsrc::ThreadInfoCompare(a1, a2); +#endif + } + + void Scr_DumpScriptThreads_stub(game::scriptInstance_t scriptInstance) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + Scr_DumpScriptThreads_hook.invoke(scriptInstance); +#else + codsrc::Scr_DumpScriptThreads(scriptInstance); +#endif + } + + void Scr_InitVariableRange_call(unsigned int a1, unsigned int a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_InitVariableRange(a1, a2, a3, Scr_InitVariableRange_original); +#else + codsrc::Scr_InitVariableRange(a1, a2, a3); +#endif + } + + // void __usercall Scr_InitVariableRange(unsigned int a1@, unsigned int a2@, game::scriptInstance_t a3) + NAKED void Scr_InitVariableRange_stub() + { + _asm + { + push esi; + push edi; + call Scr_InitVariableRange_call; + add esp, 0x8; + ret; + } + } + + void Scr_InitClassMap_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_InitClassMap(a1, Scr_InitClassMap_original); +#else + codsrc::Scr_InitClassMap(a1); +#endif + } + + // void __usercall Scr_InitClassMap(game::scriptInstance_t a1@) + NAKED void Scr_InitClassMap_stub() + { + _asm + { + push eax; + call Scr_InitClassMap_call; + add esp, 0x4; + ret; + } + } + + unsigned int GetNewVariableIndexInternal3_stub(game::scriptInstance_t inst, unsigned int parentId, unsigned int name, unsigned int index) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return GetNewVariableIndexInternal3_hook.invoke(inst, parentId, name, index); +#else + return codsrc::GetNewVariableIndexInternal3(inst, parentId, name, index); +#endif + } + + unsigned int GetNewVariableIndexInternal2_call(unsigned int name, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetNewVariableIndexInternal2(name, inst, parentId, index, GetNewVariableIndexInternal2_original); +#else + return codsrc::GetNewVariableIndexInternal2(name, inst, parentId, index); +#endif + } + + // unsigned int __usercall GetNewVariableIndexInternal2@(unsigned int name@, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) + NAKED unsigned int GetNewVariableIndexInternal2_stub() + { + _asm + { + push ecx; + call GetNewVariableIndexInternal2_call; + add esp, 0x4; + ret; + } + } + + unsigned int GetNewVariableIndexReverseInternal2_call(unsigned int name, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetNewVariableIndexReverseInternal2(name, inst, parentId, index, GetNewVariableIndexReverseInternal2_original); +#else + return codsrc::GetNewVariableIndexReverseInternal2(name, inst, parentId, index); +#endif + } + + // unsigned int __usercall GetNewVariableIndexReverseInternal2@(unsigned int name@, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) + NAKED unsigned int GetNewVariableIndexReverseInternal2_stub() + { + _asm + { + push ecx; + call GetNewVariableIndexReverseInternal2_call; + add esp, 0x4; + ret; + } + } + + void MakeVariableExternal_call(game::VariableValueInternal * parentValue, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int index) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::MakeVariableExternal(parentValue, inst, index, MakeVariableExternal_original); +#else + codsrc::MakeVariableExternal(parentValue, inst, index); +#endif + } + + // void __usercall MakeVariableExternal(game::VariableValueInternal *parentValue@, game::scriptInstance_t inst, unsigned int index) + NAKED void MakeVariableExternal_stub() + { + _asm + { + push eax; + call MakeVariableExternal_call; + add esp, 0x4; + ret; + } + } + + void FreeChildValue_call(unsigned int id, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::FreeChildValue(id, inst, parentId, FreeChildValue_original); +#else + codsrc::FreeChildValue(id, inst, parentId); +#endif + } + + // void __usercall FreeChildValue(unsigned int id@, game::scriptInstance_t inst, unsigned int parentId) + NAKED void FreeChildValue_stub() + { + _asm + { + push eax; + call FreeChildValue_call; + add esp, 0x4; + ret; + } + } + + void ClearObjectInternal_stub(game::scriptInstance_t inst, unsigned int parentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + ClearObjectInternal_hook.invoke(inst, parentId); +#else + codsrc::ClearObjectInternal(inst, parentId); +#endif + } + + void ClearObject_call(unsigned int a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::ClearObject(a1, a2, ClearObject_original); +#else + codsrc::ClearObject(a1, a2); +#endif + } + + // void __usercall ClearObject(unsigned int a1@, game::scriptInstance_t a2) + NAKED void ClearObject_stub() + { + _asm + { + push edi; + call ClearObject_call; + add esp, 0x4; + ret; + } + } + + void Scr_StopThread_call(game::scriptInstance_t inst, unsigned int a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_StopThread(inst, a2, Scr_StopThread_original); +#else + codsrc::Scr_StopThread(inst, a2); +#endif + } + + // void __usercall Scr_StopThread(game::scriptInstance_t inst@, unsigned int a2@) + NAKED void Scr_StopThread_stub() + { + _asm + { + push eax; + push ecx; + call Scr_StopThread_call; + add esp, 0x8; + ret; + } + } + + unsigned int GetSafeParentLocalId_call(game::scriptInstance_t a1, [[maybe_unused]] unsigned int localId, [[maybe_unused]] void* caller_addr, unsigned int a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetSafeParentLocalId(a1, a2, GetSafeParentLocalId_original); +#else + return codsrc::GetSafeParentLocalId(a1, a2); +#endif + } + + // unsigned int __usercall __spoils GetSafeParentLocalId@(game::scriptInstance_t inst@, unsigned int parentId) + NAKED unsigned int GetSafeParentLocalId_stub() + { + _asm + { + push edx; + + push eax; + call GetSafeParentLocalId_call; + add esp, 0x4; + + pop edx; + + ret; + } + } + + unsigned int GetStartLocalId_call(unsigned int result, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetStartLocalId(result, a2, GetStartLocalId_original); +#else + return codsrc::GetStartLocalId(result, a2); +#endif + } + + // unsigned int __usercall GetStartLocalId@(unsigned int result@, game::scriptInstance_t a2@) + NAKED unsigned int GetStartLocalId_stub() + { + _asm + { + push ecx; + push eax; + call GetStartLocalId_call; + add esp, 0x8; + ret; + } + } + + void Scr_KillThread_call(game::scriptInstance_t inst, unsigned int parentId_1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_KillThread(inst, parentId_1, Scr_KillThread_original); +#else + codsrc::Scr_KillThread(inst, parentId_1); +#endif + } + + // void __usercall Scr_KillThread(game::scriptInstance_t inst@, unsigned int parentId_1@) + NAKED void Scr_KillThread_stub() + { + _asm + { + push eax; + push ecx; + call Scr_KillThread_call; + add esp, 0x8; + ret; + } + } + + unsigned __int16 AllocVariable_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::AllocVariable(inst, AllocVariable_original); +#else + return codsrc::AllocVariable(inst); +#endif + } + + // unsigned __int16 __usercall AllocVariable@(game::scriptInstance_t inst@) + NAKED unsigned __int16 AllocVariable_stub() + { + _asm + { + push eax; + call AllocVariable_call; + add esp, 0x4; + ret; + } + } + + void FreeVariable_call(unsigned int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::FreeVariable(a1, a2, FreeVariable_original); +#else + codsrc::FreeVariable(a1, a2); +#endif + } + + // int __usercall FreeVariable@(int a1@, game::scriptInstance_t a2@) + NAKED int FreeVariable_stub() + { + _asm + { + push edx; + push eax; + call FreeVariable_call; + add esp, 0x8; + ret; + } + } + + unsigned int AllocValue_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::AllocValue(inst, AllocValue_original); +#else + return codsrc::AllocValue(inst); +#endif + } + + // unsigned int __usercall AllocValue@(game::scriptInstance_t inst@) + NAKED unsigned int AllocValue_stub() + { + _asm + { + push eax; + call AllocValue_call; + add esp, 0x4; + ret; + } + } + + unsigned int AllocEntity_call(int classnum, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int entnum, unsigned int clientnum) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::AllocEntity(classnum, inst, entnum, clientnum, AllocEntity_original); +#else + return codsrc::AllocEntity(classnum, inst, entnum, clientnum); +#endif + } + + // unsigned int __usercall AllocEntity@(int classnum@, game::scriptInstance_t inst@, int entnum, unsigned int clientnum) + NAKED unsigned int AllocEntity_stub() + { + _asm + { + push ecx; + push eax; + call AllocEntity_call; + add esp, 0x8; + ret; + } + } + + unsigned int Scr_AllocArray_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_AllocArray(a1, Scr_AllocArray_original); +#else + return codsrc::Scr_AllocArray(a1); +#endif + } + + // unsigned int __usercall Scr_AllocArray@(game::scriptInstance_t a1@) + NAKED unsigned int Scr_AllocArray_stub() + { + _asm + { + push eax; + call Scr_AllocArray_call; + add esp, 0x4; + ret; + } + } + + unsigned int AllocChildThread_call(game::scriptInstance_t inst, unsigned int a2, [[maybe_unused]] void* caller_addr, unsigned int a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::AllocChildThread(inst, a2, a3, AllocChildThread_original); +#else + return codsrc::AllocChildThread(inst, a2, a3); +#endif + } + + // unsigned int __usercall AllocChildThread@(game::scriptInstance_t inst@, unsigned int a2@, unsigned int a3) + NAKED unsigned int AllocChildThread_stub() + { + _asm + { + push eax; + push ecx; + call AllocChildThread_call; + add esp, 0x8; + ret; + } + } + + void FreeValue_call(unsigned int id, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::FreeValue(id, inst, FreeValue_original); +#else + codsrc::FreeValue(id, inst); +#endif + } + + // void __usercall FreeValue(unsigned int id@, game::scriptInstance_t inst) + NAKED void FreeValue_stub() + { + _asm + { + push eax; + call FreeValue_call; + add esp, 0x4; + ret; + } + } + + void RemoveRefToObject_call(unsigned int id, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::RemoveRefToObject(id, inst, RemoveRefToObject_original); +#else + codsrc::RemoveRefToObject(id, inst); +#endif + } + + // void __usercall RemoveRefToObject(unsigned int id@, game::scriptInstance_t inst@) + NAKED void RemoveRefToObject_stub() + { + _asm + { + push ecx; + push eax; + call RemoveRefToObject_call; + add esp, 0x8; + ret; + } + } + + float * Scr_AllocVector_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_AllocVector(a1, Scr_AllocVector_original); +#else + return codsrc::Scr_AllocVector(a1); +#endif + } + + // float *__usercall Scr_AllocVector@(game::scriptInstance_t a1@) + NAKED float * Scr_AllocVector_stub() + { + _asm + { + push eax; + call Scr_AllocVector_call; + add esp, 0x4; + ret; + } + } + + void RemoveRefToVector_call(const float* vecVal, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::RemoveRefToVector(vecVal, inst, RemoveRefToVector_original); +#else + codsrc::RemoveRefToVector(vecVal, inst); +#endif + } + + // void __usercall RemoveRefToVector(int vecVal@, game::scriptInstance_t inst) + NAKED void RemoveRefToVector_stub() + { + _asm + { + push eax; + call RemoveRefToVector_call; + add esp, 0x4; + ret; + } + } + + void AddRefToValue_call(game::scriptInstance_t inst, game::VariableType type_, [[maybe_unused]] void* caller_addr, game::VariableUnion u) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::AddRefToValue(inst, type_, u, AddRefToValue_original); +#else + codsrc::AddRefToValue(inst, type_, u); +#endif + } + + // void __usercall AddRefToValue(game::scriptInstance_t inst@, game::VariableType type@, game::VariableUnion u) + NAKED void AddRefToValue_stub() + { + _asm + { + push ecx; + push eax; + call AddRefToValue_call; + add esp, 0x8; + ret; + } + } + + void RemoveRefToValueInternal_stub(game::scriptInstance_t inst, game::VariableType type, game::VariableUnion a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + RemoveRefToValueInternal_hook.invoke(inst, type, a3); +#else + codsrc::RemoveRefToValueInternal(inst, type, a3); +#endif + } + + int FindArrayVariable_call(unsigned int id, unsigned int intvalue, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::FindArrayVariable(id, intvalue, inst, FindArrayVariable_original); +#else + return codsrc::FindArrayVariable(id, intvalue, inst); +#endif + } + + // int __usercall FindArrayVariable@(unsigned int id@, unsigned int intvalue@, game::scriptInstance_t inst) + NAKED int FindArrayVariable_stub() + { + _asm + { + push ecx; + push eax; + call FindArrayVariable_call; + add esp, 0x8; + ret; + } + } + + int FindVariable_call(int name, int a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::FindVariable(name, a2, inst, FindVariable_original); +#else + return codsrc::FindVariable(name, a2, inst); +#endif + } + + // int __usercall FindVariable@(int name@, int a2@, game::scriptInstance_t inst) + NAKED int FindVariable_stub() + { + _asm + { + push eax; + push ecx; + call FindVariable_call; + add esp, 0x8; + ret; + } + } + + unsigned int GetArrayVariableIndex_call(unsigned int unsignedValue, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetArrayVariableIndex(unsignedValue, inst, parentId, GetArrayVariableIndex_original); +#else + return codsrc::GetArrayVariableIndex(unsignedValue, inst, parentId); +#endif + } + + // unsigned int __usercall GetArrayVariableIndex@(unsigned int unsignedValue@, game::scriptInstance_t inst, unsigned int parentId) + NAKED unsigned int GetArrayVariableIndex_stub() + { + _asm + { + push eax; + call GetArrayVariableIndex_call; + add esp, 0x4; + ret; + } + } + + unsigned int Scr_GetVariableFieldIndex_call(game::scriptInstance_t a1, unsigned int name, [[maybe_unused]] void* caller_addr, unsigned int parentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_GetVariableFieldIndex(a1, name, parentId, Scr_GetVariableFieldIndex_original); +#else + return codsrc::Scr_GetVariableFieldIndex(a1, name, parentId); +#endif + } + + // unsigned int __usercall Scr_GetVariableFieldIndex@(game::scriptInstance_t a1@, unsigned int name@, unsigned int parentId) + NAKED unsigned int Scr_GetVariableFieldIndex_stub() + { + _asm + { + push esi; + push eax; + call Scr_GetVariableFieldIndex_call; + add esp, 0x8; + ret; + } + } + + game::VariableValue Scr_FindVariableField_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int parentId, unsigned int name) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_FindVariableField(inst, parentId, name, Scr_FindVariableField_original); +#else + return codsrc::Scr_FindVariableField(inst, parentId, name); +#endif + } + + // game::VariableValue __usercall Scr_FindVariableField@(game::scriptInstance_t inst@, unsigned int parentId, unsigned int name) + NAKED game::VariableValue Scr_FindVariableField_stub() + { + _asm + { + push edi; + call Scr_FindVariableField_call; + add esp, 4; + ret; + } + } + + void ClearVariableField_call(game::scriptInstance_t inst, unsigned int id, [[maybe_unused]] void* caller_addr, unsigned int name, game::VariableValue * value) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::ClearVariableField(inst, id, name, value, ClearVariableField_original); +#else + codsrc::ClearVariableField(inst, id, name, value); +#endif + } + + // void __usercall ClearVariableField(game::scriptInstance_t inst@, unsigned int id@, unsigned int name, game::VariableValue *value) + NAKED void ClearVariableField_stub() + { + _asm + { + push eax; + push ecx; + call ClearVariableField_call; + add esp, 0x8; + ret; + } + } + + unsigned int GetVariable_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int parentId, unsigned int name) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetVariable(a1, parentId, name, GetVariable_original); +#else + return codsrc::GetVariable(a1, parentId, name); +#endif + } + + // unsigned int __usercall GetVariable@(game::scriptInstance_t a1@, unsigned int parentId, unsigned int name) + NAKED unsigned int GetVariable_stub() + { + _asm + { + push eax; + call GetVariable_call; + add esp, 0x4; + ret; + } + } + + unsigned int GetNewVariable_call(game::scriptInstance_t a1, unsigned int a2, unsigned int a3, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetNewVariable(a1, a2, a3, GetNewVariable_original); +#else + return codsrc::GetNewVariable(a1, a2, a3); +#endif + } + + // unsigned int __usercall GetNewVariable@(game::scriptInstance_t a1@, unsigned int a2@, unsigned int a3@) + NAKED unsigned int GetNewVariable_stub() + { + _asm + { + push edi; + push ecx; + push eax; + call GetNewVariable_call; + add esp, 0xC; + ret; + } + } + + unsigned int GetObjectVariable_call(unsigned int a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetObjectVariable(a1, inst, parentId, GetObjectVariable_original); +#else + return codsrc::GetObjectVariable(a1, inst, parentId); +#endif + } + + // unsigned int __usercall GetObjectVariable@(unsigned int a1@, game::scriptInstance_t inst, unsigned int parentId) + NAKED unsigned int GetObjectVariable_stub() + { + _asm + { + push eax; + call GetObjectVariable_call; + add esp, 0x4; + ret; + } + } + + unsigned int GetNewObjectVariable_call(game::scriptInstance_t inst, unsigned int name, unsigned int parentId, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetNewObjectVariable(inst, name, parentId, GetNewObjectVariable_original); +#else + return codsrc::GetNewObjectVariable(inst, name, parentId); +#endif + } + + // unsigned int __usercall GetNewObjectVariable@(game::scriptInstance_t inst@, unsigned int name@, unsigned int parentId@) + NAKED unsigned int GetNewObjectVariable_stub() + { + _asm + { + push edi; + push ecx; + push eax; + call GetNewObjectVariable_call; + add esp, 0xC; + ret; + } + } + + void RemoveVariable_call(unsigned int name, unsigned int a2, game::scriptInstance_t a3, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::RemoveVariable(name, a2, a3, RemoveVariable_original); +#else + codsrc::RemoveVariable(name, a2, a3); +#endif + } + + // void __usercall RemoveVariable(unsigned int name@, unsigned int a2@, game::scriptInstance_t a3@) + NAKED void RemoveVariable_stub() + { + _asm + { + push esi; + push edi; + push ecx; + call RemoveVariable_call; + add esp, 0xC; + ret; + } + } + + void RemoveNextVariable_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int parentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::RemoveNextVariable(a1, parentId, RemoveNextVariable_original); +#else + codsrc::RemoveNextVariable(a1, parentId); +#endif + } + + // void __usercall RemoveNextVariable(game::scriptInstance_t a1@, unsigned int parentId) + NAKED void RemoveNextVariable_stub() + { + _asm + { + push edi; + call RemoveNextVariable_call; + add esp, 0x4; + ret; + } + } + + void SafeRemoveVariable_call(unsigned int unsignedValue, unsigned int parentId, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::SafeRemoveVariable(unsignedValue, parentId, inst, SafeRemoveVariable_original); +#else + codsrc::SafeRemoveVariable(unsignedValue, parentId, inst); +#endif + } + + // void __usercall SafeRemoveVariable(unsigned int unsignedValue@, unsigned int parentId@, game::scriptInstance_t inst@) + NAKED void SafeRemoveVariable_stub() + { + _asm + { + push esi; + push edi; + push ecx; + call SafeRemoveVariable_call; + add esp, 0xC; + ret; + } + } + + void CopyArray_stub(game::scriptInstance_t inst, unsigned int parentId, unsigned int newParentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + CopyArray_hook.invoke(inst, parentId, newParentId); +#else + codsrc::CopyArray(inst, parentId, newParentId); +#endif + } + + void SetVariableValue_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, unsigned int a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::SetVariableValue(a1, a2, a3, SetVariableValue_original); +#else + codsrc::SetVariableValue(a1, a2, a3); +#endif + } + + // void __usercall SetVariableValue(game::scriptInstance_t a1@, game::VariableValue *a2@, unsigned int a3) + NAKED void SetVariableValue_stub() + { + _asm + { + push edi; + push eax; + call SetVariableValue_call; + add esp, 0x8; + ret; + } + } + + void SetVariableEntityFieldValue_stub(game::scriptInstance_t inst, unsigned int parentId, unsigned int name, game::VariableValue * a4) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + SetVariableEntityFieldValue_hook.invoke(inst, parentId, name, a4); +#else + codsrc::SetVariableEntityFieldValue(inst, parentId, name, a4); +#endif + } + + game::VariableValue Scr_EvalVariable_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_EvalVariable(a1, a2, Scr_EvalVariable_original); +#else + return codsrc::Scr_EvalVariable(a1, a2); +#endif + } + + // game::VariableValue __usercall Scr_EvalVariable@(game::scriptInstance_t a1@, unsigned int a2) + NAKED game::VariableValue Scr_EvalVariable_stub() + { + _asm + { + push eax; + call Scr_EvalVariable_call; + add esp, 4; + ret; + } + } + + unsigned int Scr_EvalVariableObject_call(game::scriptInstance_t inst, int a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_EvalVariableObject(inst, a2, Scr_EvalVariableObject_original); +#else + return codsrc::Scr_EvalVariableObject(inst, a2); +#endif + } + + // unsigned int __usercall Scr_EvalVariableObject@(game::scriptInstance_t inst@, int a2@) + NAKED unsigned int Scr_EvalVariableObject_stub() + { + _asm + { + push eax; + push ecx; + call Scr_EvalVariableObject_call; + add esp, 0x8; + ret; + } + } + + game::VariableValue Scr_EvalVariableEntityField_call(unsigned int entId, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int name) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_EvalVariableEntityField(entId, inst, name, Scr_EvalVariableEntityField_original); +#else + return codsrc::Scr_EvalVariableEntityField(entId, inst, name); +#endif + } + + // game::VariableValue __usercall Scr_EvalVariableEntityField@(unsigned int entId@, game::scriptInstance_t inst, unsigned int name) + NAKED game::VariableValue Scr_EvalVariableEntityField_stub() + { + _asm + { + push ecx; + call Scr_EvalVariableEntityField_call; + add esp, 0x4; + ret; + } + } + + game::VariableValue Scr_EvalVariableField_call(game::scriptInstance_t inst, unsigned int id, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_EvalVariableField(inst, id, Scr_EvalVariableField_original); +#else + return codsrc::Scr_EvalVariableField(inst, id); +#endif + } + + // game::VariableValue __usercall Scr_EvalVariableField@(game::scriptInstance_t inst@, unsigned int id@) + NAKED game::VariableValue Scr_EvalVariableField_stub() + { + _asm + { + push edx; + push eax; + call Scr_EvalVariableField_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalSizeValue_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, game::VariableValue * value) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalSizeValue(a1, value, Scr_EvalSizeValue_original); +#else + codsrc::Scr_EvalSizeValue(a1, value); +#endif + } + + // void __usercall Scr_EvalSizeValue(game::scriptInstance_t a1@, game::VariableValue *value) + NAKED void Scr_EvalSizeValue_stub() + { + _asm + { + push eax; + call Scr_EvalSizeValue_call; + add esp, 0x4; + ret; + } + } + + unsigned int GetObject_call(game::scriptInstance_t a1, unsigned int a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetObject(a1, a2, GetObject_original); +#else + return codsrc::GetObject(a1, a2); +#endif + } + + // VariableValueInternal_u __usercall GetObject@(game::scriptInstance_t a1@, unsigned int a2@) + NAKED unsigned int GetObject_stub() + { + _asm + { + push ecx; + push eax; + call GetObject_call; + add esp, 0x8; + ret; + } + } + + unsigned int GetArray_call(game::scriptInstance_t inst, unsigned int a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::GetArray(inst, a2, GetArray_original); +#else + return codsrc::GetArray(inst, a2); +#endif + } + + // unsigned int __usercall GetArray@(game::scriptInstance_t inst@, unsigned int a2@) + NAKED unsigned int GetArray_stub() + { + _asm + { + push ecx; + push eax; + call GetArray_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalBoolComplement_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalBoolComplement(a1, a2, Scr_EvalBoolComplement_original); +#else + codsrc::Scr_EvalBoolComplement(a1, a2); +#endif + } + + // void __usercall Scr_EvalBoolComplement(game::scriptInstance_t a1@, game::VariableValue *a2@) + NAKED void Scr_EvalBoolComplement_stub() + { + _asm + { + push esi; + push eax; + call Scr_EvalBoolComplement_call; + add esp, 0x8; + ret; + } + } + + void Scr_CastBool_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_CastBool(a1, a2, Scr_CastBool_original); +#else + codsrc::Scr_CastBool(a1, a2); +#endif + } + + // void __usercall Scr_CastBool(game::scriptInstance_t a1@, game::VariableValue *a2@) + NAKED void Scr_CastBool_stub() + { + _asm + { + push esi; + push eax; + call Scr_CastBool_call; + add esp, 0x8; + ret; + } + } + + char Scr_CastString_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_CastString(a1, a2, Scr_CastString_original); +#else + return codsrc::Scr_CastString(a1, a2); +#endif + } + + // char __usercall Scr_CastString@(game::scriptInstance_t a1@, game::VariableValue *a2@) + NAKED char Scr_CastString_stub() + { + _asm + { + push esi; + push edi; + call Scr_CastString_call; + add esp, 0x8; + ret; + } + } + + void Scr_CastDebugString_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_CastDebugString(a1, a2, Scr_CastDebugString_original); +#else + codsrc::Scr_CastDebugString(a1, a2); +#endif + } + + // void __usercall Scr_CastDebugString(game::scriptInstance_t a1@, game::VariableValue *a2@) + NAKED void Scr_CastDebugString_stub() + { + _asm + { + push eax; + push ecx; + call Scr_CastDebugString_call; + add esp, 0x8; + ret; + } + } + + void Scr_ClearVector_stub(game::scriptInstance_t inst, game::VariableValue * a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + Scr_ClearVector_hook.invoke(inst, a2); +#else + codsrc::Scr_ClearVector(inst, a2); +#endif + } + + void Scr_CastVector_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_CastVector(a1, a2, Scr_CastVector_original); +#else + codsrc::Scr_CastVector(a1, a2); +#endif + } + + // void __usercall Scr_CastVector(game::scriptInstance_t a1@, game::VariableValue *a2@) + NAKED void Scr_CastVector_stub() + { + _asm + { + push esi; + push eax; + call Scr_CastVector_call; + add esp, 0x8; + ret; + } + } + + game::VariableUnion Scr_EvalFieldObject_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, int a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_EvalFieldObject(a1, inst, a3, Scr_EvalFieldObject_original); +#else + return codsrc::Scr_EvalFieldObject(a1, inst, a3); +#endif + } + + // game::VariableUnion __usercall Scr_EvalFieldObject@(game::VariableValue *a1@, game::scriptInstance_t inst, int a3) + NAKED game::VariableUnion Scr_EvalFieldObject_stub() + { + _asm + { + push eax; + call Scr_EvalFieldObject_call; + add esp, 0x4; + ret; + } + } + + void Scr_UnmatchingTypesError_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::VariableValue * value) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_UnmatchingTypesError(a1, a2, value, Scr_UnmatchingTypesError_original); +#else + codsrc::Scr_UnmatchingTypesError(a1, a2, value); +#endif + } + + // void __usercall Scr_UnmatchingTypesError(game::scriptInstance_t a1@, game::VariableValue *a2@, game::VariableValue *value) + NAKED void Scr_UnmatchingTypesError_stub() + { + _asm + { + push esi; + push eax; + call Scr_UnmatchingTypesError_call; + add esp, 0x8; + ret; + } + } + + void Scr_CastWeakerPair_call(game::VariableValue * a1, game::VariableValue * a2, game::scriptInstance_t a3, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_CastWeakerPair(a1, a2, a3, Scr_CastWeakerPair_original); +#else + codsrc::Scr_CastWeakerPair(a1, a2, a3); +#endif + } + + // void __usercall Scr_CastWeakerPair(game::VariableValue *a1@, game::VariableValue *a2@, game::scriptInstance_t a3@) + NAKED void Scr_CastWeakerPair_stub() + { + _asm + { + push eax; + push edi; + push ecx; + call Scr_CastWeakerPair_call; + add esp, 0xC; + ret; + } + } + + void Scr_CastWeakerStringPair_call(game::VariableValue * a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_CastWeakerStringPair(a1, a2, inst, Scr_CastWeakerStringPair_original); +#else + codsrc::Scr_CastWeakerStringPair(a1, a2, inst); +#endif + } + + // void __usercall Scr_CastWeakerStringPair(game::VariableValue *a1@, game::VariableValue *a2@, game::scriptInstance_t inst) + NAKED void Scr_CastWeakerStringPair_stub() + { + _asm + { + push ecx; + push eax; + call Scr_CastWeakerStringPair_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalOr_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalOr(result, a2, a3, Scr_EvalOr_original); +#else + codsrc::Scr_EvalOr(result, a2, a3); +#endif + } + + // void __usercall Scr_EvalOr(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) + NAKED void Scr_EvalOr_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalOr_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalExOr_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalExOr(result, a2, a3, Scr_EvalExOr_original); +#else + codsrc::Scr_EvalExOr(result, a2, a3); +#endif + } + + // void __usercall Scr_EvalExOr(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) + NAKED void Scr_EvalExOr_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalExOr_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalAnd_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalAnd(result, a2, a3, Scr_EvalAnd_original); +#else + codsrc::Scr_EvalAnd(result, a2, a3); +#endif + } + + // void __usercall Scr_EvalAnd(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) + NAKED void Scr_EvalAnd_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalAnd_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalEquality_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::VariableValue * a4) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalEquality(a1, inst, a4, Scr_EvalEquality_original); +#else + codsrc::Scr_EvalEquality(a1, inst, a4); +#endif + } + + // void __usercall Scr_EvalEquality(game::VariableValue *a1@, game::scriptInstance_t inst, game::VariableValue *a4) + NAKED void Scr_EvalEquality_stub() + { + _asm + { + push eax; + call Scr_EvalEquality_call; + add esp, 0x4; + ret; + } + } + + void Scr_EvalLess_call(game::VariableValue * a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalLess(a1, a2, a3, Scr_EvalLess_original); +#else + codsrc::Scr_EvalLess(a1, a2, a3); +#endif + } + + // void __usercall Scr_EvalLess(game::VariableValue *a1@, game::VariableValue *a2@, game::scriptInstance_t a3) + NAKED void Scr_EvalLess_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalLess_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalGreaterEqual_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::VariableValue * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalGreaterEqual(a1, a2, a3, Scr_EvalGreaterEqual_original); +#else + codsrc::Scr_EvalGreaterEqual(a1, a2, a3); +#endif + } + + // void __usercall Scr_EvalGreaterEqual(game::scriptInstance_t a1@, game::VariableValue *a2@, game::VariableValue *a3) + NAKED void Scr_EvalGreaterEqual_stub() + { + _asm + { + push esi; + push eax; + call Scr_EvalGreaterEqual_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalGreater_call(game::VariableValue * a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalGreater(a1, a2, a3, Scr_EvalGreater_original); +#else + codsrc::Scr_EvalGreater(a1, a2, a3); +#endif + } + + // void __usercall Scr_EvalGreater(game::VariableValue *a1@, game::VariableValue *a2@, game::scriptInstance_t a3) + NAKED void Scr_EvalGreater_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalGreater_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalLessEqual_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::VariableValue * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalLessEqual(a1, a2, a3, Scr_EvalLessEqual_original); +#else + codsrc::Scr_EvalLessEqual(a1, a2, a3); +#endif + } + + // void __usercall Scr_EvalLessEqual(game::scriptInstance_t a1@, game::VariableValue *a2@, game::VariableValue *a3) + NAKED void Scr_EvalLessEqual_stub() + { + _asm + { + push esi; + push eax; + call Scr_EvalLessEqual_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalShiftLeft_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalShiftLeft(result, a2, a3, Scr_EvalShiftLeft_original); +#else + codsrc::Scr_EvalShiftLeft(result, a2, a3); +#endif + } + + // void __usercall Scr_EvalShiftLeft(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) + NAKED void Scr_EvalShiftLeft_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalShiftLeft_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalShiftRight_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalShiftRight(result, a2, a3, Scr_EvalShiftRight_original); +#else + codsrc::Scr_EvalShiftRight(result, a2, a3); +#endif + } + + // void __usercall Scr_EvalShiftRight(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) + NAKED void Scr_EvalShiftRight_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalShiftRight_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalPlus_call(game::scriptInstance_t a, [[maybe_unused]] void* caller_addr, game::VariableValue * a1, game::VariableValue * a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalPlus(a, a1, a2, Scr_EvalPlus_original); +#else + codsrc::Scr_EvalPlus(a, a1, a2); +#endif + } + + // void __usercall Scr_EvalPlus(game::scriptInstance_t a@, game::VariableValue *a1, game::VariableValue *a2) + NAKED void Scr_EvalPlus_stub() + { + _asm + { + push ecx; + call Scr_EvalPlus_call; + add esp, 0x4; + ret; + } + } + + void Scr_EvalMinus_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2, game::VariableValue * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalMinus(a1, a2, a3, Scr_EvalMinus_original); +#else + codsrc::Scr_EvalMinus(a1, a2, a3); +#endif + } + + // void __usercall Scr_EvalMinus(game::VariableValue *a1@, game::scriptInstance_t a2, game::VariableValue *a3) + NAKED void Scr_EvalMinus_stub() + { + _asm + { + push eax; + call Scr_EvalMinus_call; + add esp, 0x4; + ret; + } + } + + void Scr_EvalMultiply_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2, game::VariableValue * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalMultiply(a1, a2, a3, Scr_EvalMultiply_original); +#else + codsrc::Scr_EvalMultiply(a1, a2, a3); +#endif + } + + // void __usercall Scr_EvalMultiply(game::VariableValue *a1@, game::scriptInstance_t a2, game::VariableValue *a3) + NAKED void Scr_EvalMultiply_stub() + { + _asm + { + push eax; + call Scr_EvalMultiply_call; + add esp, 0x4; + ret; + } + } + + void Scr_EvalDivide_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::VariableValue * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalDivide(a1, inst, a3, Scr_EvalDivide_original); +#else + codsrc::Scr_EvalDivide(a1, inst, a3); +#endif + } + + // void __usercall Scr_EvalDivide(game::VariableValue *a1@, game::scriptInstance_t inst, game::VariableValue *a3) + NAKED void Scr_EvalDivide_stub() + { + _asm + { + push eax; + call Scr_EvalDivide_call; + add esp, 0x4; + ret; + } + } + + void Scr_EvalMod_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::VariableValue * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalMod(a1, a2, a3, Scr_EvalMod_original); +#else + codsrc::Scr_EvalMod(a1, a2, a3); +#endif + } + + // void __usercall Scr_EvalMod(game::scriptInstance_t a1@, game::VariableValue *a2@, game::VariableValue *a3) + NAKED void Scr_EvalMod_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalMod_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalBinaryOperator_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::OpcodeVM a4, game::VariableValue * a5) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalBinaryOperator(a1, a2, a4, a5, Scr_EvalBinaryOperator_original); +#else + codsrc::Scr_EvalBinaryOperator(a1, a2, a4, a5); +#endif + } + + // void __usercall Scr_EvalBinaryOperator(game::scriptInstance_t a1@, game::VariableValue *a2@, OpcodeVM a4, game::VariableValue *a5) + NAKED void Scr_EvalBinaryOperator_stub() + { + _asm + { + push ecx; + push eax; + call Scr_EvalBinaryOperator_call; + add esp, 0x8; + ret; + } + } + + void Scr_FreeEntityNum_call(game::scriptInstance_t inst, unsigned int classnum, [[maybe_unused]] void* caller_addr, unsigned int entnum) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_FreeEntityNum(inst, classnum, entnum, Scr_FreeEntityNum_original); +#else + codsrc::Scr_FreeEntityNum(inst, classnum, entnum); +#endif + } + + // void __usercall Scr_FreeEntityNum(game::scriptInstance_t inst@, unsigned int result@, unsigned int a3) + NAKED void Scr_FreeEntityNum_stub() + { + _asm + { + push eax; + push ecx; + call Scr_FreeEntityNum_call; + add esp, 0x8; + ret; + } + } + + void Scr_FreeEntityList_stub(game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + Scr_FreeEntityList_hook.invoke(inst); +#else + codsrc::Scr_FreeEntityList(inst); +#endif + } + + void Scr_FreeObjects_stub(game::scriptInstance_t a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + Scr_FreeObjects_hook.invoke(a2); +#else + codsrc::Scr_FreeObjects(a2); +#endif + } + + void Scr_SetClassMap_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_SetClassMap(a1, a2, Scr_SetClassMap_original); +#else + codsrc::Scr_SetClassMap(a1, a2); +#endif + } + + // void __usercall Scr_SetClassMap(game::scriptInstance_t a1@, unsigned int a2) + NAKED void Scr_SetClassMap_stub() + { + _asm + { + push esi; + call Scr_SetClassMap_call; + add esp, 0x4; + ret; + } + } + + void Scr_RemoveClassMap_call(unsigned int result, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_RemoveClassMap(result, a2, Scr_RemoveClassMap_original); +#else + codsrc::Scr_RemoveClassMap(result, a2); +#endif + } + + // void __usercall Scr_RemoveClassMap(unsigned int result@, game::scriptInstance_t a2@) + NAKED void Scr_RemoveClassMap_stub() + { + _asm + { + push edi; + push eax; + call Scr_RemoveClassMap_call; + add esp, 0x8; + ret; + } + } + + void Scr_AddClassField_call(game::scriptInstance_t inst, unsigned int a2, [[maybe_unused]] void* caller_addr, const char * name, unsigned int a4) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_AddClassField(inst, a2, name, a4, Scr_AddClassField_original); +#else + codsrc::Scr_AddClassField(inst, a2, name, a4); +#endif + } + + // void __usercall Scr_AddClassField(game::scriptInstance_t inst@, unsigned int a2@, char *name, unsigned int a4) + NAKED void Scr_AddClassField_stub() + { + _asm + { + push eax; + push ecx; + call Scr_AddClassField_call; + add esp, 0x8; + ret; + } + } + + game::VariableUnion Scr_GetOffset_call(const char* name, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::classNum_e classNum) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_GetOffset(name, inst, classNum, Scr_GetOffset_original); +#else + return codsrc::Scr_GetOffset(name, inst, classNum); +#endif + } + + // int __usercall Scr_GetOffset@(char *name@, game::scriptInstance_t inst@, classNum_e classNum) + NAKED game::VariableUnion Scr_GetOffset_stub() + { + _asm + { + push edi; + push eax; + call Scr_GetOffset_call; + add esp, 0x8; + ret; + } + } + + unsigned int FindEntityId_call(unsigned int entClass, int entNum, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::FindEntityId(entClass, entNum, inst, FindEntityId_original); +#else + return codsrc::FindEntityId(entClass, entNum, inst); +#endif + } + + // unsigned int __usercall FindEntityId@(unsigned int entClass@, int entNum@, game::scriptInstance_t inst@) + NAKED unsigned int FindEntityId_stub() + { + _asm + { + push edi; + push ecx; + push eax; + call FindEntityId_call; + add esp, 0xC; + ret; + } + } + + unsigned int Scr_GetEntityId_call(int entNum, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::classNum_e classnum, int clientnum) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_GetEntityId(entNum, inst, classnum, clientnum, Scr_GetEntityId_original); +#else + return codsrc::Scr_GetEntityId(entNum, inst, classnum, clientnum); +#endif + } + + // unsigned int __usercall Scr_GetEntityId@(int entNum@, game::scriptInstance_t inst, classNum_e classnum, int clientnum) + NAKED unsigned int Scr_GetEntityId_stub() + { + _asm + { + push eax; + call Scr_GetEntityId_call; + add esp, 0x4; + ret; + } + } + + unsigned int Scr_FindArrayIndex_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, int a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_FindArrayIndex(a1, a2, a3, Scr_FindArrayIndex_original); +#else + return codsrc::Scr_FindArrayIndex(a1, a2, a3); +#endif + } + + // unsigned int __usercall Scr_FindArrayIndex@(game::scriptInstance_t a1@, game::VariableValue *a2@, int a3) + NAKED unsigned int Scr_FindArrayIndex_stub() + { + _asm + { + push ecx; + push eax; + call Scr_FindArrayIndex_call; + add esp, 0x8; + ret; + } + } + + void Scr_EvalArray_call(game::scriptInstance_t a2, game::VariableValue * eax0, [[maybe_unused]] void* caller_addr, game::VariableValue * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_EvalArray(a2, eax0, a3, Scr_EvalArray_original); +#else + codsrc::Scr_EvalArray(a2, eax0, a3); +#endif + } + + // void __usercall Scr_EvalArray(game::scriptInstance_t a2@, game::VariableValue *eax0@, game::VariableValue *a3) + NAKED void Scr_EvalArray_stub() + { + _asm + { + push eax; + push ecx; + call Scr_EvalArray_call; + add esp, 0x8; + ret; + } + } + + unsigned int Scr_EvalArrayRef_call(game::scriptInstance_t a2, unsigned int eax0, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_EvalArrayRef(a2, eax0, Scr_EvalArrayRef_original); +#else + return codsrc::Scr_EvalArrayRef(a2, eax0); +#endif + } + + // unsigned int __usercall Scr_EvalArrayRef@(game::scriptInstance_t a2@, unsigned int eax0@) + NAKED unsigned int Scr_EvalArrayRef_stub() + { + _asm + { + push eax; + push ecx; + call Scr_EvalArrayRef_call; + add esp, 0x8; + ret; + } + } + + void ClearArray_call(unsigned int parentId, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::VariableValue * value) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::ClearArray(parentId, inst, value, ClearArray_original); +#else + codsrc::ClearArray(parentId, inst, value); +#endif + } + + // void __usercall ClearArray(unsigned int parentId@, game::scriptInstance_t inst@, game::VariableValue *value) + NAKED void ClearArray_stub() + { + _asm + { + push ecx; + push eax; + call ClearArray_call; + add esp, 0x8; + ret; + } + } + + void SetEmptyArray_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::SetEmptyArray(a1, a2, SetEmptyArray_original); +#else + codsrc::SetEmptyArray(a1, a2); +#endif + } + + // unsigned int __usercall SetEmptyArray@(game::scriptInstance_t a1@, unsigned int a2) + NAKED unsigned int SetEmptyArray_stub() + { + _asm + { + push edi; + call SetEmptyArray_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddArrayKeys_stub(unsigned int array, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + Scr_AddArrayKeys_hook.invoke(array, inst); +#else + codsrc::Scr_AddArrayKeys(array, inst); +#endif + } + + game::scr_entref_t * Scr_GetEntityIdRef_call(game::scr_entref_t * result, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, unsigned int a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_GetEntityIdRef(result, a2, a3, Scr_GetEntityIdRef_original); +#else + return codsrc::Scr_GetEntityIdRef(result, a2, a3); +#endif + } + + // scr_entref_t *__usercall Scr_GetEntityIdRef@(scr_entref_t *result@, game::scriptInstance_t a2@, unsigned int a3) + NAKED game::scr_entref_t * Scr_GetEntityIdRef_stub() + { + _asm + { + push ecx; + push eax; + call Scr_GetEntityIdRef_call; + add esp, 0x8; + ret; + } + } + + void CopyEntity_call(unsigned int parentId, [[maybe_unused]] void* caller_addr, unsigned int newParentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::CopyEntity(parentId, newParentId, CopyEntity_original); +#else + codsrc::CopyEntity(parentId, newParentId); +#endif + } + + // void __usercall Scr_CopyEntityNum(unsigned int a1@, unsigned int parentId) + NAKED void CopyEntity_stub() + { + _asm + { + push eax; + call CopyEntity_call; + add esp, 0x4; + ret; + } + } + + float Scr_GetEndonUsage_call(unsigned int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_GetEndonUsage(a1, a2, Scr_GetEndonUsage_original); +#else + return codsrc::Scr_GetEndonUsage(a1, a2); +#endif + } + + // float __usercall Scr_GetEndonUsage@(unsigned int a1@, game::scriptInstance_t a2@) + NAKED float Scr_GetEndonUsage_stub() + { + _asm + { + push edi; + push ecx; + call Scr_GetEndonUsage_call; + add esp, 0x8; + ret; + } + } + + float Scr_GetObjectUsage_stub(game::scriptInstance_t a1, unsigned int parentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return Scr_GetObjectUsage_hook.invoke(a1, parentId); +#else + return codsrc::Scr_GetObjectUsage(a1, parentId); +#endif + } + + float Scr_GetThreadUsage_call(game::VariableStackBuffer * a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, float * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_GetThreadUsage(a1, a2, a3, Scr_GetThreadUsage_original); +#else + return codsrc::Scr_GetThreadUsage(a1, a2, a3); +#endif + } + + // float __usercall Scr_GetThreadUsage@(VariableStackBuffer *a1@, game::scriptInstance_t a2@, float *a3) + NAKED float Scr_GetThreadUsage_stub() + { + _asm + { + push ecx; + push eax; + call Scr_GetThreadUsage_call; + add esp, 0x8; + + sub esp, 4; + + fstp dword ptr[esp]; + movsd xmm0, dword ptr[esp]; + add esp, 4; + + ret; + } + } + + int Scr_FindField_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * name, int * type) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_FindField(inst, name, type, Scr_FindField_original); +#else + return codsrc::Scr_FindField(inst, name, type); +#endif + } + + // int __usercall Scr_FindField@(game::scriptInstance_t a1@, unsigned __int8 *a2, _DWORD *a3) + NAKED int Scr_FindField_stub() + { + _asm + { + push eax; + call Scr_FindField_call; + add esp, 0x4; + ret; + } + } + + char * Scr_GetSourceFile_LoadObj_stub(const char * a1) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return Scr_GetSourceFile_LoadObj_hook.invoke(a1); +#else + return codsrc::Scr_GetSourceFile_LoadObj(a1); +#endif + } + + char * Scr_GetSourceFile_FastFile_stub(char * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return Scr_GetSourceFile_FastFile_hook.invoke(a3); +#else + return codsrc::Scr_GetSourceFile_FastFile(a3); +#endif + } + + void Scr_AddFieldsForFile_stub(game::scriptInstance_t a1, char * Format) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + Scr_AddFieldsForFile_hook.invoke(a1, Format); +#else + codsrc::Scr_AddFieldsForFile(a1, Format); +#endif + } + + void Scr_AddFields_LoadObj_stub(game::scriptInstance_t a1, const char * edx0, CHAR * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + Scr_AddFields_LoadObj_hook.invoke(a1, edx0, a3); +#else + codsrc::Scr_AddFields_LoadObj(a1, edx0, a3); +#endif + } + + void Scr_AddFields_FastFile_stub(game::scriptInstance_t a1, const char * a2, const char * a3) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + Scr_AddFields_FastFile_hook.invoke(a1, a2, a3); +#else + codsrc::Scr_AddFields_FastFile(a1, a2, a3); +#endif + } + + int Scr_MakeValuePrimitive_stub(game::scriptInstance_t inst, unsigned int parentId) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return Scr_MakeValuePrimitive_hook.invoke(inst, parentId); +#else + return codsrc::Scr_MakeValuePrimitive(inst, parentId); +#endif + } + + void Scr_FreeGameVariable_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, int bComplete) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + game::Scr_FreeGameVariable(a1, bComplete, Scr_FreeGameVariable_original); +#else + codsrc::Scr_FreeGameVariable(a1, bComplete); +#endif + } + + // void __usercall Scr_FreeGameVariable(game::scriptInstance_t a1@, int bComplete) + NAKED void Scr_FreeGameVariable_stub() + { + _asm + { + push eax; + call Scr_FreeGameVariable_call; + add esp, 0x4; + ret; + } + } + + bool Scr_SLHasLowercaseString_call(unsigned int a1, const char * a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS + return game::Scr_SLHasLowercaseString(a1, a2, Scr_SLHasLowercaseString_original); +#else + return codsrc::Scr_SLHasLowercaseString(a1, a2); +#endif + } + + // char __usercall Scr_SLHasLowercaseString@(int a1@, const char *a2@) + NAKED bool Scr_SLHasLowercaseString_stub() + { + _asm + { + push edx; + push eax; + call Scr_SLHasLowercaseString_call; + add esp, 0x8; + ret; + } + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + ThreadInfoCompare_hook.create(game::ThreadInfoCompare.get(), ThreadInfoCompare_stub); + Scr_DumpScriptThreads_hook.create(game::Scr_DumpScriptThreads.get(), Scr_DumpScriptThreads_stub); + Scr_InitVariableRange_hook.create(game::Scr_InitVariableRange_ADDR(), Scr_InitVariableRange_stub); + Scr_InitClassMap_hook.create(game::Scr_InitClassMap_ADDR(), Scr_InitClassMap_stub); + GetNewVariableIndexInternal3_hook.create(game::GetNewVariableIndexInternal3.get(), GetNewVariableIndexInternal3_stub); + GetNewVariableIndexInternal2_hook.create(game::GetNewVariableIndexInternal2_ADDR(), GetNewVariableIndexInternal2_stub); + GetNewVariableIndexReverseInternal2_hook.create(game::GetNewVariableIndexReverseInternal2_ADDR(), GetNewVariableIndexReverseInternal2_stub); + MakeVariableExternal_hook.create(game::MakeVariableExternal_ADDR(), MakeVariableExternal_stub); + FreeChildValue_hook.create(game::FreeChildValue_ADDR(), FreeChildValue_stub); + ClearObjectInternal_hook.create(game::ClearObjectInternal.get(), ClearObjectInternal_stub); + ClearObject_hook.create(game::ClearObject_ADDR(), ClearObject_stub); + Scr_StopThread_hook.create(game::Scr_StopThread_ADDR(), Scr_StopThread_stub); + GetSafeParentLocalId_hook.create(game::GetSafeParentLocalId_ADDR(), GetSafeParentLocalId_stub); + GetStartLocalId_hook.create(game::GetStartLocalId_ADDR(), GetStartLocalId_stub); + Scr_KillThread_hook.create(game::Scr_KillThread_ADDR(), Scr_KillThread_stub); + AllocVariable_hook.create(game::AllocVariable_ADDR(), AllocVariable_stub); + FreeVariable_hook.create(game::FreeVariable_ADDR(), FreeVariable_stub); + AllocValue_hook.create(game::AllocValue_ADDR(), AllocValue_stub); + AllocEntity_hook.create(game::AllocEntity_ADDR(), AllocEntity_stub); + Scr_AllocArray_hook.create(game::Scr_AllocArray_ADDR(), Scr_AllocArray_stub); + + AllocChildThread_hook.create(game::AllocChildThread_ADDR(), AllocChildThread_stub); + FreeValue_hook.create(game::FreeValue_ADDR(), FreeValue_stub); + RemoveRefToObject_hook.create(game::RemoveRefToObject_ADDR(), RemoveRefToObject_stub); + Scr_AllocVector_hook.create(game::Scr_AllocVector_ADDR(), Scr_AllocVector_stub); + RemoveRefToVector_hook.create(game::RemoveRefToVector_ADDR(), RemoveRefToVector_stub); + + AddRefToValue_hook.create(game::AddRefToValue_ADDR(), AddRefToValue_stub); + RemoveRefToValueInternal_hook.create(game::RemoveRefToValueInternal.get(), RemoveRefToValueInternal_stub); + FindArrayVariable_hook.create(game::FindArrayVariable_ADDR(), FindArrayVariable_stub); + FindVariable_hook.create(game::FindVariable_ADDR(), FindVariable_stub); + + GetArrayVariableIndex_hook.create(game::GetArrayVariableIndex_ADDR(), GetArrayVariableIndex_stub); + Scr_GetVariableFieldIndex_hook.create(game::Scr_GetVariableFieldIndex_ADDR(), Scr_GetVariableFieldIndex_stub); + Scr_FindVariableField_hook.create(game::Scr_FindVariableField_ADDR(), Scr_FindVariableField_stub); + ClearVariableField_hook.create(game::ClearVariableField_ADDR(), ClearVariableField_stub); + GetVariable_hook.create(game::GetVariable_ADDR(), GetVariable_stub); + + GetNewVariable_hook.create(game::GetNewVariable_ADDR(), GetNewVariable_stub); + GetObjectVariable_hook.create(game::GetObjectVariable_ADDR(), GetObjectVariable_stub); + GetNewObjectVariable_hook.create(game::GetNewObjectVariable_ADDR(), GetNewObjectVariable_stub); + RemoveVariable_hook.create(game::RemoveVariable_ADDR(), RemoveVariable_stub); + RemoveNextVariable_hook.create(game::RemoveNextVariable_ADDR(), RemoveNextVariable_stub); + SafeRemoveVariable_hook.create(game::SafeRemoveVariable_ADDR(), SafeRemoveVariable_stub); + + CopyArray_hook.create(game::CopyArray.get(), CopyArray_stub); + SetVariableValue_hook.create(game::SetVariableValue_ADDR(), SetVariableValue_stub); + SetVariableEntityFieldValue_hook.create(game::SetVariableEntityFieldValue.get(), SetVariableEntityFieldValue_stub); + Scr_EvalVariable_hook.create(game::Scr_EvalVariable_ADDR(), Scr_EvalVariable_stub); + + Scr_EvalVariableObject_hook.create(game::Scr_EvalVariableObject_ADDR(), Scr_EvalVariableObject_stub); + Scr_EvalVariableEntityField_hook.create(game::Scr_EvalVariableEntityField_ADDR(), Scr_EvalVariableEntityField_stub); + Scr_EvalVariableField_hook.create(game::Scr_EvalVariableField_ADDR(), Scr_EvalVariableField_stub); + Scr_EvalSizeValue_hook.create(game::Scr_EvalSizeValue_ADDR(), Scr_EvalSizeValue_stub); + + GetObject_hook.create(game::GetObject_ADDR(), GetObject_stub); + GetArray_hook.create(game::GetArray_ADDR(), GetArray_stub); + Scr_EvalBoolComplement_hook.create(game::Scr_EvalBoolComplement_ADDR(), Scr_EvalBoolComplement_stub); + Scr_CastBool_hook.create(game::Scr_CastBool_ADDR(), Scr_CastBool_stub); + Scr_CastString_hook.create(game::Scr_CastString_ADDR(), Scr_CastString_stub); + Scr_CastDebugString_hook.create(game::Scr_CastDebugString_ADDR(), Scr_CastDebugString_stub); + Scr_ClearVector_hook.create(game::Scr_ClearVector.get(), Scr_ClearVector_stub); + Scr_CastVector_hook.create(game::Scr_CastVector_ADDR(), Scr_CastVector_stub); + + Scr_EvalFieldObject_hook.create(game::Scr_EvalFieldObject_ADDR(), Scr_EvalFieldObject_stub); + Scr_UnmatchingTypesError_hook.create(game::Scr_UnmatchingTypesError_ADDR(), Scr_UnmatchingTypesError_stub); + Scr_CastWeakerPair_hook.create(game::Scr_CastWeakerPair_ADDR(), Scr_CastWeakerPair_stub); + Scr_CastWeakerStringPair_hook.create(game::Scr_CastWeakerStringPair_ADDR(), Scr_CastWeakerStringPair_stub); + Scr_EvalOr_hook.create(game::Scr_EvalOr_ADDR(), Scr_EvalOr_stub); + Scr_EvalExOr_hook.create(game::Scr_EvalExOr_ADDR(), Scr_EvalExOr_stub); + Scr_EvalAnd_hook.create(game::Scr_EvalAnd_ADDR(), Scr_EvalAnd_stub); + Scr_EvalEquality_hook.create(game::Scr_EvalEquality_ADDR(), Scr_EvalEquality_stub); + Scr_EvalLess_hook.create(game::Scr_EvalLess_ADDR(), Scr_EvalLess_stub); + Scr_EvalGreaterEqual_hook.create(game::Scr_EvalGreaterEqual_ADDR(), Scr_EvalGreaterEqual_stub); + Scr_EvalGreater_hook.create(game::Scr_EvalGreater_ADDR(), Scr_EvalGreater_stub); + Scr_EvalLessEqual_hook.create(game::Scr_EvalLessEqual_ADDR(), Scr_EvalLessEqual_stub); + Scr_EvalShiftLeft_hook.create(game::Scr_EvalShiftLeft_ADDR(), Scr_EvalShiftLeft_stub); + Scr_EvalShiftRight_hook.create(game::Scr_EvalShiftRight_ADDR(), Scr_EvalShiftRight_stub); + Scr_EvalPlus_hook.create(game::Scr_EvalPlus_ADDR(), Scr_EvalPlus_stub); + Scr_EvalMinus_hook.create(game::Scr_EvalMinus_ADDR(), Scr_EvalMinus_stub); + Scr_EvalMultiply_hook.create(game::Scr_EvalMultiply_ADDR(), Scr_EvalMultiply_stub); + + Scr_EvalDivide_hook.create(game::Scr_EvalDivide_ADDR(), Scr_EvalDivide_stub); + Scr_EvalMod_hook.create(game::Scr_EvalMod_ADDR(), Scr_EvalMod_stub); + + Scr_EvalBinaryOperator_hook.create(game::Scr_EvalBinaryOperator_ADDR(), Scr_EvalBinaryOperator_stub); + + Scr_FreeEntityNum_hook.create(game::Scr_FreeEntityNum_ADDR(), Scr_FreeEntityNum_stub); + + Scr_FreeEntityList_hook.create(game::Scr_FreeEntityList.get(), Scr_FreeEntityList_stub); + Scr_FreeObjects_hook.create(game::Scr_FreeObjects.get(), Scr_FreeObjects_stub); + Scr_SetClassMap_hook.create(game::Scr_SetClassMap_ADDR(), Scr_SetClassMap_stub); + + Scr_RemoveClassMap_hook.create(game::Scr_RemoveClassMap_ADDR(), Scr_RemoveClassMap_stub); + Scr_AddClassField_hook.create(game::Scr_AddClassField_ADDR(), Scr_AddClassField_stub); + Scr_GetOffset_hook.create(game::Scr_GetOffset_ADDR(), Scr_GetOffset_stub); + FindEntityId_hook.create(game::FindEntityId_ADDR(), FindEntityId_stub); + Scr_GetEntityId_hook.create(game::Scr_GetEntityId_ADDR(), Scr_GetEntityId_stub); + Scr_FindArrayIndex_hook.create(game::Scr_FindArrayIndex_ADDR(), Scr_FindArrayIndex_stub); + Scr_EvalArray_hook.create(game::Scr_EvalArray_ADDR(), Scr_EvalArray_stub); + + Scr_EvalArrayRef_hook.create(game::Scr_EvalArrayRef_ADDR(), Scr_EvalArrayRef_stub); + ClearArray_hook.create(game::ClearArray_ADDR(), ClearArray_stub); + + SetEmptyArray_hook.create(game::SetEmptyArray_ADDR(), SetEmptyArray_stub); + Scr_AddArrayKeys_hook.create(game::Scr_AddArrayKeys.get(), Scr_AddArrayKeys_stub); + Scr_GetEntityIdRef_hook.create(game::Scr_GetEntityIdRef_ADDR(), Scr_GetEntityIdRef_stub); + CopyEntity_hook.create(game::CopyEntity_ADDR(), CopyEntity_stub); + + Scr_GetEndonUsage_hook.create(game::Scr_GetEndonUsage_ADDR(), Scr_GetEndonUsage_stub); + Scr_GetObjectUsage_hook.create(game::Scr_GetObjectUsage.get(), Scr_GetObjectUsage_stub); + Scr_GetThreadUsage_hook.create(game::Scr_GetThreadUsage_ADDR(), Scr_GetThreadUsage_stub); + + Scr_FindField_hook.create(game::Scr_FindField_ADDR(), Scr_FindField_stub); + Scr_GetSourceFile_LoadObj_hook.create(game::Scr_GetSourceFile_LoadObj.get(), Scr_GetSourceFile_LoadObj_stub); + Scr_GetSourceFile_FastFile_hook.create(game::Scr_GetSourceFile_FastFile.get(), Scr_GetSourceFile_FastFile_stub); + Scr_AddFieldsForFile_hook.create(game::Scr_AddFieldsForFile.get(), Scr_AddFieldsForFile_stub); + Scr_AddFields_LoadObj_hook.create(game::Scr_AddFields_LoadObj.get(), Scr_AddFields_LoadObj_stub); + Scr_AddFields_FastFile_hook.create(game::Scr_AddFields_FastFile.get(), Scr_AddFields_FastFile_stub); + Scr_MakeValuePrimitive_hook.create(game::Scr_MakeValuePrimitive.get(), Scr_MakeValuePrimitive_stub); + Scr_FreeGameVariable_hook.create(game::Scr_FreeGameVariable_ADDR(), Scr_FreeGameVariable_stub); + Scr_SLHasLowercaseString_hook.create(game::Scr_SLHasLowercaseString_ADDR(), Scr_SLHasLowercaseString_stub); + + //Original hook function addresses + ThreadInfoCompare_original = ThreadInfoCompare_hook.get_original(); + Scr_DumpScriptThreads_original = Scr_DumpScriptThreads_hook.get_original(); + Scr_InitVariableRange_original = Scr_InitVariableRange_hook.get_original(); + Scr_InitClassMap_original = Scr_InitClassMap_hook.get_original(); + GetNewVariableIndexInternal3_original = GetNewVariableIndexInternal3_hook.get_original(); + GetNewVariableIndexInternal2_original = GetNewVariableIndexInternal2_hook.get_original(); + GetNewVariableIndexReverseInternal2_original = GetNewVariableIndexReverseInternal2_hook.get_original(); + MakeVariableExternal_original = MakeVariableExternal_hook.get_original(); + FreeChildValue_original = FreeChildValue_hook.get_original(); + ClearObjectInternal_original = ClearObjectInternal_hook.get_original(); + ClearObject_original = ClearObject_hook.get_original(); + Scr_StopThread_original = Scr_StopThread_hook.get_original(); + GetSafeParentLocalId_original = GetSafeParentLocalId_hook.get_original(); + GetStartLocalId_original = GetStartLocalId_hook.get_original(); + Scr_KillThread_original = Scr_KillThread_hook.get_original(); + AllocVariable_original = AllocVariable_hook.get_original(); + FreeVariable_original = FreeVariable_hook.get_original(); + AllocValue_original = AllocValue_hook.get_original(); + AllocEntity_original = AllocEntity_hook.get_original(); + Scr_AllocArray_original = Scr_AllocArray_hook.get_original(); + AllocChildThread_original = AllocChildThread_hook.get_original(); + FreeValue_original = FreeValue_hook.get_original(); + RemoveRefToObject_original = RemoveRefToObject_hook.get_original(); + Scr_AllocVector_original = Scr_AllocVector_hook.get_original(); + RemoveRefToVector_original = RemoveRefToVector_hook.get_original(); + AddRefToValue_original = AddRefToValue_hook.get_original(); + RemoveRefToValueInternal_original = RemoveRefToValueInternal_hook.get_original(); + FindArrayVariable_original = FindArrayVariable_hook.get_original(); + FindVariable_original = FindVariable_hook.get_original(); + GetArrayVariableIndex_original = GetArrayVariableIndex_hook.get_original(); + Scr_GetVariableFieldIndex_original = Scr_GetVariableFieldIndex_hook.get_original(); + Scr_FindVariableField_original = Scr_FindVariableField_hook.get_original(); + ClearVariableField_original = ClearVariableField_hook.get_original(); + GetVariable_original = GetVariable_hook.get_original(); + GetNewVariable_original = GetNewVariable_hook.get_original(); + GetObjectVariable_original = GetObjectVariable_hook.get_original(); + GetNewObjectVariable_original = GetNewObjectVariable_hook.get_original(); + RemoveVariable_original = RemoveVariable_hook.get_original(); + RemoveNextVariable_original = RemoveNextVariable_hook.get_original(); + SafeRemoveVariable_original = SafeRemoveVariable_hook.get_original(); + CopyArray_original = CopyArray_hook.get_original(); + SetVariableValue_original = SetVariableValue_hook.get_original(); + SetVariableEntityFieldValue_original = SetVariableEntityFieldValue_hook.get_original(); + Scr_EvalVariable_original = Scr_EvalVariable_hook.get_original(); + Scr_EvalVariableObject_original = Scr_EvalVariableObject_hook.get_original(); + Scr_EvalVariableEntityField_original = Scr_EvalVariableEntityField_hook.get_original(); + Scr_EvalVariableField_original = Scr_EvalVariableField_hook.get_original(); + Scr_EvalSizeValue_original = Scr_EvalSizeValue_hook.get_original(); + GetObject_original = GetObject_hook.get_original(); + GetArray_original = GetArray_hook.get_original(); + Scr_EvalBoolComplement_original = Scr_EvalBoolComplement_hook.get_original(); + Scr_CastBool_original = Scr_CastBool_hook.get_original(); + Scr_CastString_original = Scr_CastString_hook.get_original(); + Scr_CastDebugString_original = Scr_CastDebugString_hook.get_original(); + Scr_ClearVector_original = Scr_ClearVector_hook.get_original(); + Scr_CastVector_original = Scr_CastVector_hook.get_original(); + Scr_EvalFieldObject_original = Scr_EvalFieldObject_hook.get_original(); + Scr_UnmatchingTypesError_original = Scr_UnmatchingTypesError_hook.get_original(); + Scr_CastWeakerPair_original = Scr_CastWeakerPair_hook.get_original(); + Scr_CastWeakerStringPair_original = Scr_CastWeakerStringPair_hook.get_original(); + Scr_EvalOr_original = Scr_EvalOr_hook.get_original(); + Scr_EvalExOr_original = Scr_EvalExOr_hook.get_original(); + Scr_EvalAnd_original = Scr_EvalAnd_hook.get_original(); + Scr_EvalEquality_original = Scr_EvalEquality_hook.get_original(); + Scr_EvalLess_original = Scr_EvalLess_hook.get_original(); + Scr_EvalGreaterEqual_original = Scr_EvalGreaterEqual_hook.get_original(); + Scr_EvalGreater_original = Scr_EvalGreater_hook.get_original(); + Scr_EvalLessEqual_original = Scr_EvalLessEqual_hook.get_original(); + Scr_EvalShiftLeft_original = Scr_EvalShiftLeft_hook.get_original(); + Scr_EvalShiftRight_original = Scr_EvalShiftRight_hook.get_original(); + Scr_EvalPlus_original = Scr_EvalPlus_hook.get_original(); + Scr_EvalMinus_original = Scr_EvalMinus_hook.get_original(); + Scr_EvalMultiply_original = Scr_EvalMultiply_hook.get_original(); + Scr_EvalDivide_original = Scr_EvalDivide_hook.get_original(); + Scr_EvalMod_original = Scr_EvalMod_hook.get_original(); + Scr_EvalBinaryOperator_original = Scr_EvalBinaryOperator_hook.get_original(); + Scr_FreeEntityNum_original = Scr_FreeEntityNum_hook.get_original(); + Scr_FreeEntityList_original = Scr_FreeEntityList_hook.get_original(); + Scr_FreeObjects_original = Scr_FreeObjects_hook.get_original(); + Scr_SetClassMap_original = Scr_SetClassMap_hook.get_original(); + Scr_RemoveClassMap_original = Scr_RemoveClassMap_hook.get_original(); + Scr_AddClassField_original = Scr_AddClassField_hook.get_original(); + Scr_GetOffset_original = Scr_GetOffset_hook.get_original(); + FindEntityId_original = FindEntityId_hook.get_original(); + Scr_GetEntityId_original = Scr_GetEntityId_hook.get_original(); + Scr_FindArrayIndex_original = Scr_FindArrayIndex_hook.get_original(); + Scr_EvalArray_original = Scr_EvalArray_hook.get_original(); + Scr_EvalArrayRef_original = Scr_EvalArrayRef_hook.get_original(); + ClearArray_original = ClearArray_hook.get_original(); + SetEmptyArray_original = SetEmptyArray_hook.get_original(); + Scr_AddArrayKeys_original = Scr_AddArrayKeys_hook.get_original(); + Scr_GetEntityIdRef_original = Scr_GetEntityIdRef_hook.get_original(); + CopyEntity_original = CopyEntity_hook.get_original(); + Scr_GetEndonUsage_original = Scr_GetEndonUsage_hook.get_original(); + Scr_GetObjectUsage_original = Scr_GetObjectUsage_hook.get_original(); + Scr_GetThreadUsage_original = Scr_GetThreadUsage_hook.get_original(); + Scr_FindField_original = Scr_FindField_hook.get_original(); + Scr_GetSourceFile_LoadObj_original = Scr_GetSourceFile_LoadObj_hook.get_original(); + Scr_GetSourceFile_FastFile_original = Scr_GetSourceFile_FastFile_hook.get_original(); + Scr_AddFieldsForFile_original = Scr_AddFieldsForFile_hook.get_original(); + Scr_AddFields_LoadObj_original = Scr_AddFields_LoadObj_hook.get_original(); + Scr_AddFields_FastFile_original = Scr_AddFields_FastFile_hook.get_original(); + Scr_MakeValuePrimitive_original = Scr_MakeValuePrimitive_hook.get_original(); + Scr_FreeGameVariable_original = Scr_FreeGameVariable_hook.get_original(); + Scr_SLHasLowercaseString_original = Scr_SLHasLowercaseString_hook.get_original(); + } + + private: + }; +} +REGISTER_COMPONENT(re_cscr_variable::component) \ No newline at end of file diff --git a/src/component/decomp/clientscript/re_cscr_vm.cpp b/src/component/decomp/clientscript/re_cscr_vm.cpp new file mode 100644 index 0000000..d6e78f9 --- /dev/null +++ b/src/component/decomp/clientscript/re_cscr_vm.cpp @@ -0,0 +1,1684 @@ +#include +#include "loader/component_loader.hpp" +#include "utils/hook.hpp" +//#include "codsrc/clientscript/cscr_vm.hpp" + +#define RE_CSCR_VM_USE_WRAPPERS + +namespace re_cscr_vm +{ + utils::hook::detour Scr_VM_Init_hook; + utils::hook::detour Scr_Init_hook; + utils::hook::detour Scr_Shutdown_hook; + utils::hook::detour Scr_ErrorInternal_hook; + utils::hook::detour Scr_ClearOutParams_hook; + utils::hook::detour GetDummyObject_hook; + utils::hook::detour GetDummyFieldValue_hook; + utils::hook::detour VM_ExecuteInternal_hook; + utils::hook::detour VM_CancelNotifyInternal_hook; + utils::hook::detour VM_CancelNotify_hook; + utils::hook::detour VM_ArchiveStack_hook; + utils::hook::detour Scr_AddLocalVars_hook; + utils::hook::detour VM_UnarchiveStack_hook; + utils::hook::detour VM_TerminateStack_hook; + utils::hook::detour VM_TrimStack_hook; + utils::hook::detour Scr_TerminateRunningThread_hook; + utils::hook::detour Scr_TerminateWaitThread_hook; + utils::hook::detour Scr_CancelWaittill_hook; + utils::hook::detour Scr_TerminateWaittillThread_hook; + utils::hook::detour Scr_TerminateThread_hook; + utils::hook::detour VM_Notify_hook; + utils::hook::detour Scr_NotifyNum_Internal_hook; + utils::hook::detour Scr_CancelNotifyList_hook; + utils::hook::detour VM_TerminateTime_hook; + utils::hook::detour VM_Resume_hook; + utils::hook::detour VM_Execute_hook; + utils::hook::detour Scr_ExecThread_hook; + utils::hook::detour Scr_ExecEntThread_hook; + utils::hook::detour Scr_AddExecThread_hook; + utils::hook::detour VM_SetTime_hook; + utils::hook::detour Scr_InitSystem_hook; + utils::hook::detour Scr_ShutdownSystem_hook; + utils::hook::detour Scr_IsSystemActive_hook; + utils::hook::detour Scr_GetInt_hook; + utils::hook::detour Scr_GetAnim_hook; + utils::hook::detour Scr_GetAnimTree_hook; + utils::hook::detour Scr_GetFloat_hook; + utils::hook::detour Scr_GetConstString_hook; + utils::hook::detour Scr_GetConstLowercaseString_hook; + utils::hook::detour Scr_GetString_hook; + utils::hook::detour Scr_GetConstStringIncludeNull_hook; + utils::hook::detour Scr_GetDebugString_hook; + utils::hook::detour Scr_GetConstIString_hook; + utils::hook::detour Scr_GetVector_hook; + utils::hook::detour Scr_GetFunc_hook; + utils::hook::detour Scr_GetEntityRef_hook; + utils::hook::detour Scr_GetObject_hook; + utils::hook::detour Scr_GetType_hook; + utils::hook::detour Scr_GetTypeName_hook; + utils::hook::detour Scr_GetPointerType_hook; + utils::hook::detour Scr_AddInt_hook; + utils::hook::detour Scr_AddFloat_hook; + utils::hook::detour Scr_AddAnim_hook; + utils::hook::detour Scr_AddUndefined_hook; + utils::hook::detour Scr_AddObject_hook; + utils::hook::detour Scr_AddString_hook; + utils::hook::detour Scr_AddIString_hook; + utils::hook::detour Scr_AddConstString_hook; + utils::hook::detour Scr_AddVector_hook; + utils::hook::detour Scr_MakeArray_hook; + utils::hook::detour Scr_AddArray_hook; + utils::hook::detour Scr_AddArrayStringIndexed_hook; + utils::hook::detour Scr_Error_hook; + utils::hook::detour Scr_TerminalError_hook; + utils::hook::detour Scr_ParamError_hook; + utils::hook::detour Scr_ObjectError_hook; + utils::hook::detour SetEntityFieldValue_hook; + utils::hook::detour GetEntityFieldValue_hook; + utils::hook::detour Scr_SetStructField_hook; + utils::hook::detour Scr_IncTime_hook; + utils::hook::detour Scr_RunCurrentThreads_hook; + utils::hook::detour Scr_ResetTimeout_hook; + + void* Scr_VM_Init_original; + void* Scr_Init_original; + void* Scr_Shutdown_original; + void* Scr_ErrorInternal_original; + void* Scr_ClearOutParams_original; + void* GetDummyObject_original; + void* GetDummyFieldValue_original; + void* VM_ExecuteInternal_original; + void* VM_CancelNotifyInternal_original; + void* VM_CancelNotify_original; + void* VM_ArchiveStack_original; + void* Scr_AddLocalVars_original; + void* VM_UnarchiveStack_original; + void* VM_TerminateStack_original; + void* VM_TrimStack_original; + void* Scr_TerminateRunningThread_original; + void* Scr_TerminateWaitThread_original; + void* Scr_CancelWaittill_original; + void* Scr_TerminateWaittillThread_original; + void* Scr_TerminateThread_original; + void* VM_Notify_original; + void* Scr_NotifyNum_Internal_original; + void* Scr_CancelNotifyList_original; + void* VM_TerminateTime_original; + void* VM_Resume_original; + void* VM_Execute_original; + void* Scr_ExecThread_original; + void* Scr_ExecEntThread_original; + void* Scr_AddExecThread_original; + void* VM_SetTime_original; + void* Scr_InitSystem_original; + void* Scr_ShutdownSystem_original; + void* Scr_IsSystemActive_original; + void* Scr_GetInt_original; + void* Scr_GetAnim_original; + void* Scr_GetAnimTree_original; + void* Scr_GetFloat_original; + void* Scr_GetConstString_original; + void* Scr_GetConstLowercaseString_original; + void* Scr_GetString_original; + void* Scr_GetConstStringIncludeNull_original; + void* Scr_GetDebugString_original; + void* Scr_GetConstIString_original; + void* Scr_GetVector_original; + void* Scr_GetFunc_original; + void* Scr_GetEntityRef_original; + void* Scr_GetObject_original; + void* Scr_GetType_original; + void* Scr_GetTypeName_original; + void* Scr_GetPointerType_original; + void* Scr_AddInt_original; + void* Scr_AddFloat_original; + void* Scr_AddAnim_original; + void* Scr_AddUndefined_original; + void* Scr_AddObject_original; + void* Scr_AddString_original; + void* Scr_AddIString_original; + void* Scr_AddConstString_original; + void* Scr_AddVector_original; + void* Scr_MakeArray_original; + void* Scr_AddArray_original; + void* Scr_AddArrayStringIndexed_original; + void* Scr_Error_original; + void* Scr_TerminalError_original; + void* Scr_ParamError_original; + void* Scr_ObjectError_original; + void* SetEntityFieldValue_original; + void* GetEntityFieldValue_original; + void* Scr_SetStructField_original; + void* Scr_IncTime_original; + void* Scr_RunCurrentThreads_original; + void* Scr_ResetTimeout_original; + + namespace + { + + void Scr_VM_Init_stub(game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + Scr_VM_Init_hook.invoke(inst); +#else + codsrc::Scr_VM_Init(inst); +#endif + } + + void Scr_Init_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_Init(a1, Scr_Init_original); +#else + codsrc::Scr_Init(a1); +#endif + } + + NAKED void Scr_Init_stub() + { + _asm + { + push eax; + call Scr_Init_call; + add esp, 0x4; + ret; + } + } + + void Scr_Shutdown_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_Shutdown(a1, Scr_Shutdown_original); +#else + codsrc::Scr_Shutdown(a1); +#endif + } + + NAKED void Scr_Shutdown_stub() + { + _asm + { + push edi; + call Scr_Shutdown_call; + add esp, 0x4; + ret; + } + } + + void Scr_ErrorInternal_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_ErrorInternal(a1, Scr_ErrorInternal_original); +#else + codsrc::Scr_ErrorInternal(a1); +#endif + } + + NAKED void Scr_ErrorInternal_stub() + { + _asm + { + push eax; + call Scr_ErrorInternal_call; + add esp, 0x4; + ret; + } + } + + void Scr_ClearOutParams_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_ClearOutParams(a1, Scr_ClearOutParams_original); +#else + codsrc::Scr_ClearOutParams(a1); +#endif + } + + NAKED void Scr_ClearOutParams_stub() + { + _asm + { + push edi; + call Scr_ClearOutParams_call; + add esp, 0x4; + ret; + } + } + + unsigned int GetDummyObject_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::GetDummyObject(a1, GetDummyObject_original); +#else + return codsrc::GetDummyObject(a1); +#endif + } + + NAKED unsigned int GetDummyObject_stub/*@*/() + { + _asm + { + push edi; + call GetDummyObject_call; + add esp, 0x4; + ret; + } + } + + unsigned int GetDummyFieldValue_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::GetDummyFieldValue(a1, GetDummyFieldValue_original); +#else + return codsrc::GetDummyFieldValue(a1); +#endif + } + + NAKED unsigned int GetDummyFieldValue_stub/*@*/() + { + _asm + { + push eax; + call GetDummyFieldValue_call; + add esp, 0x4; + ret; + } + } + + unsigned int VM_ExecuteInternal_stub(game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return VM_ExecuteInternal_hook.invoke(inst); +#else + return codsrc::VM_ExecuteInternal(inst); +#endif + } + + void VM_CancelNotifyInternal_call(game::scriptInstance_t inst, unsigned int notifyListOwnerId, [[maybe_unused]] void* caller_addr, unsigned int startLocalId, unsigned int notifyListId, unsigned int notifyNameListId, unsigned int stringValue) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::VM_CancelNotifyInternal(inst, notifyListOwnerId, startLocalId, notifyListId, notifyNameListId, stringValue, VM_CancelNotifyInternal_original); +#else + codsrc::VM_CancelNotifyInternal(inst, notifyListOwnerId, startLocalId, notifyListId, notifyNameListId, stringValue); +#endif + } + + NAKED void VM_CancelNotifyInternal_stub() + { + _asm + { + push eax; + push ecx; + call VM_CancelNotifyInternal_call; + add esp, 0x8; + ret; + } + } + + void VM_CancelNotify_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2, unsigned int a3) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::VM_CancelNotify(a1, a2, a3, VM_CancelNotify_original); +#else + codsrc::VM_CancelNotify(a1, a2, a3); +#endif + } + + NAKED void VM_CancelNotify_stub() + { + _asm + { + push edi; + call VM_CancelNotify_call; + add esp, 0x4; + ret; + } + } + + game::VariableStackBuffer* VM_ArchiveStack_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::VM_ArchiveStack(inst, VM_ArchiveStack_original); +#else + return codsrc::VM_ArchiveStack(inst); +#endif + } + + NAKED game::VariableStackBuffer * VM_ArchiveStack_stub/*@*/() + { + _asm + { + push eax; + call VM_ArchiveStack_call; + add esp, 0x4; + ret; + } + } + + int Scr_AddLocalVars_call(game::scriptInstance_t a1, unsigned int a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_AddLocalVars(a1, a2, Scr_AddLocalVars_original); +#else + return codsrc::Scr_AddLocalVars(a1, a2); +#endif + } + + NAKED int Scr_AddLocalVars_stub/*@*/() + { + _asm + { + push edx; + push eax; + call Scr_AddLocalVars_call; + add esp, 0x8; + ret; + } + } + + void VM_UnarchiveStack_stub(game::scriptInstance_t inst, unsigned int startLocalId, game::VariableStackBuffer* stackValue) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + VM_UnarchiveStack_hook.invoke(inst, startLocalId, stackValue); +#else + codsrc::VM_UnarchiveStack(inst, startLocalId, stackValue); +#endif + } + + void VM_TerminateStack_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2, unsigned int a3, game::VariableStackBuffer* name) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::VM_TerminateStack(a1, a2, a3, name, VM_TerminateStack_original); +#else + codsrc::VM_TerminateStack(a1, a2, a3, name); +#endif + } + + NAKED void VM_TerminateStack_stub() + { + _asm + { + push esi; + call VM_TerminateStack_call; + add esp, 0x4; + ret; + } + } + + void VM_TrimStack_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int parentId, game::VariableStackBuffer* a3, int fromEndon) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::VM_TrimStack(a1, parentId, a3, fromEndon, VM_TrimStack_original); +#else + codsrc::VM_TrimStack(a1, parentId, a3, fromEndon); +#endif + } + + NAKED void VM_TrimStack_stub() + { + _asm + { + push eax; + call VM_TrimStack_call; + add esp, 0x4; + ret; + } + } + + void Scr_TerminateRunningThread_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_TerminateRunningThread(a1, a2, Scr_TerminateRunningThread_original); +#else + codsrc::Scr_TerminateRunningThread(a1, a2); +#endif + } + + NAKED void Scr_TerminateRunningThread_stub() + { + _asm + { + push edx; + call Scr_TerminateRunningThread_call; + add esp, 0x4; + ret; + } + } + + void Scr_TerminateWaitThread_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2, unsigned int a3) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_TerminateWaitThread(a1, a2, a3, Scr_TerminateWaitThread_original); +#else + codsrc::Scr_TerminateWaitThread(a1, a2, a3); +#endif + } + + NAKED void Scr_TerminateWaitThread_stub() + { + _asm + { + push eax; + call Scr_TerminateWaitThread_call; + add esp, 0x4; + ret; + } + } + + void Scr_CancelWaittill_call(game::scriptInstance_t inst, unsigned int startLocalId, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_CancelWaittill(inst, startLocalId, Scr_CancelWaittill_original); +#else + codsrc::Scr_CancelWaittill(inst, startLocalId); +#endif + } + + NAKED void Scr_CancelWaittill_stub() + { + _asm + { + push eax; + push ecx; + call Scr_CancelWaittill_call; + add esp, 0x8; + ret; + } + } + + void Scr_TerminateWaittillThread_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2, unsigned int a3) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_TerminateWaittillThread(a1, a2, a3, Scr_TerminateWaittillThread_original); +#else + codsrc::Scr_TerminateWaittillThread(a1, a2, a3); +#endif + } + + NAKED void Scr_TerminateWaittillThread_stub() + { + _asm + { + push eax; + call Scr_TerminateWaittillThread_call; + add esp, 0x4; + ret; + } + } + + void Scr_TerminateThread_call(unsigned int a2, game::scriptInstance_t a3, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_TerminateThread(a2, a3, Scr_TerminateThread_original); +#else + codsrc::Scr_TerminateThread(a2, a3); +#endif + } + + NAKED void Scr_TerminateThread_stub() + { + _asm + { + push esi; + push edi; + call Scr_TerminateThread_call; + add esp, 0x8; + ret; + } + } + + void VM_Notify_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int notifyListOwnerId, unsigned int stringValue, game::VariableValue* top) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::VM_Notify(inst, notifyListOwnerId, stringValue, top, VM_Notify_original); +#else + codsrc::VM_Notify(inst, notifyListOwnerId, stringValue, top); +#endif + } + + NAKED void VM_Notify_stub() + { + _asm + { + push eax; + call VM_Notify_call; + add esp, 0x4; + ret; + } + } + + void Scr_NotifyNum_Internal_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int entNum, int entClass, unsigned int notifStr, int numParams) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_NotifyNum_Internal(inst, entNum, entClass, notifStr, numParams, Scr_NotifyNum_Internal_original); +#else + codsrc::Scr_NotifyNum_Internal(inst, entNum, entClass, notifStr, numParams); +#endif + } + + NAKED void Scr_NotifyNum_Internal_stub() + { + _asm + { + push eax; + call Scr_NotifyNum_Internal_call; + add esp, 0x4; + ret; + } + } + + void Scr_CancelNotifyList_call(unsigned int notifyListOwnerId, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_CancelNotifyList(notifyListOwnerId, inst, Scr_CancelNotifyList_original); +#else + codsrc::Scr_CancelNotifyList(notifyListOwnerId, inst); +#endif + } + + NAKED void Scr_CancelNotifyList_stub() + { + _asm + { + push eax; + call Scr_CancelNotifyList_call; + add esp, 0x4; + ret; + } + } + + void VM_TerminateTime_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int parentId) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::VM_TerminateTime(a1, parentId, VM_TerminateTime_original); +#else + codsrc::VM_TerminateTime(a1, parentId); +#endif + } + + NAKED void VM_TerminateTime_stub() + { + _asm + { + push eax; + call VM_TerminateTime_call; + add esp, 0x4; + ret; + } + } + + void VM_Resume_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int timeId) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::VM_Resume(inst, timeId, VM_Resume_original); +#else + codsrc::VM_Resume(inst, timeId); +#endif + } + + NAKED void VM_Resume_stub() + { + _asm + { + push eax; + call VM_Resume_call; + add esp, 0x4; + ret; + } + } + + unsigned int VM_Execute_stub(game::scriptInstance_t inst, unsigned int localId, const char* pos, unsigned int paramcount) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return VM_Execute_hook.invoke(inst, localId, pos, paramcount); +#else + return codsrc::VM_Execute(inst, localId, pos, paramcount); +#endif + } + + unsigned __int16 Scr_ExecThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int handle, unsigned int paramCount) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_ExecThread(inst, handle, paramCount, Scr_ExecThread_original); +#else + return codsrc::Scr_ExecThread(inst, handle, paramCount); +#endif + } + + NAKED unsigned __int16 Scr_ExecThread_stub/*@*/() + { + _asm + { + push edi; + call Scr_ExecThread_call; + add esp, 0x4; + ret; + } + } + unsigned __int16 Scr_ExecEntThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int entNum, unsigned int handle, int numParams, unsigned int entClass) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_ExecEntThreadNum(inst, entNum, handle, numParams, entClass, Scr_ExecEntThread_original); +#else + return codsrc::Scr_ExecEntThreadNum(inst, entNum, handle, numParams, entClass); +#endif + } + + NAKED unsigned __int16 Scr_ExecEntThread_stub/*@*/() + { + _asm + { + push edi; + call Scr_ExecEntThread_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddExecThread_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int handle) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddExecThread(a1, handle, Scr_AddExecThread_original); +#else + codsrc::Scr_AddExecThread(a1, handle); +#endif + } + + NAKED void Scr_AddExecThread_stub() + { + _asm + { + push edi; + call Scr_AddExecThread_call; + add esp, 0x4; + ret; + } + } + + void VM_SetTime_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::VM_SetTime(a1, VM_SetTime_original); +#else + codsrc::VM_SetTime(a1); +#endif + } + + NAKED void VM_SetTime_stub() + { + _asm + { + push eax; + call VM_SetTime_call; + add esp, 0x4; + ret; + } + } + + void Scr_InitSystem_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_InitSystem(a1, Scr_InitSystem_original); +#else + codsrc::Scr_InitSystem(a1); +#endif + } + + NAKED void Scr_InitSystem_stub() + { + _asm + { + push edi; + call Scr_InitSystem_call; + add esp, 0x4; + ret; + } + } + + void Scr_ShutdownSystem_stub(game::scriptInstance_t inst, int bComplete) + { +#if USE_SCHEDULER_FUNCTION_OVERRIDES == 1 + scheduler::Scr_ShutdownSystem_Override(inst, bComplete); + return; +#endif + +#ifdef RE_CSCR_VM_USE_WRAPPERS + Scr_ShutdownSystem_hook.invoke(inst, bComplete); +#else + codsrc::Scr_ShutdownSystem(inst, bComplete); +#endif + } + + BOOL Scr_IsSystemActive_stub() + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return Scr_IsSystemActive_hook.invoke(); +#else + return codsrc::Scr_IsSystemActive(); +#endif + } + + int Scr_GetInt_call(game::scriptInstance_t inst, unsigned int index, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetInt(inst, index, Scr_GetInt_original); +#else + return codsrc::Scr_GetInt(inst, index); +#endif + } + + NAKED int Scr_GetInt_stub/*@*/() + { + _asm + { + push ecx; + push eax; + call Scr_GetInt_call; + add esp, 0x8; + ret; + } + } + + game::scr_anim_s Scr_GetAnim_call(unsigned int index, game::XAnimTree_s* a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetAnim(index, a2, Scr_GetAnim_original); +#else + return codsrc::Scr_GetAnim(index, a2); +#endif + } + + NAKED game::scr_anim_s Scr_GetAnim_stub/*@*/() + { + _asm + { + push ecx; + push eax; + call Scr_GetAnim_call; + add esp, 0x8; + ret; + } + } + + game::scr_animtree_t Scr_GetAnimTree_stub() + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return Scr_GetAnimTree_hook.invoke(); +#else + return codsrc::Scr_GetAnimTree(); +#endif + } + + float Scr_GetFloat_call(game::scriptInstance_t inst, unsigned int index, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetFloat(inst, index, Scr_GetFloat_original); +#else + return codsrc::Scr_GetFloat(inst, index); +#endif + } + + NAKED float Scr_GetFloat_stub/*@*/() + { + _asm + { + push ecx; + push eax; + call Scr_GetFloat_call; + add esp, 0x8; + + sub esp, 4; + + fstp dword ptr[esp]; + movsd xmm0, dword ptr[esp]; + add esp, 4; + + ret; + } + } + + unsigned int Scr_GetConstString_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int index) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetConstString(inst, index, Scr_GetConstString_original); +#else + return codsrc::Scr_GetConstString(inst, index); +#endif + } + + NAKED unsigned int Scr_GetConstString_stub/*@*/() + { + _asm + { + push eax; + call Scr_GetConstString_call; + add esp, 0x4; + ret; + } + } + + unsigned int Scr_GetConstLowercaseString_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int index) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetConstLowercaseString(inst, index, Scr_GetConstLowercaseString_original); +#else + return codsrc::Scr_GetConstLowercaseString(inst, index); +#endif + } + + NAKED const char * Scr_GetConstLowercaseString_stub/*@*/() + { + _asm + { + push ecx; + call Scr_GetConstLowercaseString_call; + add esp, 0x4; + ret; + } + } + + const char* Scr_GetString_call(unsigned int index, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetString(index, inst, Scr_GetString_original); +#else + return codsrc::Scr_GetString(index, inst); +#endif + } + + NAKED const char * Scr_GetString_stub/*@*/() + { + _asm + { + push esi; + push eax; + call Scr_GetString_call; + add esp, 0x8; + ret; + } + } + + unsigned int Scr_GetConstStringIncludeNull_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetConstStringIncludeNull(a1, Scr_GetConstStringIncludeNull_original); +#else + return codsrc::Scr_GetConstStringIncludeNull(a1); +#endif + } + + NAKED unsigned int Scr_GetConstStringIncludeNull_stub/*@*/() + { + _asm + { + push eax; + call Scr_GetConstStringIncludeNull_call; + add esp, 0x4; + ret; + } + } + + char* Scr_GetDebugString_call(game::scriptInstance_t a1, unsigned int a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetDebugString(a1, a2, Scr_GetDebugString_original); +#else + return codsrc::Scr_GetDebugString(a1, a2); +#endif + } + + NAKED char * Scr_GetDebugString_stub/*@*/() + { + _asm + { + push ecx; + push eax; + call Scr_GetDebugString_call; + add esp, 0x8; + ret; + } + } + + unsigned int Scr_GetConstIString_call(unsigned int index, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetConstIString(index, Scr_GetConstIString_original); +#else + return codsrc::Scr_GetConstIString(index); +#endif + } + + NAKED unsigned int Scr_GetConstIString_stub/*@*/() + { + _asm + { + push eax; + call Scr_GetConstIString_call; + add esp, 0x4; + ret; + } + } + + void Scr_GetVector_call(game::scriptInstance_t inst, float* value, [[maybe_unused]] void* caller_addr, unsigned int index) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_GetVector(inst, value, index, Scr_GetVector_original); +#else + codsrc::Scr_GetVector(inst, value, index); +#endif + } + + NAKED void Scr_GetVector_stub() + { + _asm + { + push ecx; + push eax; + call Scr_GetVector_call; + add esp, 0x8; + ret; + } + } + + unsigned int Scr_GetFunc_stub() + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return Scr_GetFunc_hook.invoke(); +#else + return codsrc::Scr_GetFunc(); +#endif + } + + game::scr_entref_t* Scr_GetEntityRef_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::scr_entref_t* retstr, unsigned int index) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetEntityRef(inst, retstr, index, Scr_GetEntityRef_original); +#else + return codsrc::Scr_GetEntityRef(inst, retstr, index); +#endif + } + + NAKED game::scr_entref_t * Scr_GetEntityRef_stub/*@*/() + { + _asm + { + push eax; + call Scr_GetEntityRef_call; + add esp, 0x4; + ret; + } + } + + game::VariableUnion Scr_GetObject_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetObject(a1, Scr_GetObject_original); +#else + return codsrc::Scr_GetObject(a1); +#endif + } + + NAKED game::VariableUnion Scr_GetObject_stub/*@*/() + { + _asm + { + push eax; + call Scr_GetObject_call; + add esp, 0x4; + ret; + } + } + + game::VariableType Scr_GetType_call(game::scriptInstance_t inst, unsigned int index, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetType(inst, index, Scr_GetType_original); +#else + return codsrc::Scr_GetType(inst, index); +#endif + } + + NAKED game::VariableType Scr_GetType_stub/*@*/() + { + _asm + { + push ecx; + push eax; + call Scr_GetType_call; + add esp, 0x8; + ret; + } + } + + char* Scr_GetTypeName_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetTypeName(a1, Scr_GetTypeName_original); +#else + return codsrc::Scr_GetTypeName(a1); +#endif + } + + NAKED char * Scr_GetTypeName_stub/*@*/() + { + _asm + { + push eax; + call Scr_GetTypeName_call; + add esp, 0x4; + ret; + } + } + + game::VariableType Scr_GetPointerType_call(game::scriptInstance_t a1, unsigned int a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::Scr_GetPointerType(a1, a2, Scr_GetPointerType_original); +#else + return codsrc::Scr_GetPointerType(a1, a2); +#endif + } + + NAKED game::VariableType Scr_GetPointerType_stub/*@*/() + { + _asm + { + push ecx; + push eax; + call Scr_GetPointerType_call; + add esp, 0x8; + ret; + } + } + + void Scr_AddInt_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int value) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddInt(inst, value, Scr_AddInt_original); +#else + codsrc::Scr_AddInt(inst, value); +#endif + } + + NAKED void Scr_AddInt_stub() + { + _asm + { + push eax; + call Scr_AddInt_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddFloat_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, float value) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddFloat(inst, value, Scr_AddFloat_original); +#else + codsrc::Scr_AddFloat(inst, value); +#endif + } + + NAKED void Scr_AddFloat_stub() + { + _asm + { + push eax; + call Scr_AddFloat_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddAnim_stub(game::scr_anim_s a1) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + Scr_AddAnim_hook.invoke(a1); +#else + codsrc::Scr_AddAnim(a1); +#endif + } + + void Scr_AddUndefined_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddUndefined(inst, Scr_AddUndefined_original); +#else + codsrc::Scr_AddUndefined(inst); +#endif + } + + NAKED void Scr_AddUndefined_stub() + { + _asm + { + push eax; + call Scr_AddUndefined_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddObject_call(game::scriptInstance_t inst, unsigned int entid, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddObject(inst, entid, Scr_AddObject_original); +#else + codsrc::Scr_AddObject(inst, entid); +#endif + } + + NAKED void Scr_AddObject_stub() + { + _asm + { + push esi; + push eax; + call Scr_AddObject_call; + add esp, 0x8; + ret; + } + } + + void Scr_AddString_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, char* string) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddString(inst, string, Scr_AddString_original); +#else + codsrc::Scr_AddString(inst, string); +#endif + } + + NAKED void Scr_AddString_stub() + { + _asm + { + push eax; + call Scr_AddString_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddIString_call(char* string, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddIString(string, Scr_AddIString_original); +#else + codsrc::Scr_AddIString(string); +#endif + } + + NAKED void Scr_AddIString_stub() + { + _asm + { + push esi; + call Scr_AddIString_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddConstString_call(game::scriptInstance_t inst, unsigned int id, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddConstString(inst, id, Scr_AddConstString_original); +#else + codsrc::Scr_AddConstString(inst, id); +#endif + } + + NAKED void Scr_AddConstString_stub() + { + _asm + { + push esi; + push eax; + call Scr_AddConstString_call; + add esp, 0x8; + ret; + } + } + + void Scr_AddVector_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, float* value) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddVector(inst, value, Scr_AddVector_original); +#else + codsrc::Scr_AddVector(inst, value); +#endif + } + + NAKED void Scr_AddVector_stub() + { + _asm + { + push eax; + call Scr_AddVector_call; + add esp, 0x4; + ret; + } + } + + void Scr_MakeArray_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_MakeArray(a1, Scr_MakeArray_original); +#else + codsrc::Scr_MakeArray(a1); +#endif + } + + NAKED void Scr_MakeArray_stub() + { + _asm + { + push eax; + call Scr_MakeArray_call; + add esp, 0x4; + ret; + } + } + + void Scr_AddArray_stub(game::scriptInstance_t inst) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + Scr_AddArray_hook.invoke(inst); +#else + codsrc::Scr_AddArray(inst); +#endif + } + + void Scr_AddArrayStringIndexed_call(unsigned int id, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_AddArrayStringIndexed(id, inst, Scr_AddArrayStringIndexed_original); +#else + codsrc::Scr_AddArrayStringIndexed(id, inst); +#endif + } + + NAKED void Scr_AddArrayStringIndexed_stub() + { + _asm + { + push edi; + push ecx; + call Scr_AddArrayStringIndexed_call; + add esp, 0x8; + ret; + } + } + + void Scr_Error_call(const char* err, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int is_terminal) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_Error(err, inst, is_terminal, Scr_Error_original); +#else + codsrc::Scr_Error(err, inst, is_terminal); +#endif + } + + NAKED void Scr_Error_stub() + { + _asm + { + push edi; + push ecx; + call Scr_Error_call; + add esp, 0x8; + ret; + } + } + + void Scr_TerminalError_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, char* Source) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_TerminalError(a1, Source, Scr_TerminalError_original); +#else + codsrc::Scr_TerminalError(a1, Source); +#endif + } + + NAKED void Scr_TerminalError_stub() + { + _asm + { + push eax; + call Scr_TerminalError_call; + add esp, 0x4; + ret; + } + } + + void Scr_ParamError_call(int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, char* Source) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_ParamError(a1, a2, Source, Scr_ParamError_original); +#else + codsrc::Scr_ParamError(a1, a2, Source); +#endif + } + + NAKED void Scr_ParamError_stub() + { + _asm + { + push ecx; + push eax; + call Scr_ParamError_call; + add esp, 0x8; + ret; + } + } + + void Scr_ObjectError_call(game::scriptInstance_t a1, const char* a2, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_ObjectError(a1, a2, Scr_ObjectError_original); +#else + codsrc::Scr_ObjectError(a1, a2); +#endif + } + + NAKED void Scr_ObjectError_stub() + { + _asm + { + push ecx; + push eax; + call Scr_ObjectError_call; + add esp, 0x8; + ret; + } + } + + bool SetEntityFieldValue_call(game::scriptInstance_t inst, int offset_, int entnum, [[maybe_unused]] void* caller_addr, game::classNum_e classnum, int clientNum, game::VariableValue* value) + { +#if CSCR_VARIABLE_EXTRA_CLASSMAPS + return script::SetEntityFieldValue_Override(inst, offset_, entnum, classnum, clientNum, value); +#endif + +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::SetEntityFieldValue(inst, offset_, entnum, classnum, clientNum, value, SetEntityFieldValue_original); +#else + return codsrc::SetEntityFieldValue(inst, offset_, entnum, classnum, clientNum, value); +#endif + } + + NAKED bool SetEntityFieldValue_stub/*@*/() + { + _asm + { + push ecx; + push eax; + push edi; + call SetEntityFieldValue_call; + add esp, 0xC; + ret; + } + } + + game::VariableValue GetEntityFieldValue_call(int offset_, int entnum, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::classNum_e classnum, int clientNum) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + return game::GetEntityFieldValue(offset_, entnum, inst, classnum, clientNum, GetEntityFieldValue_original); +#else + return codsrc::GetEntityFieldValue(offset_, entnum, inst, classnum, clientNum); +#endif + } + + NAKED game::VariableValue GetEntityFieldValue_stub() + { + _asm + { + push ecx; + push eax; + call GetEntityFieldValue_call; + add esp, 0x8; + ret; + } + } + + void Scr_SetStructField_call(unsigned int a1, unsigned int a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_SetStructField(a1, a2, a3, Scr_SetStructField_original); +#else + codsrc::Scr_SetStructField(a1, a2, a3); +#endif + } + + NAKED void Scr_SetStructField_stub() + { + _asm + { + push ecx; + push eax; + call Scr_SetStructField_call; + add esp, 0x8; + ret; + } + } + + void Scr_IncTime_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_IncTime(a1, Scr_IncTime_original); +#else + codsrc::Scr_IncTime(a1); +#endif + } + + NAKED void Scr_IncTime_stub() + { + _asm + { + push eax; + call Scr_IncTime_call; + add esp, 0x4; + ret; + } + } + + void Scr_RunCurrentThreads_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_RunCurrentThreads(a1, Scr_RunCurrentThreads_original); +#else + codsrc::Scr_RunCurrentThreads(a1); +#endif + } + + NAKED void Scr_RunCurrentThreads_stub() + { + _asm + { + push esi; + call Scr_RunCurrentThreads_call; + add esp, 0x4; + ret; + } + } + + void Scr_ResetTimeout_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) + { +#ifdef RE_CSCR_VM_USE_WRAPPERS + game::Scr_ResetTimeout(a1, Scr_ResetTimeout_original); +#else + codsrc::Scr_ResetTimeout(a1); +#endif + } + + NAKED void Scr_ResetTimeout_stub() + { + _asm + { + push eax; + call Scr_ResetTimeout_call; + add esp, 0x4; + ret; + } + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + Scr_VM_Init_hook.create(game::Scr_VM_Init.get(), Scr_VM_Init_stub); + Scr_Init_hook.create(game::Scr_Init_ADDR(), Scr_Init_stub); + Scr_Shutdown_hook.create(game::Scr_Shutdown_ADDR(), Scr_Shutdown_stub); + Scr_ErrorInternal_hook.create(game::Scr_ErrorInternal_ADDR(), Scr_ErrorInternal_stub); + Scr_ClearOutParams_hook.create(game::Scr_ClearOutParams_ADDR(), Scr_ClearOutParams_stub); + GetDummyObject_hook.create(game::GetDummyObject_ADDR(), GetDummyObject_stub); + GetDummyFieldValue_hook.create(game::GetDummyFieldValue_ADDR(), GetDummyFieldValue_stub); + VM_ExecuteInternal_hook.create(game::VM_ExecuteInternal.get(), VM_ExecuteInternal_stub); + VM_CancelNotifyInternal_hook.create(game::VM_CancelNotifyInternal_ADDR(), VM_CancelNotifyInternal_stub); + VM_CancelNotify_hook.create(game::VM_CancelNotify_ADDR(), VM_CancelNotify_stub); + VM_ArchiveStack_hook.create(game::VM_ArchiveStack_ADDR(), VM_ArchiveStack_stub); + Scr_AddLocalVars_hook.create(game::Scr_AddLocalVars_ADDR(), Scr_AddLocalVars_stub); + VM_UnarchiveStack_hook.create(game::VM_UnarchiveStack.get(), VM_UnarchiveStack_stub); + VM_TerminateStack_hook.create(game::VM_TerminateStack_ADDR(), VM_TerminateStack_stub); + VM_TrimStack_hook.create(game::VM_TrimStack_ADDR(), VM_TrimStack_stub); + Scr_TerminateRunningThread_hook.create(game::Scr_TerminateRunningThread_ADDR(), Scr_TerminateRunningThread_stub); + Scr_TerminateWaitThread_hook.create(game::Scr_TerminateWaitThread_ADDR(), Scr_TerminateWaitThread_stub); + Scr_CancelWaittill_hook.create(game::Scr_CancelWaittill_ADDR(), Scr_CancelWaittill_stub); + Scr_TerminateWaittillThread_hook.create(game::Scr_TerminateWaittillThread_ADDR(), Scr_TerminateWaittillThread_stub); + Scr_TerminateThread_hook.create(game::Scr_TerminateThread_ADDR(), Scr_TerminateThread_stub); + VM_Notify_hook.create(game::VM_Notify_ADDR(), VM_Notify_stub); + Scr_NotifyNum_Internal_hook.create(game::Scr_NotifyNum_Internal_ADDR(), Scr_NotifyNum_Internal_stub); + Scr_CancelNotifyList_hook.create(game::Scr_CancelNotifyList_ADDR(), Scr_CancelNotifyList_stub); + + VM_TerminateTime_hook.create(game::VM_TerminateTime_ADDR(), VM_TerminateTime_stub); + VM_Resume_hook.create(game::VM_Resume_ADDR(), VM_Resume_stub); + VM_Execute_hook.create(game::VM_Execute.get(), VM_Execute_stub); + Scr_ExecThread_hook.create(game::Scr_ExecThread_ADDR(), Scr_ExecThread_stub); + Scr_ExecEntThread_hook.create(game::Scr_ExecEntThread_ADDR(), Scr_ExecEntThread_stub); + Scr_AddExecThread_hook.create(game::Scr_AddExecThread_ADDR(), Scr_AddExecThread_stub); + VM_SetTime_hook.create(game::VM_SetTime_ADDR(), VM_SetTime_stub); + Scr_InitSystem_hook.create(game::Scr_InitSystem_ADDR(), Scr_InitSystem_stub); + Scr_ShutdownSystem_hook.create(game::Scr_ShutdownSystem.get(), Scr_ShutdownSystem_stub); + Scr_IsSystemActive_hook.create(game::Scr_IsSystemActive.get(), Scr_IsSystemActive_stub); + Scr_GetInt_hook.create(game::Scr_GetInt_ADDR(), Scr_GetInt_stub); + Scr_GetAnim_hook.create(game::Scr_GetAnim_ADDR(), Scr_GetAnim_stub); + Scr_GetAnimTree_hook.create(game::Scr_GetAnimTree.get(), Scr_GetAnimTree_stub); + Scr_GetFloat_hook.create(game::Scr_GetFloat_ADDR(), Scr_GetFloat_stub); + Scr_GetConstString_hook.create(game::Scr_GetConstString_ADDR(), Scr_GetConstString_stub); + Scr_GetConstLowercaseString_hook.create(game::Scr_GetConstLowercaseString_ADDR(), Scr_GetConstLowercaseString_stub); + Scr_GetString_hook.create(game::Scr_GetString_ADDR(), Scr_GetString_stub); + Scr_GetConstStringIncludeNull_hook.create(game::Scr_GetConstStringIncludeNull_ADDR(), Scr_GetConstStringIncludeNull_stub); + Scr_GetDebugString_hook.create(game::Scr_GetDebugString_ADDR(), Scr_GetDebugString_stub); + Scr_GetConstIString_hook.create(game::Scr_GetConstIString_ADDR(), Scr_GetConstIString_stub); + Scr_GetVector_hook.create(game::Scr_GetVector_ADDR(), Scr_GetVector_stub); + Scr_GetFunc_hook.create(game::Scr_GetFunc.get(), Scr_GetFunc_stub); + Scr_GetEntityRef_hook.create(game::Scr_GetEntityRef_ADDR(), Scr_GetEntityRef_stub); + Scr_GetObject_hook.create(game::Scr_GetObject_ADDR(), Scr_GetObject_stub); + Scr_GetType_hook.create(game::Scr_GetType_ADDR(), Scr_GetType_stub); + Scr_GetTypeName_hook.create(game::Scr_GetTypeName_ADDR(), Scr_GetTypeName_stub); + Scr_GetPointerType_hook.create(game::Scr_GetPointerType_ADDR(), Scr_GetPointerType_stub); + Scr_AddInt_hook.create(game::Scr_AddInt_ADDR(), Scr_AddInt_stub); + Scr_AddFloat_hook.create(game::Scr_AddFloat_ADDR(), Scr_AddFloat_stub); + Scr_AddAnim_hook.create(game::Scr_AddAnim.get(), Scr_AddAnim_stub); + Scr_AddUndefined_hook.create(game::Scr_AddUndefined_ADDR(), Scr_AddUndefined_stub); + Scr_AddObject_hook.create(game::Scr_AddObject_ADDR(), Scr_AddObject_stub); + Scr_AddString_hook.create(game::Scr_AddString_ADDR(), Scr_AddString_stub); + Scr_AddIString_hook.create(game::Scr_AddIString_ADDR(), Scr_AddIString_stub); + Scr_AddConstString_hook.create(game::Scr_AddConstString_ADDR(), Scr_AddConstString_stub); + Scr_AddVector_hook.create(game::Scr_AddVector_ADDR(), Scr_AddVector_stub); + Scr_MakeArray_hook.create(game::Scr_MakeArray_ADDR(), Scr_MakeArray_stub); + Scr_AddArray_hook.create(game::Scr_AddArray.get(), Scr_AddArray_stub); + Scr_AddArrayStringIndexed_hook.create(game::Scr_AddArrayStringIndexed_ADDR(), Scr_AddArrayStringIndexed_stub); + Scr_Error_hook.create(game::Scr_Error_ADDR(), Scr_Error_stub); + Scr_TerminalError_hook.create(game::Scr_TerminalError_ADDR(), Scr_TerminalError_stub); + Scr_ParamError_hook.create(game::Scr_ParamError_ADDR(), Scr_ParamError_stub); + Scr_ObjectError_hook.create(game::Scr_ObjectError_ADDR(), Scr_ObjectError_stub); + SetEntityFieldValue_hook.create(game::SetEntityFieldValue_ADDR(), SetEntityFieldValue_stub); + GetEntityFieldValue_hook.create(game::GetEntityFieldValue_ADDR(), GetEntityFieldValue_stub); + Scr_SetStructField_hook.create(game::Scr_SetStructField_ADDR(), Scr_SetStructField_stub); + Scr_IncTime_hook.create(game::Scr_IncTime_ADDR(), Scr_IncTime_stub); + Scr_RunCurrentThreads_hook.create(game::Scr_RunCurrentThreads_ADDR(), Scr_RunCurrentThreads_stub); + Scr_ResetTimeout_hook.create(game::Scr_ResetTimeout_ADDR(), Scr_ResetTimeout_stub); + + //Original hook function addresses + Scr_VM_Init_original = Scr_VM_Init_hook.get_original(); + Scr_Init_original = Scr_Init_hook.get_original(); + Scr_Shutdown_original = Scr_Shutdown_hook.get_original(); + Scr_ErrorInternal_original = Scr_ErrorInternal_hook.get_original(); + Scr_ClearOutParams_original = Scr_ClearOutParams_hook.get_original(); + GetDummyObject_original = GetDummyObject_hook.get_original(); + GetDummyFieldValue_original = GetDummyFieldValue_hook.get_original(); + VM_ExecuteInternal_original = VM_ExecuteInternal_hook.get_original(); + VM_CancelNotifyInternal_original = VM_CancelNotifyInternal_hook.get_original(); + VM_CancelNotify_original = VM_CancelNotify_hook.get_original(); + VM_ArchiveStack_original = VM_ArchiveStack_hook.get_original(); + Scr_AddLocalVars_original = Scr_AddLocalVars_hook.get_original(); + VM_UnarchiveStack_original = VM_UnarchiveStack_hook.get_original(); + VM_TerminateStack_original = VM_TerminateStack_hook.get_original(); + VM_TrimStack_original = VM_TrimStack_hook.get_original(); + Scr_TerminateRunningThread_original = Scr_TerminateRunningThread_hook.get_original(); + Scr_TerminateWaitThread_original = Scr_TerminateWaitThread_hook.get_original(); + Scr_CancelWaittill_original = Scr_CancelWaittill_hook.get_original(); + Scr_TerminateWaittillThread_original = Scr_TerminateWaittillThread_hook.get_original(); + Scr_TerminateThread_original = Scr_TerminateThread_hook.get_original(); + VM_Notify_original = VM_Notify_hook.get_original(); + Scr_NotifyNum_Internal_original = Scr_NotifyNum_Internal_hook.get_original(); + Scr_CancelNotifyList_original = Scr_CancelNotifyList_hook.get_original(); + VM_TerminateTime_original = VM_TerminateTime_hook.get_original(); + VM_Resume_original = VM_Resume_hook.get_original(); + VM_Execute_original = VM_Execute_hook.get_original(); + Scr_ExecThread_original = Scr_ExecThread_hook.get_original(); + Scr_ExecEntThread_original = Scr_ExecEntThread_hook.get_original(); + Scr_AddExecThread_original = Scr_AddExecThread_hook.get_original(); + VM_SetTime_original = VM_SetTime_hook.get_original(); + Scr_InitSystem_original = Scr_InitSystem_hook.get_original(); + Scr_ShutdownSystem_original = Scr_ShutdownSystem_hook.get_original(); + Scr_IsSystemActive_original = Scr_IsSystemActive_hook.get_original(); + Scr_GetInt_original = Scr_GetInt_hook.get_original(); + Scr_GetAnim_original = Scr_GetAnim_hook.get_original(); + Scr_GetAnimTree_original = Scr_GetAnimTree_hook.get_original(); + Scr_GetFloat_original = Scr_GetFloat_hook.get_original(); + Scr_GetConstString_original = Scr_GetConstString_hook.get_original(); + Scr_GetConstLowercaseString_original = Scr_GetConstLowercaseString_hook.get_original(); + Scr_GetString_original = Scr_GetString_hook.get_original(); + Scr_GetConstStringIncludeNull_original = Scr_GetConstStringIncludeNull_hook.get_original(); + Scr_GetDebugString_original = Scr_GetDebugString_hook.get_original(); + Scr_GetConstIString_original = Scr_GetConstIString_hook.get_original(); + Scr_GetVector_original = Scr_GetVector_hook.get_original(); + Scr_GetFunc_original = Scr_GetFunc_hook.get_original(); + Scr_GetEntityRef_original = Scr_GetEntityRef_hook.get_original(); + Scr_GetObject_original = Scr_GetObject_hook.get_original(); + Scr_GetType_original = Scr_GetType_hook.get_original(); + Scr_GetTypeName_original = Scr_GetTypeName_hook.get_original(); + Scr_GetPointerType_original = Scr_GetPointerType_hook.get_original(); + Scr_AddInt_original = Scr_AddInt_hook.get_original(); + Scr_AddFloat_original = Scr_AddFloat_hook.get_original(); + Scr_AddAnim_original = Scr_AddAnim_hook.get_original(); + Scr_AddUndefined_original = Scr_AddUndefined_hook.get_original(); + Scr_AddObject_original = Scr_AddObject_hook.get_original(); + Scr_AddString_original = Scr_AddString_hook.get_original(); + Scr_AddIString_original = Scr_AddIString_hook.get_original(); + Scr_AddConstString_original = Scr_AddConstString_hook.get_original(); + Scr_AddVector_original = Scr_AddVector_hook.get_original(); + Scr_MakeArray_original = Scr_MakeArray_hook.get_original(); + Scr_AddArray_original = Scr_AddArray_hook.get_original(); + Scr_AddArrayStringIndexed_original = Scr_AddArrayStringIndexed_hook.get_original(); + Scr_Error_original = Scr_Error_hook.get_original(); + Scr_TerminalError_original = Scr_TerminalError_hook.get_original(); + Scr_ParamError_original = Scr_ParamError_hook.get_original(); + Scr_ObjectError_original = Scr_ObjectError_hook.get_original(); + SetEntityFieldValue_original = SetEntityFieldValue_hook.get_original(); + GetEntityFieldValue_original = GetEntityFieldValue_hook.get_original(); + Scr_SetStructField_original = Scr_SetStructField_hook.get_original(); + Scr_IncTime_original = Scr_IncTime_hook.get_original(); + Scr_RunCurrentThreads_original = Scr_RunCurrentThreads_hook.get_original(); + Scr_ResetTimeout_original = Scr_ResetTimeout_hook.get_original(); + } + + private: + }; +} +REGISTER_COMPONENT(re_cscr_vm::component) \ No newline at end of file diff --git a/src/game/clientscript/cscr_vm.hpp b/src/game/clientscript/cscr_vm.hpp index cec0938..197d14c 100644 --- a/src/game/clientscript/cscr_vm.hpp +++ b/src/game/clientscript/cscr_vm.hpp @@ -137,10 +137,9 @@ namespace game void Scr_RunCurrentThreads(scriptInstance_t inst, void* call_addr = Scr_RunCurrentThreads_ADDR()); inline void* Scr_ResetTimeout_ADDR() { return CALL_ADDR(0x0, 0x69AE60); } void Scr_ResetTimeout(scriptInstance_t inst, void* call_addr = Scr_ResetTimeout_ADDR()); - void SetVariableFieldValue(scriptInstance_t inst, unsigned int id, VariableValue* value); + void SetVariableFieldValue(scriptInstance_t inst, unsigned int id, VariableValue* value); void SetNewVariableValue(scriptInstance_t inst, unsigned int id, VariableValue* value); - void Scr_ClearErrorMessage(scriptInstance_t inst); void VM_Shutdown(scriptInstance_t inst); void Scr_ShutdownVariables(scriptInstance_t inst);