diff --git a/hook_lib/functions.cpp b/hook_lib/functions.cpp index 89896f2..74cc9bb 100644 --- a/hook_lib/functions.cpp +++ b/hook_lib/functions.cpp @@ -193,6 +193,11 @@ bool lua_toboolean(uintptr_t L, int idx) { return func(L, idx); } +const char* lua_tolstring(uintptr_t L, int idx, size_t* len) { + auto func = reinterpret_cast(0x142084950_g); + return func(L, idx, len); +} + void lua_pushboolean(uintptr_t L, int b) { auto func = reinterpret_cast(0x142083E80_g); func(L, b); @@ -233,6 +238,11 @@ void lua_settop(uintptr_t L, int idx) { func(L, idx); } +bool lua_isstring(uintptr_t L, int idx) { + auto func = reinterpret_cast(0x142083A30_g); + return func(L, idx); +} + int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults) { auto func = reinterpret_cast(0x1419B7570_g); return func(luaVM, nargs, nresults); diff --git a/hook_lib/functions.hpp b/hook_lib/functions.hpp index 452e8a7..0e0462d 100644 --- a/hook_lib/functions.hpp +++ b/hook_lib/functions.hpp @@ -178,6 +178,7 @@ bool LUI_LuaCall_Game_IsEntityAlive(uintptr_t luaVM, int entityNum); void Cbuf_AddText(const char* cmd); bool lua_toboolean(uintptr_t L, int idx); +const char* lua_tolstring(uintptr_t L, int idx, size_t* len); void lua_pushboolean(uintptr_t L, int b); void lua_remove(uintptr_t L, int idx); @@ -187,6 +188,9 @@ void lua_pushvalue(uintptr_t L, int idx); void lua_pushstring(uintptr_t L, const char* str); void lua_pushinteger(uintptr_t L, int n); void lua_settop(uintptr_t L, int idx); + +bool lua_isstring(uintptr_t L, int idx); + int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults); bool CG_DObjGetWorldBoneMatrix(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin); diff --git a/hook_lib/inventory.cpp b/hook_lib/inventory.cpp index c84bd8b..bd65575 100644 --- a/hook_lib/inventory.cpp +++ b/hook_lib/inventory.cpp @@ -238,7 +238,7 @@ void SaveInventory() } } } - // printf("Saved Inventory!\n"); + printf("Saved Inventory!\n"); } else { Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_PRIVATELOADOUTS, called before initialized?"); @@ -268,7 +268,7 @@ void SaveInventory() inventoryJson["customizationBackground"][i] = { {"customizationBackgroundName", DDL_GetInt(&state, &context)} }; } } - // printf("Saved Customizations!\n"); + printf("Saved Customizations!\n"); } else { Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_NONGAME, called before initialized?"); @@ -527,7 +527,7 @@ void LoadInventory() } } } - // printf("Loaded Inventory!\n"); + printf("Loaded Inventory!\n"); } else { Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_PRIVATELOADOUTS, called before initialized?"); @@ -556,7 +556,7 @@ void LoadInventory() DDL_SetInt(&state, &context, inventoryJson["customizationBackground"][i]["customizationBackgroundName"]); } } - // printf("Loaded Customizations!\n"); + printf("Loaded Customizations!\n"); } else { Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_NONGAME, called before initialized?"); diff --git a/hook_lib/lui_cod.cpp b/hook_lib/lui_cod.cpp index e357971..040ca52 100644 --- a/hook_lib/lui_cod.cpp +++ b/hook_lib/lui_cod.cpp @@ -20,8 +20,19 @@ int LuaShared_LuaCall_IsDemoBuild_Detour(uintptr_t luaVM) return 1; } -int LUI_CoD_LuaCall_GetBlueprintData_impl_Detour(uintptr_t luaState) -{ - SaveInventory(); - return 0; +void LUI_CoD_LuaCall_EngineNotifyServer_Detour(uintptr_t luaVM) { + static std::unordered_map> handlerMap{ + {"class_edit", SaveInventory}, + {"loadout_showcase_entered", SaveInventory} + }; + if (lua_isstring(luaVM, 1)) { + size_t strLen = 0; + const char* rawStr = lua_tolstring(luaVM, 1, &strLen); + std::string str(rawStr, strLen); + if (handlerMap.find(str) != handlerMap.cend()) + { + handlerMap.at(str)(); + } + } + lui_cod_luacall_enginenotifyserver_detour_impl.stub(luaVM); } \ No newline at end of file diff --git a/hook_lib/lui_cod.h b/hook_lib/lui_cod.h index da9814d..4824276 100644 --- a/hook_lib/lui_cod.h +++ b/hook_lib/lui_cod.h @@ -6,5 +6,5 @@ void LUI_CoD_RegisterDvars_Detour(); int LuaShared_LuaCall_IsDemoBuild_Detour(uintptr_t luaVM); -inline utils::hook::detour lui_cod_luacall_getblueprintdata_impl; -int LUI_CoD_LuaCall_GetBlueprintData_impl_Detour(uintptr_t luaState); \ No newline at end of file +inline utils::hook::detour lui_cod_luacall_enginenotifyserver_detour_impl; +void LUI_CoD_LuaCall_EngineNotifyServer_Detour(uintptr_t luaVM); \ No newline at end of file diff --git a/hook_lib/patch.cpp b/hook_lib/patch.cpp index d2e3483..e416750 100644 --- a/hook_lib/patch.cpp +++ b/hook_lib/patch.cpp @@ -143,7 +143,7 @@ void hooks() com_gamemode_supportsfeature.create(0x1410C8980_g, Com_GameMode_SupportsFeature_Detour); - lui_cod_luacall_getblueprintdata_impl.create(0x140F58A00_g, LUI_CoD_LuaCall_GetBlueprintData_impl_Detour); + lui_cod_luacall_enginenotifyserver_detour_impl.create(0x1419F7160_g, LUI_CoD_LuaCall_EngineNotifyServer_Detour); // remove FF Header version check // db_checkxfileversion.create(0x1411A7840_g, DB_CheckXFileVersion_Detour);