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 03c7a9d5f3
commit 39c82d6ea0
3 changed files with 62 additions and 54 deletions

View File

@ -74,8 +74,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;
}
CHalfLife2::CHalfLife2()
{
m_Maps.init();
@ -161,40 +176,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<void **>(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<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;
}
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;
}
}
@ -996,7 +1010,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;
@ -1023,8 +1039,7 @@ CEntInfo *CHalfLife2::LookupEntity(int entIndex)
return &tempInfo;
}
CEntInfo *pArray = (CEntInfo *)(((unsigned char *)g_EntList) + entInfoOffset);
return &pArray[entIndex];
return &entInfos[entIndex];
}
/**

View File

@ -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"

View File

@ -19,37 +19,25 @@
"game" "dota"
}
"Offsets"
"Addresses"
{
/* Offset into LevelShutdown */
"gEntList"
"EntInfosPtr"
{
"windows" "21"
}
"EntInfo"
{
"windows" "0"
"linux" "4"
"mac" "4"
"windows"
{
"signature" "EntInfosFinder"
"read" "21"
}
}
}
"Signatures"
{
// This isn't LevelShutdown, but there aren't a lot of places to get this from due to crazy insane inlining errwhere
"LevelShutdown"
"EntInfosFinder"
{
"library" "server"
"windows" "\x83\x2A\xFF\x74\x03\x0F\x2A\x2A\xC1\x2A\x04\x8B\x2A\x2A\x2A\x2A\x2A\xEB\x06\x8B"
}
"gEntList"
{
"library" "server"
"linux" "@gEntList"
"mac" "@gEntList"
}
}
}
}