From b79d6b7c5fb8c25a32cf5592be728042c8ecb0ee Mon Sep 17 00:00:00 2001 From: "J. Farnsworth" <6502enthusiast@gmail.com> Date: Sat, 7 Jan 2017 17:09:21 -0500 Subject: [PATCH] Implemented a netvar offset cache --- src/Utilities/NetVars.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Utilities/NetVars.h b/src/Utilities/NetVars.h index 9862154..e91a1c1 100644 --- a/src/Utilities/NetVars.h +++ b/src/Utilities/NetVars.h @@ -1,5 +1,7 @@ #pragma once +#include + class NetVars { private: static uintptr_t FindOffset(RecvTable* recv_table, const char* property_name, RecvProp** property_ptr = nullptr) { @@ -29,12 +31,29 @@ class NetVars { } public: static uintptr_t GetOffset(const char* class_name, const char* property_name, RecvProp** property_ptr = nullptr) { + typedef std::unordered_map PropertyCache; + typedef std::unordered_map ClassCache; + static ClassCache classCache; + + ClassCache::iterator itrClassCache = classCache.find(class_name); + if(itrClassCache != classCache.end()) + { + PropertyCache &propertyCache = itrClassCache->second; + PropertyCache::iterator itrPropertyCache = propertyCache.find(property_name); + if(itrPropertyCache != propertyCache.end()) + { + return itrPropertyCache->second; + } + } + for (ClientClass* class_ptr = clientdll->GetAllClasses(); class_ptr; class_ptr = class_ptr->m_pNext) { if (strcmp(class_ptr->m_pNetworkName, class_name) == 0) { - return FindOffset(class_ptr->m_pRecvTable, property_name, property_ptr); + uintptr_t result = FindOffset(class_ptr->m_pRecvTable, property_name, property_ptr); + classCache[class_name][property_name] = result; + return result; } } return 0; } -}; \ No newline at end of file +};