-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMemoryManager.cpp
More file actions
542 lines (487 loc) · 19.3 KB
/
MemoryManager.cpp
File metadata and controls
542 lines (487 loc) · 19.3 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
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
#include <windows.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <thread>
#include <chrono>
#include <atomic>
#include "uevr/API.hpp"
#include "MemoryManager.h"
#include "WeaponManager.h"
DWORD PID;
std::vector<MemoryBlock> matrixInstructionsRotationAddresses = {
{0x111DE7E, 7, 0xf30f118b300800},
{0x111DE85, 1, 0x00},
{0x111DECC, 7, 0xf30f118b340800},
{0x111DED3, 1, 0x00},
{0x111DED9, 7, 0xf30f11b3380800},
{0x111DEE0, 1, 0x00},
{0x111DE5C, 7, 0xf3440f11834008},
{0x111DE63, 1, 0x00},
{0x111DE64, 1, 0x00},
{0x111DE3B, 7, 0xf30f11b3440800},
{0x111DE42, 1, 0x00},
{0x111DE68, 7, 0xf30f11bb480800},
{0x111DE6F, 1, 0x00},
{0x111DE75, 7, 0xf3440f11a35008},
{0x111DE7C, 1, 0x00},
{0x111DE7D, 1, 0x00},
{0x111DE8F, 7, 0xf3440f118b5408},
{0x111DE96, 1, 0x00},
{0x111DE97, 1, 0x00},
{0x111DE98, 7, 0xf3440f119b5808},
{0x111DE9F, 1, 0x00},
{0x111DEA0, 1, 0x00}
};
std::vector<MemoryBlock> matrixInstructionsPositionAddresses = {
{0x111DEA5, 7, 0xf3440f11b36008},
{0x111DEAC, 1, 0x00},
{0x111DEAD, 1, 0x00},
{0x111DF57, 7, 0xf30f1183600800},
{0x111DF5E, 1, 0x00},
{0x111DEB3, 7, 0xf30f1183640800},
{0x111DEBA, 1, 0x00},
{0x111DF72, 7, 0xf30f1183640800},
{0x111DF79, 1, 0x00},
{0x111DEBE, 7, 0xf3440f11bb6808},
{0x111DEC5, 1, 0x00},
{0x111DEC6, 1, 0x00},
{0x111DF8D, 7, 0xf30f1183680800},
{0x111DF94, 1, 0x00},
};
std::vector<MemoryBlock> ingameCameraPositionInstructionsAddresses = {
{0x1109F20, 3, 0xf20f11},
{0x1109F23, 1, 0x06},
{0x1109F96, 3, 0xf30f11},
{0x1109F99, 1, 0x06},
{0x110A28E, 3, 0xf30f11},
{0x110A291, 1, 0x06},
{0x11255AB, 3, 0xf30f11},
{0x11255AE, 1, 0x03},
{0x11070E2, 3, 0xf30f11},
{0x11070E5, 1, 0x03},
{0x110A3BD, 3, 0xf30f11},
{0x110A3C0, 1, 0x06},
{0x11080C6, 7, 0xf20f1106894608},
{0x1109F24, 3, 0x894608},
{0x1109FBC, 5, 0xf30f114608},
{0x110A252, 5, 0xf3440f1146},
{0x110A257, 1, 0x08},
{0x110A2C0, 5, 0xf30f114608},
{0x11255B4, 5, 0xf30f114b08},
{0x11070FF, 5, 0xf30f114308},
{0x110A3DD, 5, 0xf30f114608},
{0x1108165, 5, 0xf3440f115e},
{0x110816A, 1, 0x08},
{0x1109FA4, 5, 0xf30f114604},
{0x110A29C, 5, 0xf30f114604},
{0x11255B3, 5, 0x04f30f114b},
{0x11070F0, 5, 0xf30f114304},
{0x110A3CB, 5, 0xf30f114604},
{0x110D0BC, 3, 0xf20f11},
{0x110D0BF, 1, 0x03},
};
std::vector<MemoryBlock> ingameCameraPositionSniperAndCamWpnInstructionsAddresses = {
{0x110E06D, 3, 0xf30f11},
{0x110E070, 1, 0x03},
{0x110E018, 7, 0xf30f11871c0100},
{0x110E01F, 1, 0x00},
{0x110E3F2, 3, 0xf30f11},
{0x110E3F5, 1, 0x03},
{0x110E1F2, 3, 0xf30f11},
{0x110E1F5, 1, 0x33},
{0x110E0B2, 7, 0xf30f11871c0100},
{0x110E0B9, 1, 0x00},
{0x110E0D2, 7, 0xf30f1187200100},
{0x110E0D9, 1, 0x00},
{0x110e20c, 5, 0xf30f117b04},
{0x110e3ff, 5, 0xf30f114304},
{0x110dfc4, 3, 0x894b08},
{0x110dfdb, 7, 0xf30f1187240100},
{0x110dfe2, 1, 0x00},
{0x110e21d, 5, 0xf3440f1143},
{0x110e222, 1, 0x08},
{0x110e40d, 5, 0xf30f114308},
{0x110e045, 7, 0xf30f1187200100},
{0x110e04c, 1, 0x00},
{0x110dfc0, 3, 0xf20f11},
{0x110dfc3, 1, 0x03},
};
std::vector<MemoryBlock> pitchAxisAimingInstructionsAddresses = {
{0x11077c9, 3, 0xf30f11},
{0x11077cc, 1, 0x07},
{0x1107c9b, 5, 0xf3440f110f},
{0x1109dce, 3, 0xf30f11},
{0x1109dd1, 1, 0x33},
{0x1109e1c, 3, 0xf30f11},
{0x1109e1f, 1, 0x0b},
{0x110d8ad, 5, 0xf3440f1117},
{0x1108dbd, 3, 0x448933},
{0x1108e23, 3, 0xf30f11},
{0x1108e26, 1, 0x03},
{0x110903f, 3, 0xf30f11},
{0x1109042, 1, 0x03},
};
std::vector<MemoryBlock> aimingForwardVectorInstructionsAddresses = {
{0x11090E8, 5, 0xf2410f1107},
//{0xAE0410, 5, 0xf3440f1101}, //cause aggressive spawning velocity of cars
{0x1109EA5, 5, 0xf2410f1107},
{0x1105AAC, 7, 0xf20f1189100100},
{0x1105AB3, 1, 0x00},
{0x1107E3B, 7, 0xf20f1187100100},
{0x1107E42, 1, 0x00},
{0x1108E75, 5, 0xf2410f1107},
//{0xAE0406, 5, 0xf30f117104}, //cause aggressive spawning velocity of cars
{0x11090ED, 3, 0x418947},
{0x11090F0, 1, 0x08},
//{0xAE040B, 5, 0xf30f117908}, //cause aggressive spawning velocity of cars
{0x1109EAA, 3, 0x418947},
{0x1109EAD, 1, 0x08},
{0x1105AC9, 5, 0x8981180100},
{0x1105ACE, 1, 0x00},
{0x1107E43, 5, 0x8987180100},
{0x1107E48, 1, 0x00},
{0x1108E7A, 3, 0x418947},
{0x1108E7D, 1, 0x08},
//Cause extinguisher, spraycan, flamethrower up and down aiming issues
//{0x1105A60, 7, 0xc741180000F041},
//{0x1108D75, 7, 0xc7431800007a44},
//{0x1105A4F, 3, 0x668941},
//{0x1105A52, 1, 0x28},
//{0x11202A4, 7, 0x6689ac38b00100},
//{0x11202AB, 1, 0x00},
//{0x11205DB, 7, 0x6689ac38b00100},
//{0x11205E2, 1, 0x00},
{0x11077C9, 3, 0xf30f11},
{0x11077CC, 1, 0x07},
{0x1107C9B, 5, 0xf3440f110f},
{0x110D0F2, 5, 0xf2410f1101}
};
std::vector<MemoryBlock> aimingUpVectorInstructionsAddresses = {
{0x1105840, 5, 0xf20f118134},
{0x1105845, 3, 0x010000},
{0x1105A00, 5, 0xf20f118234},
{0x1105A05, 3, 0x010000},
{0x1105854, 5, 0x89813c0100},
{0x1105859, 1, 0x00},
{0x1105A08, 5, 0x89823c0100},
{0x1105A0D, 1, 0x00},
};
std::vector<MemoryBlock> rocketLauncherAimingVectorInstructionsAddresses = {
{0x110E71D, 5, 0x8987180100},
{0x110E722, 1, 0x00},
{0x110E70B, 7, 0xf20f1187100100},
{0x110E712, 1, 0x00}
};
std::vector<MemoryBlock> sniperAimingVectorInstructionsAddresses = {
{0x110E19E, 5, 0x8987180100},
{0x110E1A3, 1, 0x00},
{0x110E196, 7, 0xf20f1187100100},
{0x110E19D, 1, 0x00}
};
std::vector<MemoryBlock> carAimingVectorInstructionsAddresses = {
{0x110BB78, 3, 0x418945},
{0x110BB7B, 1, 0x08},
{0x110C5A4, 3, 0x418945},
{0x110C5A7, 1, 0x08},
{0x110C59E, 5, 0xf2410f1145},
{0x110C5A3, 1, 0x00},
{0x110BB68, 5, 0xf2410f114d},
{0x110BB6D, 1, 0x00},
{0x110CE81, 3, 0x894208},
{0x110CE7A, 3, 0xf20f11},
{0x110CE7D, 1, 0x02}
};
uintptr_t MemoryManager::playerShootInstructionAddress = 0x11C6A7E;
uintptr_t MemoryManager::playerShootCam45InstructionAddress = 0x112D6F0; //
//uintptr_t MemoryManager::cameraShootInstructionAddress = 0x13F4000; // Take photo function address;
bool MemoryManager::FirstWeaponIsShooting = false;
std::array<uintptr_t, 16> MemoryManager::cameraMatrixAddresses{}; // x, y, z
// Struct for each breakpoint
struct BreakpointInfo {
void* address;
bool* flag; // Pointer to the boolean variable to update
};
// Global breakpoints
BreakpointInfo breakpoints[4]; // DR0, DR1, DR2, DR3, only DR0 is used in this plugin
bool MemoryManager::SetHardwareBreakpoint(HANDLE hThread, int index, void* address, bool* flag) {
if (index < 0 || index > 3) return false; // DR0-DR3 are valid
CONTEXT ctx = { 0 };
ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
if (!GetThreadContext(hThread, &ctx)) return false;
// Assign the correct debug register (DR0 - DR3)
switch (index) {
case 0: ctx.Dr0 = (DWORD64)address; break;
case 1: ctx.Dr1 = (DWORD64)address; break;
case 2: ctx.Dr2 = (DWORD64)address; break;
case 3: ctx.Dr3 = (DWORD64)address; break;
default: return false;
}
// Enable the corresponding debug control bits
ctx.Dr7 |= (1ULL << (index * 2)); // Enable breakpoint (L0, L1, L2, L3)
if (!SetThreadContext(hThread, &ctx)) return false;
// Store the breakpoint information
breakpoints[index] = { address, flag };
return true;
}
LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS* pException) {
if (pException->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) {
uintptr_t instructionAddress = (uintptr_t)pException->ExceptionRecord->ExceptionAddress;
if (instructionAddress == MemoryManager::playerShootInstructionAddress || instructionAddress == MemoryManager::playerShootCam45InstructionAddress) {
MemoryManager::FirstWeaponIsShooting = true;
}
// Set Resume Flag (RF) to prevent infinite breakpoint triggering
pException->ContextRecord->EFlags |= (1 << 16); // Set RF bit in EFLAGS
// Move execution to the next instruction to avoid freezing
return EXCEPTION_CONTINUE_EXECUTION;
}
return EXCEPTION_CONTINUE_SEARCH; // Let other handlers process it if it's not our breakpoint
}
bool MemoryManager::breakpointsInstalled = false;
void MemoryManager::InstallBreakpoints() {
if (settingsManager->debugMod) uevr::API::get()->log_info("InstallBreakpoints()");
if (breakpointsInstalled)
return;
HANDLE hThread = GetCurrentThread();
// Set the breakpoints
SetHardwareBreakpoint(hThread, 0, (void*)MemoryManager::playerShootInstructionAddress, &MemoryManager::FirstWeaponIsShooting);
SetHardwareBreakpoint(hThread, 1, (void*)MemoryManager::playerShootCam45InstructionAddress, &MemoryManager::FirstWeaponIsShooting);
//SetHardwareBreakpoint(hThread, 1, (void*)MemoryManager::cameraShootInstructionAddress, &MemoryManager::isShooting);
// Install exception handler
exceptionHandlerHandle = AddVectoredExceptionHandler(1, ExceptionHandler);
breakpointsInstalled = true;
}
void MemoryManager::RemoveBreakpoints() {
if (settingsManager->debugMod) uevr::API::get()->log_info("RemoveBreakpoints()");
// Clear hardware breakpoints
CONTEXT ctx = { 0 };
ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
HANDLE hThread = GetCurrentThread(); // Only applies to current thread (set for all if needed)
GetThreadContext(hThread, &ctx);
// Remove breakpoints by clearing DR0, DR1, and their control bits
ctx.Dr0 = 0;
ctx.Dr1 = 0;
ctx.Dr7 &= ~(1 << 0); // Clear enable bit for DR0
ctx.Dr7 &= ~(1 << 2); // Clear enable bit for DR1
SetThreadContext(hThread, &ctx);
// Remove the exception handler
if (exceptionHandlerHandle) {
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
exceptionHandlerHandle = nullptr; // Prevent accidental double removal
}
breakpointsInstalled = false;
}
void MemoryManager::RemoveExceptionHandler() {
if (settingsManager->debugMod) uevr::API::get()->log_info("RemoveExceptionHandler()");
static PVOID handler = nullptr; // Store handler pointer globally
if (handler) {
RemoveVectoredExceptionHandler(handler);
handler = nullptr;
}
}
// Function to NOP a batch of addresses
void NopMemory(const std::vector<MemoryBlock>& memoryBlocks) {
for (const auto& [address, size, bytes] : memoryBlocks) {
DWORD oldProtect;
VirtualProtect((LPVOID)address, size, PAGE_EXECUTE_READWRITE, &oldProtect);
for (size_t i = 0; i < size; ++i) {
uintptr_t currentAddr = address + i;
*reinterpret_cast<uint8_t*>(currentAddr) = 0x90; // Write NOP
}
VirtualProtect((LPVOID)address, size, oldProtect, &oldProtect);
}
}
// Function to restore original bytes for a batch of addresses
void RestoreMemory(const std::vector<MemoryBlock>& memoryBlocks) {
for (const auto& block : memoryBlocks) {
DWORD oldProtect;
VirtualProtect((LPVOID)block.address, block.size, PAGE_EXECUTE_READWRITE, &oldProtect);
for (size_t i = 0; i < block.size; ++i) {
*reinterpret_cast<uint8_t*>(block.address + i) = block.bytes[i];
}
VirtualProtect((LPVOID)block.address, block.size, oldProtect, &oldProtect);
}
}
void MemoryManager::InitMemoryManager()
{
baseAddressGameEXE = GetModuleBaseAddress(nullptr);
AdjustAddresses();
}
uintptr_t MemoryManager::GetModuleBaseAddress(LPCTSTR moduleName) {
HMODULE hModule = GetModuleHandle(moduleName);
if (hModule == nullptr) {
//uevr::API::get()->log_info("Failed to get the base address of the module.");
return 0;
}
return reinterpret_cast<uintptr_t>(hModule);
}
void MemoryManager::AdjustAddresses() {
if (settingsManager->debugMod) uevr::API::get()->log_info("AdjustAddresses()");
MemoryManager::cameraMatrixAddresses = {
0x53E2C00, 0x53E2C04, 0x53E2C08, 0x53E2C0C,
0x53E2C10, 0x53E2C14, 0x53E2C18, 0x53E2C1C,
0x53E2C20, 0x53E2C24, 0x53E2C28, 0x53E2C2C,
0x53E2C30, 0x53E2C34, 0x53E2C38, 0x53E2C3C };
for (auto& [address, size, bytes] : matrixInstructionsRotationAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : matrixInstructionsPositionAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : ingameCameraPositionInstructionsAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : ingameCameraPositionSniperAndCamWpnInstructionsAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : aimingForwardVectorInstructionsAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : aimingUpVectorInstructionsAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : pitchAxisAimingInstructionsAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : rocketLauncherAimingVectorInstructionsAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : sniperAimingVectorInstructionsAddresses) { address += baseAddressGameEXE; }
for (auto& [address, size, bytes] : carAimingVectorInstructionsAddresses) { address += baseAddressGameEXE; }
for (auto& address : MemoryManager::cameraMatrixAddresses) address += baseAddressGameEXE;
for (auto& address : aimForwardVectorAddresses) address += baseAddressGameEXE;
for (auto& address : cameraPositionAddresses) address += baseAddressGameEXE;
for (auto& address : playerHeadPositionAddresses) address += baseAddressGameEXE;
for (auto& address : playerPositionAddresses) address += baseAddressGameEXE;
playerIsInControlAddress += baseAddressGameEXE;
playerIsInVehicleAddress += baseAddressGameEXE;
vehicleTypeAddress += baseAddressGameEXE;
weaponWheelDisplayedAddress += baseAddressGameEXE;
cameraModeAddress += baseAddressGameEXE;
vehicleCameraModeAddress += baseAddressGameEXE;
onFootCameraModeAddress += baseAddressGameEXE;
xAxisSpraysAimAddress += baseAddressGameEXE;
playerShootInstructionAddress += baseAddressGameEXE;
playerShootCam45InstructionAddress += baseAddressGameEXE;
//cameraShootInstructionAddress += baseAddressGameEXE;
playerShootFromCarInputAddress += baseAddressGameEXE;
/*cutscenePlayingAddress += baseAddressGameEXE;*/
}
void MemoryManager::NopVehicleRelatedMemoryInstructions()
{
if (settingsManager->debugMod) uevr::API::get()->log_info("NopVehicleRelatedMemoryInstructions()");
NopMemory(matrixInstructionsPositionAddresses);
NopMemory(ingameCameraPositionInstructionsAddresses);
NopMemory(ingameCameraPositionSniperAndCamWpnInstructionsAddresses);
NopMemory(pitchAxisAimingInstructionsAddresses);
NopMemory(aimingForwardVectorInstructionsAddresses);
NopMemory(aimingUpVectorInstructionsAddresses);
NopMemory(rocketLauncherAimingVectorInstructionsAddresses);
NopMemory(sniperAimingVectorInstructionsAddresses);
vehicleRelatedMemoryInstructionsNoped = true;
};
void MemoryManager::RestoreVehicleRelatedMemoryInstructions()
{
if (settingsManager->debugMod) uevr::API::get()->log_info("RestoreVehicleRelatedMemoryInstructions()");
RestoreMemory(matrixInstructionsPositionAddresses);
RestoreMemory(ingameCameraPositionInstructionsAddresses);
RestoreMemory(ingameCameraPositionSniperAndCamWpnInstructionsAddresses);
RestoreMemory(pitchAxisAimingInstructionsAddresses);
RestoreMemory(aimingForwardVectorInstructionsAddresses);
RestoreMemory(aimingUpVectorInstructionsAddresses);
RestoreMemory(rocketLauncherAimingVectorInstructionsAddresses);
RestoreMemory(sniperAimingVectorInstructionsAddresses);
vehicleRelatedMemoryInstructionsNoped = false;
}
void MemoryManager::ToggleHeliCanonCameraModMemoryInstructions(bool restoreInstructions)
{
if (!restoreInstructions)
{
NopMemory(matrixInstructionsRotationAddresses);
NopMemory(pitchAxisAimingInstructionsAddresses);
NopMemory(aimingForwardVectorInstructionsAddresses);
}
if (restoreInstructions)
{
RestoreMemory(matrixInstructionsRotationAddresses);
RestoreMemory(pitchAxisAimingInstructionsAddresses);
RestoreMemory(aimingForwardVectorInstructionsAddresses);
}
}
void MemoryManager::ToggleAllMemoryInstructions(bool restoreInstructions)
{
if (settingsManager->debugMod) uevr::API::get()->log_info("ToggleAllMemoryInstructions(enabled : %i )", restoreInstructions);
if (!restoreInstructions)
{
NopMemory(matrixInstructionsRotationAddresses);
NopMemory(matrixInstructionsPositionAddresses);
NopMemory(ingameCameraPositionInstructionsAddresses);
NopMemory(ingameCameraPositionSniperAndCamWpnInstructionsAddresses);
NopMemory(pitchAxisAimingInstructionsAddresses);
NopMemory(aimingForwardVectorInstructionsAddresses);
NopMemory(aimingUpVectorInstructionsAddresses);
NopMemory(rocketLauncherAimingVectorInstructionsAddresses);
NopMemory(sniperAimingVectorInstructionsAddresses);
NopMemory(carAimingVectorInstructionsAddresses);
}
if (restoreInstructions)
{
RestoreMemory(matrixInstructionsRotationAddresses);
RestoreMemory(matrixInstructionsPositionAddresses);
RestoreMemory(ingameCameraPositionInstructionsAddresses);
RestoreMemory(ingameCameraPositionSniperAndCamWpnInstructionsAddresses);
RestoreMemory(pitchAxisAimingInstructionsAddresses);
RestoreMemory(aimingForwardVectorInstructionsAddresses);
RestoreMemory(aimingUpVectorInstructionsAddresses);
RestoreMemory(rocketLauncherAimingVectorInstructionsAddresses);
RestoreMemory(sniperAimingVectorInstructionsAddresses);
RestoreMemory(carAimingVectorInstructionsAddresses);
}
vehicleRelatedMemoryInstructionsNoped = !restoreInstructions;
}
//Finds address from pointer offsets found in cheat engine
uintptr_t FindDMAAddy(uintptr_t baseAddress, const std::vector<unsigned int>& offsets) {
uintptr_t addr = baseAddress;
for (size_t i = 0; i < offsets.size(); ++i) {
if (addr == 0) {
// If at any point the address is invalid, return 0
uevr::API::get()->log_error("%s", "Cant find gunflash socket address");
return 0;
}
// Dereference the pointer
addr = *reinterpret_cast<uintptr_t*>(addr);
// Add the offset
addr += offsets[i];
}
return addr;
}
//Retrieves original bytes to manually set them as a variables in the code. std::vector<std::pair<uintptr_t, size_t>>
//void MemoryManager::GetAllBytes()
//{
// WriteBytesToIniFile("aimingUpVectorInstructionsAddresses",aimingUpVectorInstructionsAddresses);
//}
//void MemoryManager::WriteBytesToIniFile(const char* header, const std::vector<std::pair<uintptr_t, size_t>>& addresses) {
// // Open the file in append mode
// std::ofstream file("originalBytes.ini", std::ios::app);
// if (!file.is_open()) {
// std::cerr << "Failed to open file: originalBytes.ini\n";
// return;
// }
//
// // Write the header
// file << "[" << header << "]\n";
//
// for (const auto& [address, size] : addresses) {
// // Allocate a buffer to hold the bytes
// std::vector<uint8_t> bytes(size);
//
// // Read the bytes from memory
// if (ReadProcessMemory(GetCurrentProcess(), reinterpret_cast<LPVOID>(address + baseAddressGameEXE), bytes.data(), size, nullptr)) {
// // Write the address and size to the file
// file << "0x" << std::hex << address << ", " << size << ", 0x";
//
// // Write the bytes in contiguous hexadecimal format
// for (size_t i = 0; i < size; ++i) {
// file << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(bytes[i]);
// }
// file << "\n";
// } else {
// std::cerr << "Failed to read memory at address: 0x" << std::hex << address << "\n";
// }
// }
//
// file.close();
// std::cout << "Bytes appended to originalBytes.ini under header: " << header << "\n";
//}
//
// Print the original bytes
//void MemoryManager::PrintOriginalBytes() const {
// for (const auto& [offset, originalByte] : originalBytes) {
// std::cout << "Offset: 0x" << std::hex << offset
// << ", Value: 0x" << static_cast<int>(originalByte.value) << "\n";
// }
//}