-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatures.cpp
More file actions
281 lines (229 loc) · 8.81 KB
/
Copy pathfeatures.cpp
File metadata and controls
281 lines (229 loc) · 8.81 KB
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
#include <cmath>
#include <iostream>
#include "features.hpp"
#include "config.hpp" // to access config variables
#include "structs.hpp"
#include "tramp.hpp"
namespace mem
{
void Patch(BYTE* dst, BYTE* src, unsigned int size)
{
DWORD oldprotect;
// 1. Change to RWX (Read, Write, Execute)
VirtualProtect(dst, size, PAGE_EXECUTE_READWRITE, &oldprotect);
// 2. Perform the copy
memcpy(dst, src, size);
// 3. Restore original protection
VirtualProtect(dst, size, oldprotect, &oldprotect);
}
void Nop(BYTE* dst, unsigned int size)
{
DWORD oldprotect;
VirtualProtect(dst, size, PAGE_EXECUTE_READWRITE, &oldprotect);
// Fill the memory with 0x90 (NOP)
memset(dst, 0x90, size);
VirtualProtect(dst, size, oldprotect, &oldprotect);
}
}
inline bool is_in_team_mode()
{
const std::uint8_t game_type = *reinterpret_cast<std::uint8_t*>(features::offsets::game_mode);
return !(game_type
&& game_type != 4
&& game_type != 5
&& game_type != 7
&& game_type != 11
&& game_type != 13
&& game_type != 14
&& game_type != 16
&& game_type != 17
&& game_type != 20
&& game_type != 21);
}
inline std::size_t get_player_count()
{
uintptr_t module_base = (uintptr_t)GetModuleHandle(nullptr);
const auto players = *reinterpret_cast<std::size_t*>(module_base + features::offsets::num_players);
return players < 1 || players > 32 ? 0 : players - 1;
}
entity* get_closest_enemy()
{
uintptr_t base = (uintptr_t)GetModuleHandle(nullptr);
entity* closest_entity = nullptr;
entity* local_player = *(entity**)(base + features::offsets::localPlayer);
vec3 local_pos = local_player->head_pos;
auto closest_dist = 1000000.0f;
for (size_t i = 0; i < get_player_count(); i++)
{
const auto current_player = (*reinterpret_cast<entity_list**>(features::offsets::entityList))->entities[i];
printf("current player: %p\n", current_player);
if (current_player->health <= 0 || is_in_team_mode() && current_player->team == local_player->team)
continue;
const auto cur_player_pos = current_player->head_pos;
const auto dist = (local_pos - cur_player_pos).magnitude();
printf("distance to player %d: %f\n", i, dist);
if (closest_dist > dist)
{
closest_dist = dist;
closest_entity = current_player;
}
}
return closest_entity;
}
entity* get_closest_player()
{
uintptr_t base = (uintptr_t)GetModuleHandle(nullptr);
entity* closest_entity = nullptr;
entity* local_player = *(entity**)(base + features::offsets::localPlayer);
vec3 local_pos = local_player->head_pos;
auto closest_dist = 1000000.0f;
for (size_t i = 0; i < get_player_count(); i++)
{
const auto current_player = (*reinterpret_cast<entity_list**>(features::offsets::entityList))->entities[i];
printf("current player: %p\n", current_player);
if (current_player->health <= 0)
continue;
const auto cur_player_pos = current_player->head_pos;
const auto dist = (local_pos - cur_player_pos).magnitude();
printf("distance to player %d: %f\n", i, dist);
if (closest_dist > dist)
{
closest_dist = dist;
closest_entity = current_player;
}
}
return closest_entity;
}
void __stdcall ApplySilentAimLogic(uintptr_t dest_ptr) {
if (!config.b_aimbot) return;
entity* target = config.b_target_teammates ? get_closest_player() : get_closest_enemy();
if (target) {
vec3* bullet_dst = reinterpret_cast<vec3*>(dest_ptr);
bullet_dst->x = target->head_pos.x;
bullet_dst->y = target->head_pos.y;
bullet_dst->z = target->head_pos.z;
}
}
static bool silent_aim_setup = false;
static uint32_t firing_gateway = 0;
void __declspec(naked) silent_aim_handler() {
__asm {
// 1. Grab the destination vector pointer from the stack [esp + 0x3C]
mov eax, [esp + 0x3C]
// 2. Save everything
pushad
// 3. Push EAX (the pointer) as an argument for our C++ function
push eax
call ApplySilentAimLogic
// 4. Restore everything
popad
// 5. Jump back to the game
jmp [firing_gateway]
}
}
void features::execute()
{
uintptr_t module_base = (uintptr_t)GetModuleHandle(nullptr);
uintptr_t localPlayerPtr = (module_base + offsets::localPlayer);
if (!localPlayerPtr) return;
uintptr_t localPlayer = *(uintptr_t*)localPlayerPtr;
if (!localPlayer) return;
// God Mode Logic
if (config.b_god_mode)
{
entity* player = (entity*)localPlayer;
//int* health = (int*)(localPlayer + offsets::health); // offset for health
if (player->health > 0)
{
//*health = config.god_mode_health; // set health to a high value
player->health = config.god_mode_health;
}
}
//eventually im just gonna nop out the part that decrease ammo but this is cool cause you can set custom ammo count
if (config.b_inf_ammo)
{
entity* local_player = (entity*)localPlayer;
//sets all ammo types to the inf_ammo_amount specified
local_player->pistol_ammo = config.inf_ammo_amount;
local_player->carbine_ammo = config.inf_ammo_amount;
local_player->shotgun_ammo = config.inf_ammo_amount;
local_player->machinegun_ammo = config.inf_ammo_amount;
local_player->sniper_ammo = config.inf_ammo_amount;
local_player->rifle_ammo = config.inf_ammo_amount;
}
if (config.b_inf_grenades)
{
entity* local_player = (entity*)localPlayer;
local_player->grenade_count = config.inf_ammo_amount;
}
if (config.b_rapid_grenades)
{
entity* local_player = (entity*)localPlayer;
local_player->grenade_cooldown = 0; // set grenade cooldown to 0 to allow rapid throwing
}
if (config.b_rapid_knife)
{
entity* local_player = (entity*)localPlayer;
local_player->knife_cooldown = 0;
}
// Aimbot Logic
if (config.b_aimbot && !silent_aim_setup)
{
uintptr_t base = (uintptr_t)GetModuleHandle(nullptr);
uintptr_t hook_location = base + features::offsets::silent_aim_hook_location;
firing_gateway = tramp_hook(hook_location, (uintptr_t)silent_aim_handler, 3);
silent_aim_setup = true;
}
static bool recoil_patched = false;
// Original bytes for restoration
BYTE orig_vertical[] = { 0xF3, 0x0F, 0x5D, 0xD0 }; // 0xC8E4E
BYTE orig_velocity_x[] = { 0xF3, 0x0F, 0x58, 0x40, 0x10 }; // 0xC8DCD (+10)
BYTE orig_velocity_y[] = { 0xF3, 0x0F, 0x58, 0x40, 0x14 }; // 0xC8DF1 (+14)
BYTE orig_velocity_z[] = { 0xF3, 0x0F, 0x58, 0x48, 0x18 }; // 0xC8DF6 (+18)
if (config.b_norecoil && !recoil_patched)
{
// Vertical Visual Recoil (The Climb)
BYTE xor_xmm2[] = { 0x0F, 0x57, 0xD2 };
mem::Patch((BYTE*)(module_base + 0xC8E4E), xor_xmm2, 3);
mem::Nop((BYTE*)(module_base + 0xC8E51), 1);
// Physical Kick (The Push)
// NOP all three axes to ensure NO movement is added when firing
mem::Nop((BYTE*)(module_base + 0xC8DCD), 5); // Kill X-Push (+10)
mem::Nop((BYTE*)(module_base + 0xC8DF1), 5); // Kill Y-Push (+14)
mem::Nop((BYTE*)(module_base + 0xC8DF6), 5); // Kill Z-Push (+18)
recoil_patched = true;
}
else if (!config.b_norecoil && recoil_patched)
{
// RESTORE
mem::Patch((BYTE*)(module_base + 0xC8E4E), orig_vertical, 4);
mem::Patch((BYTE*)(module_base + 0xC8DCD), orig_velocity_x, 5);
mem::Patch((BYTE*)(module_base + 0xC8DF1), orig_velocity_y, 5);
mem::Patch((BYTE*)(module_base + 0xC8DF6), orig_velocity_z, 5);
recoil_patched = false;
}
static bool rapid_fire_patched = false;
uintptr_t rapidfire_offset = module_base + offsets::rapidfire;
if (config.b_rapid_fire && !rapid_fire_patched)
{
mem::Nop((BYTE*)rapidfire_offset, 2); // nop the instruction at the rapid fire offset
rapid_fire_patched = true;
}
else if (!config.b_rapid_fire && rapid_fire_patched)
{
BYTE originalRapidFireBytes[2] = { 0x89, 0x08 }; // original bytes to restore
mem::Patch((BYTE*)rapidfire_offset, originalRapidFireBytes, 2); // restore the original bytes at the rapid fire offset
rapid_fire_patched = false;
}
if (config.b_speed_hack)
{
entity* player = (entity*)localPlayer;
if (player->accel.x != 0.f )
{
player->accel.x *= config.speed_difference;
}
if (player->accel.y != 0.f)
{
player->accel.y *= config.speed_difference;
}
}