From d2eedc0e31dea3261b917ad9df253789f9c1d9d7 Mon Sep 17 00:00:00 2001 From: Mikusch <25514044+Mikusch@users.noreply.github.com> Date: Sat, 1 Aug 2026 16:41:01 +0200 Subject: [PATCH] Add support for dot-delimited entity property paths (#2518) * Support dot-delimited netprop/datamap paths * Try an exact match first --- core/HalfLife2.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 833ba48f..aac46274 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -399,7 +399,70 @@ bool UTIL_FindDataMapInfo(datamap_t *pMap, const char *name, sm_datatable_info_t pMap = pMap->baseMap; } - return false; + return false; +} + +template +static bool UTIL_FindInTablePath(Table *pTable, const char *name, Info *info, + bool (*search)(Table *, const char *, Info *), + Table *(*descend)(const Info &)) +{ + unsigned int baseOffset = 0; + const char *component = name; + + while (true) + { + const char *dot = strchr(component, '.'); + size_t len = dot ? (size_t)(dot - component) : strlen(component); + + char buffer[256]; + if (len == 0 || len >= sizeof(buffer)) + { + return false; + } + + memcpy(buffer, component, len); + buffer[len] = '\0'; + + // Search the table for the prop + Info local; + if (!search(pTable, buffer, &local)) + { + return false; + } + + if (!dot) + { + info->prop = local.prop; + info->actual_offset = baseOffset + local.actual_offset; + return true; + } + + // Handle nested properties + Table *pNext = descend(local); + if (!pNext) + { + return false; + } + + baseOffset += local.actual_offset; + pTable = pNext; + component = dot + 1; + } +} + +static bool UTIL_FindInSendTablePath(SendTable *pTable, const char *name, sm_sendprop_info_t *info) +{ + return UTIL_FindInTablePath(pTable, name, info, + [](SendTable *t, const char *n, sm_sendprop_info_t *o) { return UTIL_FindInSendTable(t, n, o, 0); }, + [](const sm_sendprop_info_t &i) -> SendTable * { return i.prop->GetDataTable(); }); +} + +static bool UTIL_FindDataMapInfoPath(datamap_t *pMap, const char *name, sm_datatable_info_t *info) +{ + return UTIL_FindInTablePath(pMap, name, info, + [](datamap_t *m, const char *n, sm_datatable_info_t *o) { return UTIL_FindDataMapInfo(m, n, o); }, + [](const sm_datatable_info_t &i) -> datamap_t * { return i.prop->td; }); } ServerClass *CHalfLife2::FindServerClass(const char *classname) @@ -460,6 +523,10 @@ bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_ if (!pInfo->lookup.retrieve(offset, &temp)) { bool found = UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp.info, 0); + if (!found && strchr(offset, '.')) + { + found = UTIL_FindInSendTablePath(pInfo->sc->m_pTable, offset, &temp.info); + } temp.name = offset; pInfo->lookup.insert(offset, temp); @@ -512,6 +579,10 @@ bool CHalfLife2::FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatab if (!cache->retrieve(offset, &temp)) { bool found = UTIL_FindDataMapInfo(pMap, offset, &temp.info); + if (!found && strchr(offset, '.')) + { + found = UTIL_FindDataMapInfoPath(pMap, offset, &temp.info); + } temp.name = offset; cache->insert(offset, temp);