This repository has been archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnetvarmanager.cpp
executable file
·150 lines (112 loc) · 3.37 KB
/
netvarmanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "main.hpp"
#include <cstdio>
std::vector<RecvTable *> NetVarManager::getTables()
{
std::vector<RecvTable *> tables;
ClientClass *clientClass = pClient->GetAllClasses();
if (!clientClass)
return std::vector<RecvTable*>();
while (clientClass)
{
RecvTable *recvTable = clientClass->m_pRecvTable;
tables.push_back(recvTable);
clientClass = clientClass->m_pNext;
}
return tables;
}
RecvTable* NetVarManager::getTable(std::vector<RecvTable *> tables, const char *tableName)
{
if (tables.empty())
return NULL;
for (unsigned long i = 0; i < tables.size(); i++)
{
RecvTable *table = tables[i];
if (!table)
continue;
if (strcasecmp(table->m_pNetTableName, tableName) == 0)
return table;
}
return NULL;
}
int NetVarManager::getOffset(std::vector<RecvTable *> tables, const char *tableName, const char *propName)
{
int offset = getProp(tables, tableName, propName);
if (!offset)
return 0;
else
pCvar->ConsoleColorPrintf(Color(0, 255, 0, 255), "Found: %s ~ > 0x%X\n", propName, offset);
return offset;
}
int NetVarManager::getProp(std::vector<RecvTable *> tables, const char *tableName, const char *propName, RecvProp **prop)
{
RecvTable *recvTable = getTable(tables, tableName);
if (!recvTable)
return 0;
int offset = getProp(tables, recvTable, propName, prop);
if (!offset)
return 0;
return offset;
}
int NetVarManager::getProp(std::vector<RecvTable *> tables, RecvTable *recvTable, const char *propName, RecvProp **prop)
{
int extraOffset = 0;
for (int i = 0; i < recvTable->m_nProps; ++i) {
RecvProp *recvProp = &recvTable->m_pProps[i];
RecvTable *child = recvProp->m_pDataTable;
if (child && (child->m_nProps > 0))
{
int tmp = getProp(tables, child, propName, prop);
if (tmp)
extraOffset += (recvProp->m_Offset + tmp);
}
if (strcasecmp(recvProp->m_pVarName, propName))
continue;
if (prop)
*prop = recvProp;
return (recvProp->m_Offset + extraOffset);
}
return extraOffset;
}
std::string NetVarManager::dumpTable(RecvTable *table, int depth)
{
std::string pre("");
std::stringstream ss;
for (int i = 0; i < depth; i++)
pre.append("\t");
ss << pre << table->m_pNetTableName << "\n";
for (int i = 0; i < table->m_nProps; i++) {
RecvProp *prop = &table->m_pProps[i];
if (!prop)
continue;
std::string varName(prop->m_pVarName);
if (varName.find("baseclass") == 0 || varName.find("0") == 0 || varName.find("1") == 0 || varName.find("2") == 0)
continue;
ss << pre << "\t" << varName << " [0x" << prop->m_Offset << "]\n";
if (prop->m_pDataTable)
ss << dumpTable(prop->m_pDataTable, depth + 1);
}
return ss.str();
}
uintptr_t NetVarManager::HookProp(const char* tableName, const char* propName, RecvVarProxyFn function) {
RecvProp* recvProp = 0;
NetVarManager::getProp(NetVarManager::getTables(), tableName, propName, &recvProp);
if (!recvProp)
return 0;
uintptr_t old = (uintptr_t)recvProp->m_ProxyFn;
recvProp->m_ProxyFn = function;
return old;
}
void NetVarManager::dumpNetvars()
{
std::stringstream ss;
char cwd[1024];
for (ClientClass *pClass = pClient->GetAllClasses(); pClass != NULL; pClass = pClass->m_pNext)
{
RecvTable *table = pClass->m_pRecvTable;
ss << NetVarManager::dumpTable(table, 0);
}
getcwd(cwd, sizeof(cwd));
char* netvarsPath;
asprintf(&netvarsPath, "%s/netvars.txt", cwd);
std::ofstream(netvarsPath) << ss.str();
}