Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a netvar offset cache #2

Merged
merged 1 commit into from Jan 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Utilities/NetVars.h
@@ -1,5 +1,7 @@
#pragma once

#include <unordered_map>

class NetVars {
private:
static uintptr_t FindOffset(RecvTable* recv_table, const char* property_name, RecvProp** property_ptr = nullptr) {
Expand Down Expand Up @@ -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<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) {
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;
}
};
};