core: Add support for networked CUtlVector (#1330)

* Add offset-reading capability for networked CUtlVector instances

* Use strncmp instead of strstr

* Use strcmp instead of strncmp

Co-authored-by: Asher Baker <asherkin@limetech.io>

* Move CSendPropExtra_UtlVector offset to gamedata

* Update name of offset + add gamedata entry

* tiny nits

Co-authored-by: Asher Baker <asherkin@limetech.io>
Co-authored-by: Kyle Sanderson <kyle.leet@gmail.com>
This commit is contained in:
nosoop 2020-08-06 19:15:20 -07:00 committed by GitHub
parent bb25b03884
commit c5619f887d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -60,6 +60,7 @@ ConVar *sv_lan = NULL;
static void *g_EntList = NULL; static void *g_EntList = NULL;
static void **g_pEntInfoList = NULL; static void **g_pEntInfoList = NULL;
static int entInfoOffset = -1; static int entInfoOffset = -1;
static int utlVecOffsetOffset = -1;
static CEntInfo *EntInfoArray() static CEntInfo *EntInfoArray()
{ {
@ -144,6 +145,7 @@ void CHalfLife2::OnSourceModAllInitialized_Post()
m_CSGOBadList.add("m_nActiveCoinRank"); m_CSGOBadList.add("m_nActiveCoinRank");
m_CSGOBadList.add("m_nMusicID"); m_CSGOBadList.add("m_nMusicID");
#endif #endif
g_pGameConf->GetOffset("CSendPropExtra_UtlVector::m_Offset", &utlVecOffsetOffset);
} }
ConfigResult CHalfLife2::OnSourceModConfigChanged(const char *key, const char *value, ConfigResult CHalfLife2::OnSourceModConfigChanged(const char *key, const char *value,
@ -326,15 +328,28 @@ bool UTIL_FindInSendTable(SendTable *pTable,
{ {
prop = pTable->GetProp(i); prop = pTable->GetProp(i);
pname = prop->GetName(); pname = prop->GetName();
SendTable *pInnerTable = prop->GetDataTable();
if (pname && strcmp(name, pname) == 0) if (pname && strcmp(name, pname) == 0)
{ {
// get true offset of CUtlVector
if (utlVecOffsetOffset != -1 && prop->GetOffset() == 0 && pInnerTable && pInnerTable->GetNumProps())
{
SendProp *pLengthProxy = pInnerTable->GetProp(0);
const char *ipname = pLengthProxy->GetName();
if (ipname && strcmp(ipname, "lengthproxy") == 0 && pLengthProxy->GetExtraData())
{
info->prop = prop;
info->actual_offset = offset + *reinterpret_cast<size_t *>(reinterpret_cast<intptr_t>(pLengthProxy->GetExtraData()) + utlVecOffsetOffset);
return true;
}
}
info->prop = prop; info->prop = prop;
info->actual_offset = offset + info->prop->GetOffset(); info->actual_offset = offset + info->prop->GetOffset();
return true; return true;
} }
if (prop->GetDataTable()) if (pInnerTable)
{ {
if (UTIL_FindInSendTable(prop->GetDataTable(), if (UTIL_FindInSendTable(pInnerTable,
name, name,
info, info,
offset + prop->GetOffset()) offset + prop->GetOffset())

View File

@ -20,6 +20,11 @@
"class" "CBasePlayer" "class" "CBasePlayer"
"prop" "m_lifeState" "prop" "m_lifeState"
} }
"CSendPropExtra_UtlVector::m_Offset"
{
"windows" "16"
"linux" "16"
}
} }
} }