From 6e40168f794036ab7ca0f6197ae0af362782daf5 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Fri, 7 Feb 2014 20:44:52 -0500 Subject: [PATCH] Fix logical entity support for Dota 2 and CS:GO on Windows. --- core/HalfLife2.cpp | 65 ++++++++++++++++++----------- gamedata/core.games/engine.csgo.txt | 23 ++++++---- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 97f7b966..60a18543 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -72,8 +72,23 @@ CHalfLife2 g_HL2; ConVar *sv_lan = NULL; static void *g_EntList = NULL; +static void **g_pEntInfoList = NULL; static int entInfoOffset = -1; +static CEntInfo *EntInfoArray() +{ + if (g_EntList != NULL) + { + return (CEntInfo *)((intp)g_EntList + entInfoOffset); + } + else if (g_pEntInfoList) + { + return *(CEntInfo **)g_pEntInfoList; + } + + return NULL; +} + namespace SourceHook { template<> @@ -192,40 +207,39 @@ void CHalfLife2::InitLogicalEntData() #endif } - if (!g_EntList) { - if (!g_pGameConf->GetMemSig("LevelShutdown", (void **)&addr)) + if (g_pGameConf->GetMemSig("LevelShutdown", (void **) &addr) && addr) { - g_Logger.LogError("Logical Entities not supported by this mod (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; + } - if (!addr) - { - g_Logger.LogError("Failed lookup of LevelShutdown - Reverting to networkable entities only"); - return; - } + g_EntList = *reinterpret_cast(addr + offset); - 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_EntList) + + // If we have g_EntList from either of the above methods, make sure we can get the offset from it to EntInfo as well + if (g_EntList && !g_pGameConf->GetOffset("EntInfo", &entInfoOffset)) { - g_Logger.LogError("Failed lookup of gEntList - Reverting to networkable entities only"); + g_Logger.LogError("Logical Entities not supported by this mod (EntInfo) - Reverting to networkable entities only"); + g_EntList = NULL; return; } - if (!g_pGameConf->GetOffset("EntInfo", &entInfoOffset)) + // If we don't have g_EntList or have it but don't know where EntInfo is on it, use fallback. + if (!g_EntList || entInfoOffset == -1) { - g_Logger.LogError("Logical Entities not supported by this mod (EntInfo) - Reverting to networkable entities only"); + g_pGameConf->GetAddress("EntInfosPtr", (void **)&g_pEntInfoList); + } + + if (!g_EntList && !g_pEntInfoList) + { + g_Logger.LogError("Failed lookup of gEntList - Reverting to networkable entities only"); return; } } @@ -993,7 +1007,9 @@ CEntInfo *CHalfLife2::LookupEntity(int entIndex) return NULL; } - if (!g_EntList || entInfoOffset == -1) + CEntInfo *entInfos = EntInfoArray(); + + if (!entInfos) { /* Attempt to use engine interface instead */ static CEntInfo tempInfo; @@ -1020,8 +1036,7 @@ CEntInfo *CHalfLife2::LookupEntity(int entIndex) return &tempInfo; } - CEntInfo *pArray = (CEntInfo *)(((unsigned char *)g_EntList) + entInfoOffset); - return &pArray[entIndex]; + return &entInfos[entIndex]; } /** diff --git a/gamedata/core.games/engine.csgo.txt b/gamedata/core.games/engine.csgo.txt index d2a9ea10..d4e86e7f 100644 --- a/gamedata/core.games/engine.csgo.txt +++ b/gamedata/core.games/engine.csgo.txt @@ -19,17 +19,22 @@ "game" "csgo" } + "Addresses" + { + "EntInfosPtr" + { + "windows" + { + "signature" "EntInfosFinder" + "read" "36" + } + } + } + "Offsets" { - /* Offset into LevelShutdown */ - "gEntList" - { - "windows" "11" - } - "EntInfo" { - "windows" "4" "linux" "4" "mac" "4" } @@ -37,10 +42,10 @@ "Signatures" { - "LevelShutdown" + "EntInfosFinder" { "library" "server" - "windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8" + "windows" "\x55\x8B\xEC\x8B\x4D\x08\x53\x56\x57\x85\xC9\x74\x2A\x8B\x01\xFF\x2A\x2A\x8B\x00\x83\xF8\xFF\x75\x11\xB8\x2A\x2A\x2A\x2A\x8D\x34\x40\x8B" } "gEntList"