Fix logical entity support for Dota 2 and CS:GO on Windows.

This commit is contained in:
Nicholas Hastings 2014-02-07 20:44:52 -05:00
parent f457362f18
commit 6e40168f79
2 changed files with 54 additions and 34 deletions

View File

@ -72,8 +72,23 @@ CHalfLife2 g_HL2;
ConVar *sv_lan = NULL; ConVar *sv_lan = NULL;
static void *g_EntList = NULL; static void *g_EntList = NULL;
static void **g_pEntInfoList = NULL;
static int entInfoOffset = -1; 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 namespace SourceHook
{ {
template<> template<>
@ -192,40 +207,39 @@ void CHalfLife2::InitLogicalEntData()
#endif #endif
} }
if (!g_EntList) 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"); int offset;
return; 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_EntList = *reinterpret_cast<void **>(addr + offset);
{
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<void **>(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; 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; return;
} }
} }
@ -993,7 +1007,9 @@ CEntInfo *CHalfLife2::LookupEntity(int entIndex)
return NULL; return NULL;
} }
if (!g_EntList || entInfoOffset == -1) CEntInfo *entInfos = EntInfoArray();
if (!entInfos)
{ {
/* Attempt to use engine interface instead */ /* Attempt to use engine interface instead */
static CEntInfo tempInfo; static CEntInfo tempInfo;
@ -1020,8 +1036,7 @@ CEntInfo *CHalfLife2::LookupEntity(int entIndex)
return &tempInfo; return &tempInfo;
} }
CEntInfo *pArray = (CEntInfo *)(((unsigned char *)g_EntList) + entInfoOffset); return &entInfos[entIndex];
return &pArray[entIndex];
} }
/** /**

View File

@ -19,17 +19,22 @@
"game" "csgo" "game" "csgo"
} }
"Addresses"
{
"EntInfosPtr"
{
"windows"
{
"signature" "EntInfosFinder"
"read" "36"
}
}
}
"Offsets" "Offsets"
{ {
/* Offset into LevelShutdown */
"gEntList"
{
"windows" "11"
}
"EntInfo" "EntInfo"
{ {
"windows" "4"
"linux" "4" "linux" "4"
"mac" "4" "mac" "4"
} }
@ -37,10 +42,10 @@
"Signatures" "Signatures"
{ {
"LevelShutdown" "EntInfosFinder"
{ {
"library" "server" "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" "gEntList"