Merge pull request #2 from sakura57/master

Implemented a netvar offset cache
This commit is contained in:
aixxe 2017-01-08 16:40:18 +00:00 committed by GitHub
commit ac03e2ead1
1 changed files with 21 additions and 2 deletions

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <unordered_map>
class NetVars { class NetVars {
private: private:
static uintptr_t FindOffset(RecvTable* recv_table, const char* property_name, RecvProp** property_ptr = nullptr) { static uintptr_t FindOffset(RecvTable* recv_table, const char* property_name, RecvProp** property_ptr = nullptr) {
@ -29,9 +31,26 @@ class NetVars {
} }
public: public:
static uintptr_t GetOffset(const char* class_name, const char* property_name, RecvProp** property_ptr = nullptr) { static uintptr_t GetOffset(const char* class_name, const char* property_name, RecvProp** property_ptr = nullptr) {
typedef std::unordered_map<const char *, uintptr_t> PropertyCache;
typedef std::unordered_map<const char *, PropertyCache> 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) { for (ClientClass* class_ptr = clientdll->GetAllClasses(); class_ptr; class_ptr = class_ptr->m_pNext) {
if (strcmp(class_ptr->m_pNetworkName, class_name) == 0) { 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;
} }
} }