Loadout saving improvements

This commit is contained in:
Werseter 2023-10-27 01:39:06 +02:00
parent e8343276d9
commit f6c19195b8
6 changed files with 36 additions and 11 deletions

View File

@ -193,6 +193,11 @@ bool lua_toboolean(uintptr_t L, int idx) {
return func(L, idx); return func(L, idx);
} }
const char* lua_tolstring(uintptr_t L, int idx, size_t* len) {
auto func = reinterpret_cast<const char* (*)(uintptr_t, int, size_t*)>(0x142084950_g);
return func(L, idx, len);
}
void lua_pushboolean(uintptr_t L, int b) { void lua_pushboolean(uintptr_t L, int b) {
auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142083E80_g); auto func = reinterpret_cast<void(*)(uintptr_t, int)>(0x142083E80_g);
func(L, b); func(L, b);
@ -233,6 +238,11 @@ void lua_settop(uintptr_t L, int idx) {
func(L, idx); func(L, idx);
} }
bool lua_isstring(uintptr_t L, int idx) {
auto func = reinterpret_cast<bool(*)(uintptr_t, int)>(0x142083A30_g);
return func(L, idx);
}
int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults) { int LuaShared_PCall(uintptr_t luaVM, int nargs, int nresults) {
auto func = reinterpret_cast<int(*)(uintptr_t, int, int)>(0x1419B7570_g); auto func = reinterpret_cast<int(*)(uintptr_t, int, int)>(0x1419B7570_g);
return func(luaVM, nargs, nresults); return func(luaVM, nargs, nresults);

View File

@ -178,6 +178,7 @@ bool LUI_LuaCall_Game_IsEntityAlive(uintptr_t luaVM, int entityNum);
void Cbuf_AddText(const char* cmd); void Cbuf_AddText(const char* cmd);
bool lua_toboolean(uintptr_t L, int idx); 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_pushboolean(uintptr_t L, int b);
void lua_remove(uintptr_t L, int idx); 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_pushstring(uintptr_t L, const char* str);
void lua_pushinteger(uintptr_t L, int n); void lua_pushinteger(uintptr_t L, int n);
void lua_settop(uintptr_t L, int idx); 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); 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); bool CG_DObjGetWorldBoneMatrix(uintptr_t pose, uintptr_t obj, int boneIndex, uintptr_t outTagMat, float* outOrigin);

View File

@ -238,7 +238,7 @@ void SaveInventory()
} }
} }
} }
// printf("Saved Inventory!\n"); printf("Saved Inventory!\n");
} }
else { else {
Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_PRIVATELOADOUTS, called before initialized?"); 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)} }; inventoryJson["customizationBackground"][i] = { {"customizationBackgroundName", DDL_GetInt(&state, &context)} };
} }
} }
// printf("Saved Customizations!\n"); printf("Saved Customizations!\n");
} }
else { else {
Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_NONGAME, called before initialized?"); 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 { else {
Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_PRIVATELOADOUTS, called before initialized?"); 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"]); DDL_SetInt(&state, &context, inventoryJson["customizationBackground"][i]["customizationBackgroundName"]);
} }
} }
// printf("Loaded Customizations!\n"); printf("Loaded Customizations!\n");
} }
else { else {
Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_NONGAME, called before initialized?"); Com_SetErrorMessage("[DLL ERROR] Couldn't get DDLBuffer for STATSGROUP_NONGAME, called before initialized?");

View File

@ -20,8 +20,19 @@ int LuaShared_LuaCall_IsDemoBuild_Detour(uintptr_t luaVM)
return 1; return 1;
} }
int LUI_CoD_LuaCall_GetBlueprintData_impl_Detour(uintptr_t luaState) void LUI_CoD_LuaCall_EngineNotifyServer_Detour(uintptr_t luaVM) {
{ static std::unordered_map<std::string, std::function<void()>> handlerMap{
SaveInventory(); {"class_edit", SaveInventory},
return 0; {"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<void>(luaVM);
} }

View File

@ -6,5 +6,5 @@ void LUI_CoD_RegisterDvars_Detour();
int LuaShared_LuaCall_IsDemoBuild_Detour(uintptr_t luaVM); int LuaShared_LuaCall_IsDemoBuild_Detour(uintptr_t luaVM);
inline utils::hook::detour lui_cod_luacall_getblueprintdata_impl; inline utils::hook::detour lui_cod_luacall_enginenotifyserver_detour_impl;
int LUI_CoD_LuaCall_GetBlueprintData_impl_Detour(uintptr_t luaState); void LUI_CoD_LuaCall_EngineNotifyServer_Detour(uintptr_t luaVM);

View File

@ -143,7 +143,7 @@ void hooks()
com_gamemode_supportsfeature.create(0x1410C8980_g, Com_GameMode_SupportsFeature_Detour); 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 // remove FF Header version check
// db_checkxfileversion.create(0x1411A7840_g, DB_CheckXFileVersion_Detour); // db_checkxfileversion.create(0x1411A7840_g, DB_CheckXFileVersion_Detour);