-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathClasses.hpp
374 lines (300 loc) · 8.36 KB
/
Classes.hpp
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#pragma once
#include <Windows.h>
#include <string>
#include <vector>
#include <cstdint>
#include <d3dx10math.h>
#include "Vector.hpp"
#include "Offsets.hpp"
#include "Enums.hpp"
#include "Functions.hpp"
using namespace SDK;
std::pair<float, float> ScreenMetrics;
std::uintptr_t GameModule;
#define AFIELD_OFFSET(type, field) ((LONG)(LONG_PTR)&(((type *)0)->field))
inline auto IsValidPtr(void* const pointer) -> bool {
return (pointer && pointer > (void*)0xFFFFFF && pointer < (void*)0x7FFFFFFFFFFF);
}
namespace SDK
{
#define MAX_PLAYER_COUNT 128
#define MAX_ENTITY_COUNT 1024
void InitSDK()
{
ScreenMetrics = std::make_pair(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
GameModule = reinterpret_cast<std::uintptr_t>(GetModuleHandleA(nullptr));
}
template <typename TElement>
class cArray
{
public:
inline auto get_count() -> size_t
{
return this->_size;
}
inline auto get_max_size() -> size_t
{
return this->_maxsize;
}
inline auto get_buffer() -> TElement
{
return _buffer;
}
inline auto get_by_idx(int _index) -> TElement
{
return _buffer[_index];
}
private:
char pad_0x01[0x10];
size_t _size;
size_t _maxsize;
TElement _buffer[];
};
class cString
{
public:
inline auto ptr() -> bool
{
return IsValidPtr((void*)_pbuffer);
}
inline auto c_str() -> const char*
{
if (this->ptr())
return this->_pbuffer;
return this->_buffer;
}
inline auto to_str() -> std::string
{
if (this->ptr())
return std::string(this->_pbuffer);
return std::string(this->_buffer);
}
private:
union {
char* _pbuffer;
char _buffer[16];
};
};
class cGameRenderer
{
public:
auto GetRenderView() -> uintptr_t
{
return *reinterpret_cast<uintptr_t*>(reinterpret_cast<uintptr_t>(this) + offsets::RenderView);
}
static auto GetInstance(uintptr_t Base = GameModule) -> cGameRenderer*
{
return *reinterpret_cast<cGameRenderer**>(Base + offsets::GameRenderer);
}
};
class cHealthComponent
{
public:
auto GetHealth() -> float
{
return *reinterpret_cast<float*>(reinterpret_cast<uintptr_t>(this) + offsets::Health);
}
auto GetMaxHealth() -> float
{
return *reinterpret_cast<float*>(reinterpret_cast<uintptr_t>(this) + offsets::MaxHealth);
}
};
class cWeapon
{
public:
auto GetName() -> cString
{
return *reinterpret_cast<cString*>(reinterpret_cast<uintptr_t>(this) + offsets::WeaponName);
}
};
class cActiveWeapon
{
public:
auto GetWeapon() -> cWeapon*
{
return *reinterpret_cast<cWeapon**>(reinterpret_cast<uintptr_t>(this) + offsets::Weapon);
}
auto GetActiveSlot() -> int
{
return *reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(this) + offsets::ActiveSlot);
}
};
class cWeaponComponent
{
public:
auto GetWeapons() -> cArray<cWeapon*>*
{
return *reinterpret_cast<cArray<cWeapon*>**>(reinterpret_cast<uintptr_t>(this) + offsets::WeaponArray);
}
auto GetActiveWeapon() -> cActiveWeapon*
{
return *reinterpret_cast<cActiveWeapon**>(reinterpret_cast<uintptr_t>(this) + offsets::ActiveWeapon);
}
};
class cClEntity
{
public:
auto GetTransformInternal(D3DMATRIX* Transform)
{
return functions::VirtualCall<offsets::GetTransform, void>(this, Transform);
}
auto GetTransformAABBInternal(D3DMATRIX* Transform)
{
return functions::VirtualCall<offsets::GetTransformAABB, void>(this, Transform);
}
};
class cSoldierEntity : public cClEntity
{
public:
auto GetPosition() -> utils::maths::vec3_t
{
return *reinterpret_cast<utils::maths::vec3_t*>(reinterpret_cast<uintptr_t>(this) + offsets::RootPosition);
}
auto GetHealthComponent() -> cHealthComponent*
{
return *reinterpret_cast<cHealthComponent**>(reinterpret_cast<uintptr_t>(this) + offsets::HealthComponent);
}
auto GetWeaponComponent() -> cWeaponComponent*
{
return *reinterpret_cast<cWeaponComponent**>(reinterpret_cast<uintptr_t>(this) + offsets::WeaponComponent);
}
auto GetActiveWeaponName() -> const char*
{
const auto WeaponComponent = this->GetWeaponComponent();
if (!IsValidPtr((void*)WeaponComponent))
return nullptr;
const auto ActiveWeapon = WeaponComponent->GetActiveWeapon();
if (!IsValidPtr((void*)ActiveWeapon))
return nullptr;
const auto Weapon = ActiveWeapon->GetWeapon();
if (!IsValidPtr((void*)Weapon))
return nullptr;
const auto WeaponName = Weapon->GetName().c_str();
if (!IsValidPtr((void*)WeaponName))
return nullptr;
return WeaponName;
}
auto IsVisible() -> bool
{
return !*reinterpret_cast<bool*>(reinterpret_cast<uintptr_t>(this) + offsets::IsHidden);
}
auto GetYawAngle() -> float
{
return *reinterpret_cast<float*>(reinterpret_cast<uintptr_t>(this) + offsets::YawAngle);
}
};
class cClientEntity
{
public:
};
class cClientPlayer : public cClientEntity
{
public:
auto GetName() -> cString
{
return *reinterpret_cast<cString*>(reinterpret_cast<uintptr_t>(this) + offsets::PlayerName);
}
auto GetTeamId() -> int
{
return *reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(this) + offsets::PlayerTeamId);
}
auto GetSoldierEntity() -> cSoldierEntity*
{
return *reinterpret_cast<cSoldierEntity**>(reinterpret_cast<uintptr_t>(this) + offsets::PlayerSoldierEntity);
}
};
class cVehicleData
{
public:
auto GetNameSid() -> cString
{
return *reinterpret_cast<cString*>(reinterpret_cast<uintptr_t>(this) + offsets::VehicleNameSid);
}
};
class cVehicleEntity : public cClEntity
{
public:
auto GetPosition(utils::maths::vec3_t* Position, bool Internal = true) -> bool
{
D3DMATRIX Transform{};
if (!Internal)
{
auto pCollection =
*reinterpret_cast<uintptr_t*>(reinterpret_cast<uintptr_t>(this) + offsets::TransformCollection);
if (!IsValidPtr((void*)pCollection))
return false;
int8_t _9 = *reinterpret_cast<int8_t*>(pCollection + 9);
int8_t _10 = *reinterpret_cast<int8_t*>(pCollection + 10);
uintptr_t ComponentCollectionOffset = 0x20 * (_9 + (2 * _10));
Transform = *reinterpret_cast<D3DMATRIX*>(pCollection + ComponentCollectionOffset + 0x10);
}
else
{
this->GetTransformAABBInternal(&Transform);
}
*Position = functions::ExtractPos(Transform);
return true;
}
auto GetVehicleData() -> cVehicleData*
{
return *reinterpret_cast<cVehicleData**>(reinterpret_cast<uintptr_t>(this) + offsets::VehicleData);
}
};
class cClientVehicle : public cClientEntity
{
public:
auto GetVehicleEntity() -> cVehicleEntity*
{
return *reinterpret_cast<cVehicleEntity**>(reinterpret_cast<uintptr_t>(this) + offsets::VehicleEntity);
}
};
class cLocalPlayer : public cClientPlayer
{
public:
};
class cClientPlayerMgr
{
public:
auto GetLocalPlayerArray() -> uintptr_t*
{
return *reinterpret_cast<uintptr_t**>(reinterpret_cast<uintptr_t>(this) + offsets::LocalPlayerArray);
}
auto GetClientPlayersArray() -> cArray<cClientEntity*>*
{
return *reinterpret_cast<cArray<cClientEntity*>**>(reinterpret_cast<uintptr_t>(this) + offsets::ClientPlayerArray);
}
auto GetLocalPlayer() -> cLocalPlayer*
{
auto lpArray = this->GetLocalPlayerArray();
if (!IsValidPtr((void*)lpArray))
return nullptr;
return (cLocalPlayer*)lpArray[0];
}
auto GetAllClientPlayers(cArray<cClientEntity*>* const clpArray, cLocalPlayer* const lPlayer) -> std::vector<cClientEntity*>
{
std::vector<cClientEntity*> clBuffer;
for (int i = 0; i < MAX_PLAYER_COUNT; i++)
{
const auto ClientPlayer = clpArray->get_by_idx(i);
if (!IsValidPtr((void*)ClientPlayer))
continue;
if ((uintptr_t)ClientPlayer == (uintptr_t)lPlayer)
continue;
clBuffer.push_back(ClientPlayer);
}
return clBuffer;
}
};
class cGameContext
{
public:
auto GetClientPlayerMgr() -> cClientPlayerMgr*
{
return *reinterpret_cast<cClientPlayerMgr**>(reinterpret_cast<uintptr_t>(this) + offsets::ClientPlayerManager);
}
static auto GetInstance(uintptr_t Base = GameModule) -> cGameContext*
{
return *reinterpret_cast<cGameContext**>(Base + offsets::GameContext);
}
};
}