diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 6e5507b8..53af3dc8 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -445,20 +445,25 @@ bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_ return false; } - if (!pInfo->lookup.retrieve(offset, info)) - { - sm_sendprop_info_t temp_info; + DataTableInfo::SendPropInfo temp; - if (!UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp_info, 0)) + if (!pInfo->lookup.retrieve(offset, &temp)) + { + bool found = UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp.info, 0); + temp.name = offset; + + pInfo->lookup.insert(offset, temp); + + if (found) { - return false; + *info = temp.info; } - pInfo->lookup.insert(offset, temp_info); - *info = temp_info; + return found; } - - return true; + + *info = temp.info; + return info->prop != nullptr; } SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset) @@ -492,15 +497,25 @@ bool CHalfLife2::FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatab m_Maps.add(i, pMap, new DataMapCache()); DataMapCache *cache = i->value; + DataMapCacheInfo temp; - if (!cache->retrieve(offset, pDataTable)) + if (!cache->retrieve(offset, &temp)) { - if (!UTIL_FindDataMapInfo(pMap, offset, pDataTable)) - return false; - cache->insert(offset, *pDataTable); + bool found = UTIL_FindDataMapInfo(pMap, offset, &temp.info); + temp.name = offset; + + cache->insert(offset, temp); + + if (found) + { + *pDataTable = temp.info; + } + + return found; } - return true; + *pDataTable = temp.info; + return pDataTable->prop != nullptr; } void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset) diff --git a/core/HalfLife2.h b/core/HalfLife2.h index 4c1d90a2..b3f9b534 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -89,16 +89,24 @@ using namespace SourceMod; struct DataTableInfo { - struct SendPropPolicy + struct SendPropInfo { - static inline bool matches(const char *name, const sm_sendprop_info_t &info) + static inline bool matches(const char *name, const SendPropInfo &info) { - return strcmp(name, info.prop->GetName()) == 0; + return strcmp(name, info.name.c_str()) == 0; } static inline uint32_t hash(const detail::CharsAndLength &key) { return key.hash(); } + + SendPropInfo() + : name(), info{nullptr, 0} + { + } + + std::string name; + sm_sendprop_info_t info; }; static inline bool matches(const char *name, const DataTableInfo *info) @@ -116,22 +124,30 @@ struct DataTableInfo } ServerClass *sc; - NameHashSet lookup; + NameHashSet lookup; }; -struct DataMapCachePolicy +struct DataMapCacheInfo { - static inline bool matches(const char *name, const sm_datatable_info_t &info) + static inline bool matches(const char *name, const DataMapCacheInfo &info) { - return strcmp(name, info.prop->fieldName) == 0; + return strcmp(name, info.name.c_str()) == 0; } static inline uint32_t hash(const detail::CharsAndLength &key) { return key.hash(); } + + DataMapCacheInfo() + : name(), info{nullptr, 0} + { + } + + std::string name; + sm_datatable_info_t info; }; -typedef NameHashSet DataMapCache; +typedef NameHashSet DataMapCache; struct DelayedFakeCliCmd {