From 87b1833f73811d3053fa4efe1543d0f68ff12759 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 9 Nov 2015 23:33:25 +0100 Subject: [PATCH] Refactor gamerules address retrieval --- modules/fakemeta/fakemeta_amxx.cpp | 23 +++++++++++++---------- modules/fakemeta/fakemeta_amxx.h | 2 +- modules/fakemeta/pdata_gamerules.cpp | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/modules/fakemeta/fakemeta_amxx.cpp b/modules/fakemeta/fakemeta_amxx.cpp index 4be7c85a..2ff4d590 100644 --- a/modules/fakemeta/fakemeta_amxx.cpp +++ b/modules/fakemeta/fakemeta_amxx.cpp @@ -19,13 +19,13 @@ IGameConfig *GamerulesConfig; IGameConfigManager *ConfigManager; HLTypeConversion TypeConversion; -void *GameRulesReferenceAddress; -void *GameRulesAddress; +void **GameRulesAddress; void OnAmxxAttach() { initialze_offsets(); initialize_glb_offsets(); + MF_AddNatives(engfunc_natives); MF_AddNatives(dllfunc_natives); MF_AddNatives(pev_natives); @@ -35,6 +35,9 @@ void OnAmxxAttach() MF_AddNatives(glb_natives); MF_AddNatives(ext2_natives); MF_AddNatives(misc_natives); + MF_AddNatives(pdata_entities_natives); + MF_AddNatives(pdata_gamerules_natives); + g_kvd_glb.kvd.szClassName = const_cast(g_kvd_glb.cls.chars()); g_kvd_glb.kvd.szKeyName = const_cast(g_kvd_glb.key.chars()); g_kvd_glb.kvd.szValue = const_cast(g_kvd_glb.val.chars()); @@ -58,14 +61,19 @@ void OnAmxxAttach() return; } - if (!CommonConfig->GetAddress("g_pGameRules", &GameRulesReferenceAddress) || !GameRulesReferenceAddress) + void *address = nullptr; + + if (!CommonConfig->GetAddress("g_pGameRules", &address) || !address) { MF_Log("get/set_gamerules_* natives have been disabled because g_pGameRules address could not be found. "); return; } - MF_AddNatives(pdata_entities_natives); - MF_AddNatives(pdata_gamerules_natives); +#if defined(KE_WINDOWS) + GameRulesAddress = *reinterpret_cast(address); +#else + GameRulesAddress = reinterpret_cast(address); +#endif } void OnPluginsLoaded() @@ -97,11 +105,6 @@ 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 a41cccda..fad11f14 100644 --- a/modules/fakemeta/fakemeta_amxx.h +++ b/modules/fakemeta/fakemeta_amxx.h @@ -80,7 +80,7 @@ extern IGameConfig *GamerulesConfig; extern IGameConfigManager *ConfigManager; extern HLTypeConversion TypeConversion; -extern void *GameRulesAddress; +extern void **GameRulesAddress; #endif //_FAKEMETA_INCLUDE_H diff --git a/modules/fakemeta/pdata_gamerules.cpp b/modules/fakemeta/pdata_gamerules.cpp index 6ad806d1..fb854a2f 100644 --- a/modules/fakemeta/pdata_gamerules.cpp +++ b/modules/fakemeta/pdata_gamerules.cpp @@ -25,7 +25,7 @@ static cell AMX_NATIVE_CALL get_gamerules_int(AMX *amx, cell *params) int element = params[3]; CHECK_DATA(data, element, BaseFieldType::Integer); - return PvData::GetInt(GameRulesAddress, data, element); + return PvData::GetInt(*GameRulesAddress, data, element); } // native set_gamerules_int(const class[], const member[], any:value, element = 0); @@ -45,7 +45,7 @@ static cell AMX_NATIVE_CALL set_gamerules_int(AMX *amx, cell *params) return 0; } - PvData::SetInt(GameRulesAddress, data, params[3], element); + PvData::SetInt(*GameRulesAddress, data, params[3], element); return 0; } @@ -62,7 +62,7 @@ static cell AMX_NATIVE_CALL get_gamerules_float(AMX *amx, cell *params) int element = params[3]; CHECK_DATA(data, element, BaseFieldType::Float); - return PvData::GetFloat(GameRulesAddress, data, element); + return PvData::GetFloat(*GameRulesAddress, data, element); } // native set_gamerules_float(const class[], const member[], Float:value, element = 0); @@ -76,7 +76,7 @@ static cell AMX_NATIVE_CALL set_gamerules_float(AMX *amx, cell *params) int element = params[4]; CHECK_DATA(data, element, BaseFieldType::Float); - PvData::SetFloat(GameRulesAddress, data, amx_ctof(params[3]), element); + PvData::SetFloat(*GameRulesAddress, data, amx_ctof(params[3]), element); return 1; } @@ -93,7 +93,7 @@ static cell AMX_NATIVE_CALL get_gamerules_vector(AMX *amx, cell *params) int element = params[4]; CHECK_DATA(data, element, BaseFieldType::Vector); - PvData::GetVector(GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element); + PvData::GetVector(*GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element); return 1; } @@ -109,7 +109,7 @@ static cell AMX_NATIVE_CALL set_gamerules_vector(AMX *amx, cell *params) int element = params[4]; CHECK_DATA(data, element, BaseFieldType::Vector); - PvData::GetVector(GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element); + PvData::GetVector(*GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element); return 1; } @@ -126,7 +126,7 @@ static cell AMX_NATIVE_CALL get_gamerules_entity(AMX *amx, cell *params) int element = params[3]; CHECK_DATA(data, element, BaseFieldType::Entity); - return PvData::GetEntity(GameRulesAddress, data, element); + return PvData::GetEntity(*GameRulesAddress, data, element); } // native set_gamerules_entity(const class[], const member[], value, element = 0); @@ -147,7 +147,7 @@ static cell AMX_NATIVE_CALL set_gamerules_entity(AMX *amx, cell *params) int element = params[4]; CHECK_DATA(data, element, BaseFieldType::Entity); - PvData::SetEntity(GameRulesAddress, data, params[3], element); + PvData::SetEntity(*GameRulesAddress, data, params[3], element); return 0; } @@ -167,7 +167,7 @@ static cell AMX_NATIVE_CALL get_gamerules_string(AMX *amx, cell *params) auto buffer = params[3]; auto maxlen = params[4]; - auto string = PvData::GetString(GameRulesAddress, data, element); + auto string = PvData::GetString(*GameRulesAddress, data, element); if (data.fieldSize) { @@ -191,7 +191,7 @@ static cell AMX_NATIVE_CALL set_gamerules_string(AMX *amx, cell *params) int length; const char *value = MF_GetAmxString(amx, params[3], 0, &length); - return PvData::SetString(GameRulesAddress, data, value, length, element); + return PvData::SetString(*GameRulesAddress, data, value, length, element); }