diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 4fc44fe6..1a578103 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -133,40 +133,57 @@ void CHalfLife2::OnSourceModAllInitialized() void CHalfLife2::OnSourceModAllInitialized_Post() { char *addr = NULL; -#ifdef PLATFORM_WINDOWS - int offset; - /* gEntList and/or g_pEntityList */ - if (!g_pGameConf->GetMemSig("LevelShutdown", (void **)&addr)) + /* + * gEntList and/or g_pEntityList + * + * First try to lookup pointer directly for platforms with symbols. + * If symbols aren't present (Windows or stripped Linux/Mac), + * attempt find via LevelShutdown + offset + */ + if (g_pGameConf->GetMemSig("gEntList", (void **)&addr)) { - g_Logger.LogError("Logical Entities not supported by this mod (LevelShutdown) - Reverting to networkable entities only"); - return; + if (!addr) + { + // Key exists so notify if lookup fails, but try other method. + g_Logger.LogError("Failed lookup of gEntList directly - Reverting to lookup via LevelShutdown"); + } + else + { + g_EntList = reinterpret_cast(addr); + } } - if (!addr) + + + if (!g_EntList) { - g_Logger.LogError("Failed lookup of LevelShutdown - Reverting to networkable entities only"); - return; + if (!g_pGameConf->GetMemSig("LevelShutdown", (void **)&addr)) + { + g_Logger.LogError("Logical Entities not supported by this mod (LevelShutdown) - Reverting to networkable entities only"); + return; + } + + if (!addr) + { + g_Logger.LogError("Failed lookup of LevelShutdown - Reverting to networkable entities only"); + return; + } + + int offset; + if (!g_pGameConf->GetOffset("gEntList", &offset)) + { + g_Logger.LogError("Logical Entities not supported by this mod (gEntList) - Reverting to networkable entities only"); + return; + } + + g_EntList = *reinterpret_cast(addr + offset); } - if (!g_pGameConf->GetOffset("gEntList", &offset)) - { - g_Logger.LogError("Logical Entities not supported by this mod (gEntList) - Reverting to networkable entities only"); - return; - } - g_EntList = *reinterpret_cast(addr + offset); -#elif defined PLATFORM_LINUX || defined PLATFORM_APPLE - /* gEntList and/or g_pEntityList */ - if (!g_pGameConf->GetMemSig("gEntList", (void **)&addr)) - { - g_Logger.LogError("Logical Entities not supported by this mod (gEntList) - Reverting to networkable entities only"); - return; - } - if (!addr) + + if (!g_EntList) { g_Logger.LogError("Failed lookup of gEntList - Reverting to networkable entities only"); return; } - g_EntList = reinterpret_cast(addr); -#endif if (!g_pGameConf->GetOffset("EntInfo", &entInfoOffset)) { diff --git a/extensions/sdktools/tempents.cpp b/extensions/sdktools/tempents.cpp index 46f1185a..80d1f3d6 100644 --- a/extensions/sdktools/tempents.cpp +++ b/extensions/sdktools/tempents.cpp @@ -285,26 +285,33 @@ void TempEntityManager::Initialize() int offset; m_Loaded = false; + /* + * First try to lookup s_pTempEntities directly for platforms with symbols. + * If symbols aren't present (Windows or stripped Linux/Mac), + * attempt find via CBaseTempEntity ctor + offset + */ + /* Read our sigs and offsets from the config file */ -#if defined PLATFORM_WINDOWS - if (!g_pGameConf->GetMemSig("CBaseTempEntity", &addr) || !addr) + if (g_pGameConf->GetMemSig("s_pTempEntities", &addr) && addr) + { + + /* Store the head of the TE linked list */ + m_ListHead = *(void **)addr; + } + else if (g_pGameConf->GetMemSig("CBaseTempEntity", &addr) && addr) + { + if (!g_pGameConf->GetOffset("s_pTempEntities", &offset)) + { + return; + } + /* Store the head of the TE linked list */ + m_ListHead = **(void ***)((unsigned char *)addr + offset); + } + else { return; } - if (!g_pGameConf->GetOffset("s_pTempEntities", &offset)) - { - return; - } - /* Store the head of the TE linked list */ - m_ListHead = **(void ***)((unsigned char *)addr + offset); -#else - if (!g_pGameConf->GetMemSig("s_pTempEntities", &addr) || !addr) - { - return; - } - /* Store the head of the TE linked list */ - m_ListHead = *(void **)addr; -#endif + if (!g_pGameConf->GetOffset("GetTEName", &m_NameOffs)) { return; diff --git a/extensions/sdktools/vglobals.cpp b/extensions/sdktools/vglobals.cpp index 1e45c7cd..c72ddff3 100644 --- a/extensions/sdktools/vglobals.cpp +++ b/extensions/sdktools/vglobals.cpp @@ -39,29 +39,28 @@ void InitializeValveGlobals() { g_EntList = gamehelpers->GetGlobalEntityList(); + /* + * g_pGameRules + * + * First try to lookup pointer directly for platforms with symbols. + * If symbols aren't present (Windows or stripped Linux/Mac), + * attempt find via CreateGameRulesObject + offset + */ + char *addr; - -#ifdef PLATFORM_WINDOWS - /* g_pGameRules */ - if (!g_pGameConf->GetMemSig("CreateGameRulesObject", (void **)&addr) || !addr) + if (g_pGameConf->GetMemSig("g_pGameRules", (void **)&addr) && addr) { - return; + g_pGameRules = reinterpret_cast(addr); } - - int offset; - if (!g_pGameConf->GetOffset("g_pGameRules", &offset) || !offset) + else if (g_pGameConf->GetMemSig("CreateGameRulesObject", (void **)&addr) && addr) { - return; + int offset; + if (!g_pGameConf->GetOffset("g_pGameRules", &offset) || !offset) + { + return; + } + g_pGameRules = *reinterpret_cast(addr + offset); } - g_pGameRules = *reinterpret_cast(addr + offset); -#elif defined PLATFORM_LINUX || defined PLATFORM_APPLE - /* g_pGameRules */ - if (!g_pGameConf->GetMemSig("g_pGameRules", (void **)&addr) || !addr) - { - return; - } - g_pGameRules = reinterpret_cast(addr); -#endif } size_t UTIL_StringToSignature(const char *str, char buffer[], size_t maxlength)