Skip to content

Instantly share code, notes, and snippets.

@AltimorTASDK
Created December 11, 2014 22:01
Show Gist options
  • Save AltimorTASDK/11e10cdd4ac3f712881c to your computer and use it in GitHub Desktop.
Save AltimorTASDK/11e10cdd4ac3f712881c to your computer and use it in GitHub Desktop.
/*
* Recursively scan the tree of datatables for a netvar with the given name
*/
static size_t recursive_scan(RecvTable *table,
const char *var_name,
size_t accum = 0)
{
for(auto i = 0; i < table->GetNumProps(); i++) {
const auto *prop = table->GetProp(i);
if(std::strcmp(prop->GetName(), var_name) == 0)
return accum + prop->GetOffset();
if(prop->GetType() != DPT_DataTable)
continue;
auto result = recursive_scan(prop->GetDataTable(),
var_name,
accum + prop->GetOffset());
if(result != 0)
return result;
}
return 0;
}
/*
* Given a class name (ex CBasePlayer) and a netvar name get the netvar offset
*/
size_t get_netvar(const char *class_name, const char *var_name)
{
for(auto *list = iface::client->GetAllClasses();
list != nullptr;
list = list->m_pNext) {
if(std::strcmp(list->GetName(), class_name) == 0)
return recursive_scan(list->m_pRecvTable, var_name);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment