diff --git a/gamedata/common.games/globalvars.engine.txt b/gamedata/common.games/globalvars.engine.txt index e0389709..ccc3b2b9 100644 --- a/gamedata/common.games/globalvars.engine.txt +++ b/gamedata/common.games/globalvars.engine.txt @@ -40,6 +40,18 @@ "read" "2" } } + + "g_pGameRules" + { + "signature" "g_pGameRules" + + "windows" + { + "read" "2" + } + + "read" "0" + } } "Signatures" @@ -66,6 +78,14 @@ "linux" "@realtime" "mac" "@realtime" } + + "g_pGameRules" // CGameRules *g_pGameRules + { + "library" "server" + "windows" "\x8B\x2A\x2A\x2A\x2A\x2A\x85\x2A\x74\x2A\x8B\x2A\xFF\x2A\x2A\xA1" // StartFrame() + "linux" "@g_pGameRules" + "mac" "@g_pGameRules" + } } } } diff --git a/modules/fakemeta/fakemeta_amxx.cpp b/modules/fakemeta/fakemeta_amxx.cpp index 5814ed44..ca0eb3df 100644 --- a/modules/fakemeta/fakemeta_amxx.cpp +++ b/modules/fakemeta/fakemeta_amxx.cpp @@ -15,9 +15,12 @@ #include "sh_stack.h" IGameConfig *CommonConfig; +IGameConfig *GamerulesConfig; IGameConfigManager *ConfigManager; HLTypeConversion TypeConversion; +void *GameRulesReferenceAddress; +void *GameRulesAddress; void OnAmxxAttach() { @@ -39,13 +42,25 @@ void OnAmxxAttach() ConfigManager = MF_GetConfigManager(); - char error[256]; - error[0] = '\0'; + char error[256] = ""; if (!ConfigManager->LoadGameConfigFile("common.games", &CommonConfig, error, sizeof(error)) && error[0] != '\0') { - MF_Log("Could not read common.games gamedata: %s", error); - MF_Log("get/set/find_ent_data* natives have been disabled"); + MF_Log("get/set_ent_data* natives have been disabled because common.games gamedata could not be read: %s", error); + return; + } + + *error = '\0'; + + if (!ConfigManager->LoadGameConfigFile("common.games/gamerules.games", &GamerulesConfig, error, sizeof(error)) && error[0] != '\0') + { + MF_Log("get/set_gamerules_* natives have been disabled because common.games/gamerules.games gamedata could not be read: %s", error); + return; + } + + if (!CommonConfig->GetAddress("g_pGameRules", &GameRulesReferenceAddress) || !GameRulesReferenceAddress) + { + MF_Log("get/set_gamerules_* natives have been disabled because g_pGameRules address could not be found. "); return; } @@ -63,6 +78,9 @@ extern ke::Vector g_FreeKVDWs; void OnAmxxDetach() { + ConfigManager->CloseGameConfigFile(CommonConfig); + ConfigManager->CloseGameConfigFile(GamerulesConfig); + while (!g_FreeTRs.empty()) { delete g_FreeTRs.front(); @@ -78,6 +96,11 @@ void OnAmxxDetach() void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) { + if (GameRulesReferenceAddress) + { + GameRulesAddress = **reinterpret_cast(GameRulesReferenceAddress); + } + g_pFunctionTable_Post->pfnServerDeactivate = FMH_ServerDeactivate_Post; RETURN_META(MRES_IGNORED); } diff --git a/modules/fakemeta/fakemeta_amxx.h b/modules/fakemeta/fakemeta_amxx.h index e61b4f61..c796fb10 100644 --- a/modules/fakemeta/fakemeta_amxx.h +++ b/modules/fakemeta/fakemeta_amxx.h @@ -75,9 +75,11 @@ extern NEW_DLL_FUNCTIONS *g_pNewFunctionsTable; extern NEW_DLL_FUNCTIONS *g_pNewFunctionsTable_Post; extern IGameConfig *CommonConfig; +extern IGameConfig *GamerulesConfig; extern IGameConfigManager *ConfigManager; extern HLTypeConversion TypeConversion; +extern void *GameRulesAddress; #endif //_FAKEMETA_INCLUDE_H