-
Notifications
You must be signed in to change notification settings - Fork 2
/
prop_manager.cpp
196 lines (151 loc) · 4.29 KB
/
prop_manager.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include "prop_manager.hpp"
#include "source.hpp"
#include <iomanip>
namespace Engine
{
PropManager::~PropManager()
{
this->Destroy();
}
bool PropManager::Create(IBaseClientDLL* client)
{
if (!client)
{
#ifdef DEBUG
Win32::Error("IBaseClientDLL is nullptr (PropManager::%s)", __FUNCTION__);
#endif // DEBUG
return false;
}
auto entry = client->GetAllClasses();
if (!entry)
{
#ifdef DEBUG
Win32::Error("ClientClass is nullptr (PropManager::%s)", __FUNCTION__);
#endif // DEBUG
return false;
}
while (entry)
{
auto table = entry->m_pRecvTable;
if (table)
this->m_pTables.emplace_back(table);
entry = entry->m_pNext;
}
if (this->m_pTables.empty())
{
#ifdef DEBUG
Win32::Error("std::vector<RecvTable*> is empty (PropManager::%s)", __FUNCTION__);
#endif // DEBUG
return false;
}
return true;
}
void PropManager::Destroy()
{
this->m_pTables.clear();
}
int PropManager::GetOffset(const std::string& table_name, const std::string& prop_name)
{
auto offst = (this->GetProp(table_name, prop_name));
if (!offst)
{
#ifndef AUTH
Win32::Warning("Prop '%s::%s' not found (PropManager::%s)", table_name.c_str(), prop_name.c_str(), __FUNCTION__);
#endif // !AUTH
return 0;//Win32::Warning("Prop '%s::%s' not found (PropManager::%s)", table_name.c_str(), prop_name.c_str(), __FUNCTION__);
}
return offst;
}
RecvVarProxyFn PropManager::Hook(const RecvVarProxyFn hooked, const std::string& table_name, const std::string& prop_name)
{
RecvProp* prop = nullptr;
if (!GetProp(table_name, prop_name, &prop))
{
#ifndef AUTH
Win32::Warning("Prop '%s::%s' not found (PropManager::%s)", table_name.c_str(), prop_name.c_str(), __FUNCTION__);
#endif // !AUTH
//Win32::Warning("Prop '%s::%s' not found (PropManager::%s)", table_name.c_str(), prop_name.c_str(), __FUNCTION__);
return nullptr;
}
auto restore = prop->m_ProxyFn;
prop->m_ProxyFn = hooked;
return restore;
}
int PropManager::GetProp(const std::string& table_name, const std::string& prop_name, RecvProp** out_prop /*= nullptr */)
{
return (this->GetProp(this->GetTable(table_name), prop_name, out_prop));
}
int PropManager::GetProp(RecvTable* table, const std::string& prop_name, RecvProp** out_prop /*= nullptr */)
{
int extra = 0;
if (!table)
return 0;
for (int i = 0; i < table->m_nProps; i++)
{
auto prop = &table->m_pProps[i];
auto child = prop->m_pDataTable;
if (child && child->m_nProps)
{
int add = GetProp(child, prop_name, out_prop);
if (add)
extra += (prop->m_Offset + add);
}
if (prop_name.compare(prop->m_pVarName) == 0)
{
if (out_prop)
* out_prop = prop;
return (prop->m_Offset + extra);
}
}
return extra;
}
RecvTable* PropManager::GetTable(const std::string& name)
{
if (!this->m_pTables.empty())
{
for (auto& table : m_pTables)
{
if (name.compare(table->m_pNetTableName) == 0)
return table;
}
}
#ifndef AUTH
Win32::Warning("Prop table '%s' not found (PropManager::%s)", name.c_str(), __FUNCTION__);
#endif // !AUTH
// Win32::Warning("Prop table '%s' not found (PropManager::%s)", name.c_str(), __FUNCTION__);
return nullptr;
}
void PropManager::DumpTable(RecvTable* table, int depth)
{
std::string pre("");
for (int i = 0; i < depth; i++)
pre.append("\t");
m_file << 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(sxor("baseclass")) == 0 || varName.find("0") == 0 || varName.find("1") == 0 || varName.find("2") == 0)
continue;
m_file << pre << "\t " << varName << " "
<< std::setfill('_') << std::setw(60 - varName.length() - (depth * 4))
<< "[0x" << std::setfill('0') << std::setw(8) << std::hex
<< std::uppercase << prop->m_Offset << "]\n";
if (prop->m_pDataTable)
DumpTable(prop->m_pDataTable, depth + 1);
}
}
void PropManager::DumpProps()
{
//m_file.open("C:/sause/csgo.txt");
//m_file << ("NetVars From Source Engined paste\n\n");
//m_file << ("aye \n\n");
for (ClientClass* pClass = csgo.m_client()->GetAllClasses(); pClass != NULL; pClass = pClass->m_pNext)
{
RecvTable* table = pClass->m_pRecvTable;
DumpTable(table, 0);
}
m_file.close();
}
}