Adjust code style and fix unloading in NetVar scanner.

Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
aixxe 2017-01-08 16:47:03 +00:00
parent ac03e2ead1
commit d3ed74068a
1 changed files with 16 additions and 15 deletions

View File

@ -2,6 +2,11 @@
#include <unordered_map> #include <unordered_map>
typedef std::unordered_map<const char*, uintptr_t> PropertyCache;
typedef std::unordered_map<const char*, PropertyCache> ClassCache;
static ClassCache class_cache;
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) {
@ -31,25 +36,21 @@ 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; ClassCache::iterator class_cache_itr = class_cache.find(class_name);
typedef std::unordered_map<const char *, PropertyCache> ClassCache;
static ClassCache classCache; if (class_cache_itr != class_cache.end()) {
PropertyCache& property_cache = class_cache_itr->second;
ClassCache::iterator itrClassCache = classCache.find(class_name); PropertyCache::iterator property_cache_itr = property_cache.find(property_name);
if(itrClassCache != classCache.end())
{ if (property_cache_itr != property_cache.end()) {
PropertyCache &propertyCache = itrClassCache->second; return property_cache_itr->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) {
uintptr_t result = 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; class_cache[class_name][property_name] = result;
return result; return result;
} }
} }