-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNetVars.cpp
122 lines (89 loc) · 2.81 KB
/
NetVars.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
/*
Syn's AyyWare Framework 2015
*/
// Credits to Valve and Shad0w
#include "NetVars.h"
#include "ClientRecvProps.h"
#include "CRC32.h"
#include "Utilities.h"
#include "SDK.h"
CNetVar NetVar;
const char* AlignText(int align)
{
static char buffer[256];
int i = 0;
for (i = 0; i < align; i++)
{
buffer[i] = ' ';
}
buffer[i + 1] = 0;
return buffer;
}
void CNetVar::RetrieveClasses()
{
Utilities::EnableLogFile(NETVAR_FILENAME);
ClientClass *clientClass = Interfaces::Client->GetAllClasses();
if (!clientClass)
return;
//Clear netvar vector incase of another call, not necesarry as it doesnt add duplicates
vars.clear();
while (clientClass != 0)
{
if (clientClass == 0)
break;
LogNetVar(clientClass->m_pRecvTable, 0);
clientClass = clientClass->m_pNext;
}
}
void CNetVar::LogNetVar(RecvTable *table, int align)
{
if (table->m_nProps < 0)
return;
if (align)
Utilities::Log("%s===%s===", AlignText(20 + align), table->m_pNetTableName);
else
Utilities::Log(table->m_pNetTableName);
for (auto i = 0; i < table->m_nProps; ++i)
{
RecvProp *prop = &table->m_pProps[i];
if (!prop)
continue;
char szCRC32[150];
sprintf_s(szCRC32, "%s%s", table->m_pNetTableName, prop->m_pVarName);
DWORD_PTR dwCRC32 = CRC32((void*)szCRC32, strlen(szCRC32));
Utilities::Log("%s%s [0x%X] [CRC32::0x%X]", AlignText(15 + align), prop->m_pVarName, prop->m_Offset, dwCRC32);
//Dont add duplicates
bool bAddNetVar = true;
for (auto netvar = 0; netvar < (int)vars.size(); ++netvar)
{
netvar_info_s *netvars = &vars[netvar];
if (netvars->dwCRC32 == dwCRC32)
bAddNetVar = false;
if (netvars->dwCRC32 == dwCRC32 && netvars->dwOffset != prop->m_Offset) //just a test if any crc collide with another (didnt happen obviously)
{
Utilities::Log("^^^^ ERROR HASH %s%s::%s [0x%X] [CRC32::0x%X] ^^^^", AlignText(15 + align), table->m_pNetTableName, prop->m_pVarName, prop->m_Offset, dwCRC32);
Utilities::Log("^^^^ CONFLICT %s%s::%s [0x%X] [CRC32::0x%X] ^^^^", AlignText(15 + align), netvars->szTableName, netvars->szPropName, netvars->dwOffset, netvars->dwCRC32);
}
}
if (bAddNetVar) //avoid adding duplicates (faster lookup)
{
netvar_info_s tmp;
strcpy_s(tmp.szTableName, table->m_pNetTableName);
strcpy_s(tmp.szPropName, prop->m_pVarName);
tmp.dwCRC32 = dwCRC32;
tmp.dwOffset = prop->m_Offset;
vars.push_back(tmp);
}
if (prop->m_pDataTable)
LogNetVar(prop->m_pDataTable, 5);
}
}
DWORD_PTR CNetVar::GetNetVar(DWORD_PTR dwCRC32) //returns 0xFFFFFFFF (-1) if not found (ex: if(GetNetVar(0xD34DB33F)==-1) return false;
{
for (auto i = 0; i < (int)vars.size(); ++i)
{
if (vars[i].dwCRC32 == dwCRC32)
return vars[i].dwOffset;
}
return 0xFFFFFFFF;
}