Skip to content

Commit 8bc0b0e

Browse files
committed
added namespaces
1 parent 80dd782 commit 8bc0b0e

File tree

5 files changed

+172
-151
lines changed

5 files changed

+172
-151
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ project(memoria)
33

44
set(CMAKE_CXX_STANDARD 23)
55

6-
add_executable(memoria src/main.cpp src/memoria.h src/memoria.cpp)
6+
add_executable(memoria src/main.cpp src/memoria.h src/memoria.cpp src/offsets.h)

src/main.cpp

+12-20
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,34 @@
33
* Last offset update: 17.10.2022
44
*/
55

6-
76
#include <iostream>
87
#include <cmath>
8+
#include "offsets.h"
99
#include "memoria.h"
1010

11+
using namespace memoria;
1112

1213
int main() {
13-
14-
// define all offsets
15-
uintptr_t off_health = 0xEC;
16-
uintptr_t off_x = 0x04;
17-
uintptr_t off_y = 0x08;
18-
uintptr_t off_z = 0x0C;
19-
uintptr_t off_yaw = 0x34;
20-
uintptr_t off_pitch = 0x38;
21-
uintptr_t off_current_height = 0x50;
22-
uintptr_t off_height = 0x054;
23-
uintptr_t off_direction = 0x80;
24-
uintptr_t off_shots = 0x188;
14+
HANDLE pHandle = nullptr;
15+
while (pHandle == nullptr) {
16+
pHandle = GetProcessHandleByClass("SDL_app", PROCESS_ALL_ACCESS);
17+
}
2518

2619
// get base address
2720
char module_name[] = "client.dll"; // ac_client.exe also works?
2821
uintptr_t ac_client = GetModuleBaseAddress(_T(module_name), GetProcessIdByClass("SDL_app"));
29-
HANDLE pHandle = GetProcessHandleByClass("SDL_app", PROCESS_ALL_ACCESS);
3022

3123
// add playerent offset to base and read value at address
3224
uintptr_t add_playerent = ac_client + 0x18AC00;
3325
uintptr_t playerent = ReadInt(pHandle, add_playerent);
3426

3527
// calculate all addresses
36-
uintptr_t add_yaw = playerent + off_yaw;
37-
uintptr_t add_pitch = playerent + off_pitch;
38-
uintptr_t add_health = playerent + off_health;
39-
uintptr_t add_x = playerent + off_x;
40-
uintptr_t add_y = playerent + off_y;
41-
uintptr_t add_z = playerent + off_z;
28+
uintptr_t add_yaw = playerent + offsets::yaw;
29+
uintptr_t add_pitch = playerent + offsets::pitch;
30+
uintptr_t add_health = playerent + offsets::health;
31+
uintptr_t add_x = playerent + offsets::x;
32+
uintptr_t add_y = playerent + offsets::y;
33+
uintptr_t add_z = playerent + offsets::z;
4234

4335
int health;
4436
float x, y, z;

src/memoria.cpp

+110-110
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,127 @@
11
#include "memoria.h"
22

3-
// --- WINDOW HANDLE ---
4-
HWND GetWindowHandleByTitle(LPCSTR window_title) {
5-
HWND window_handle = FindWindowA(nullptr, window_title);
6-
return window_handle;
7-
}
8-
9-
HWND GetWindowHandleByClass(LPCSTR class_name) {
10-
HWND window_handle = FindWindowA(class_name, nullptr);
11-
return window_handle;
12-
}
13-
14-
// --- PROCESS ID ---
15-
DWORD GetProcessIdFromWindowHandle(HWND window_handle) {
16-
DWORD process_id;
17-
GetWindowThreadProcessId(window_handle, &process_id); // get the process id using window handle
18-
return process_id;
19-
}
20-
21-
DWORD GetProcessIdByTitle(LPCSTR window_title) {
22-
return GetProcessIdFromWindowHandle(GetWindowHandleByTitle(window_title));
23-
}
24-
25-
DWORD GetProcessIdByClass(LPCSTR class_name) {
26-
return GetProcessIdFromWindowHandle(GetWindowHandleByClass(class_name));
27-
}
28-
29-
// --- PROCESS HANDLE ---
30-
31-
HANDLE GetProcessHandleByProcessId(DWORD process_id, DWORD desired_access) {
32-
return OpenProcess(desired_access, FALSE, process_id);
33-
}
34-
35-
HANDLE GetProcessHandleByTitle(LPCSTR window_title, DWORD desired_access) {
36-
return GetProcessHandleByProcessId(GetProcessIdByTitle(window_title), desired_access);
37-
}
38-
39-
HANDLE GetProcessHandleByClass(LPCSTR class_name, DWORD desired_access) {
40-
return GetProcessHandleByProcessId(GetProcessIdByClass(class_name), desired_access);
41-
}
42-
43-
// BASE ADDRESS
44-
uintptr_t GetModuleBaseAddress(TCHAR* modName, DWORD processId) {
45-
46-
uintptr_t base_address = 0;
47-
48-
// takes snapshot of all loaded modules in process
49-
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId);
50-
51-
// check if snapshot is valid
52-
if (hSnap != INVALID_HANDLE_VALUE) {
53-
54-
// create struct that holds the module info while iterating
55-
MODULEENTRY32 moduleEntry;
56-
moduleEntry.dwSize = sizeof(moduleEntry);
57-
58-
// if a module exists in snapshot, get entry
59-
if (Module32First(hSnap, &moduleEntry)) { // select first entry
60-
do {
61-
if (_tcscmp(moduleEntry.szModule, modName)) { // check if current module name equals searched module
62-
base_address = (uintptr_t) moduleEntry.modBaseAddr;
63-
break;
64-
}
65-
}
66-
while (Module32Next(hSnap, &moduleEntry)); // select next module
67-
}
3+
namespace memoria {
4+
5+
// --- WINDOW HANDLE ---
6+
HWND GetWindowHandleByTitle(LPCSTR window_title) {
7+
HWND window_handle = FindWindowA(nullptr, window_title);
8+
return window_handle;
9+
}
10+
11+
HWND GetWindowHandleByClass(LPCSTR class_name) {
12+
HWND window_handle = FindWindowA(class_name, nullptr);
13+
return window_handle;
14+
}
15+
16+
// --- PROCESS ID ---
17+
DWORD GetProcessIdFromWindowHandle(HWND window_handle) {
18+
DWORD process_id;
19+
GetWindowThreadProcessId(window_handle, &process_id); // get the process id using window handle
20+
return process_id;
21+
}
22+
23+
DWORD GetProcessIdByTitle(LPCSTR window_title) {
24+
return GetProcessIdFromWindowHandle(GetWindowHandleByTitle(window_title));
6825
}
6926

70-
CloseHandle(hSnap);
71-
return base_address;
72-
}
27+
DWORD GetProcessIdByClass(LPCSTR class_name) {
28+
return GetProcessIdFromWindowHandle(GetWindowHandleByClass(class_name));
29+
}
30+
31+
// --- PROCESS HANDLE ---
32+
HANDLE GetProcessHandleByProcessId(DWORD process_id, DWORD desired_access) {
33+
return OpenProcess(desired_access, FALSE, process_id);
34+
}
35+
36+
HANDLE GetProcessHandleByTitle(LPCSTR window_title, DWORD desired_access) {
37+
return GetProcessHandleByProcessId(GetProcessIdByTitle(window_title), desired_access);
38+
}
39+
40+
HANDLE GetProcessHandleByClass(LPCSTR class_name, DWORD desired_access) {
41+
return GetProcessHandleByProcessId(GetProcessIdByClass(class_name), desired_access);
42+
}
43+
44+
// BASE ADDRESS
45+
uintptr_t GetModuleBaseAddress(TCHAR *modName, DWORD processId) {
46+
47+
uintptr_t base_address = 0;
7348

74-
// --- READ ---
49+
// takes snapshot of all loaded modules in process
50+
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId);
7551

76-
int ReadInt(HANDLE pHandle, uintptr_t address) {
77-
int buffer;
78-
ReadProcessMemory(pHandle, (LPCVOID)address, &buffer, sizeof(int), nullptr);
79-
return buffer;
80-
}
52+
// check if snapshot is valid
53+
if (hSnap != INVALID_HANDLE_VALUE) {
8154

82-
double ReadDouble(HANDLE pHandle, uintptr_t address) {
83-
double buffer;
84-
ReadProcessMemory(pHandle, (LPCVOID)address, &buffer, sizeof(double), nullptr);
85-
return buffer;
86-
}
55+
// create struct that holds the module info while iterating
56+
MODULEENTRY32 moduleEntry;
57+
moduleEntry.dwSize = sizeof(moduleEntry);
8758

88-
float ReadFloat(HANDLE pHandle, uintptr_t address) {
89-
float buffer;
90-
ReadProcessMemory(pHandle, (LPCVOID)address, &buffer, sizeof(float), nullptr);
91-
return buffer;
92-
}
59+
// if a module exists in snapshot, get entry
60+
if (Module32First(hSnap, &moduleEntry)) { // select first entry
61+
do {
62+
if (_tcscmp(moduleEntry.szModule, modName)) { // check if current module name equals searched module
63+
base_address = (uintptr_t) moduleEntry.modBaseAddr;
64+
break;
65+
}
66+
} while (Module32Next(hSnap, &moduleEntry)); // select next module
67+
}
68+
}
69+
70+
CloseHandle(hSnap);
71+
return base_address;
72+
}
73+
74+
// --- READ ---
75+
int ReadInt(HANDLE pHandle, uintptr_t address) {
76+
int buffer;
77+
ReadProcessMemory(pHandle, (LPCVOID) address, &buffer, sizeof(int), nullptr);
78+
return buffer;
79+
}
80+
81+
double ReadDouble(HANDLE pHandle, uintptr_t address) {
82+
double buffer;
83+
ReadProcessMemory(pHandle, (LPCVOID) address, &buffer, sizeof(double), nullptr);
84+
return buffer;
85+
}
86+
87+
float ReadFloat(HANDLE pHandle, uintptr_t address) {
88+
float buffer;
89+
ReadProcessMemory(pHandle, (LPCVOID) address, &buffer, sizeof(float), nullptr);
90+
return buffer;
91+
}
9392

94-
// --- WRITE ---
95-
void WriteInt(HANDLE pHandle, uintptr_t address, int value) {
96-
WriteProcessMemory(pHandle, (LPVOID)address, &value, sizeof(int), nullptr);
97-
}
93+
// --- WRITE ---
94+
void WriteInt(HANDLE pHandle, uintptr_t address, int value) {
95+
WriteProcessMemory(pHandle, (LPVOID) address, &value, sizeof(int), nullptr);
96+
}
9897

99-
void WriteDouble(HANDLE pHandle, uintptr_t address, double value) {
100-
WriteProcessMemory(pHandle, (LPVOID)address, &value, sizeof(double), nullptr);
101-
}
98+
void WriteDouble(HANDLE pHandle, uintptr_t address, double value) {
99+
WriteProcessMemory(pHandle, (LPVOID) address, &value, sizeof(double), nullptr);
100+
}
102101

103-
void WriteFloat(HANDLE pHandle, uintptr_t address, float value) {
104-
WriteProcessMemory(pHandle, (LPVOID)address, &value, sizeof(float), nullptr);
105-
}
102+
void WriteFloat(HANDLE pHandle, uintptr_t address, float value) {
103+
WriteProcessMemory(pHandle, (LPVOID) address, &value, sizeof(float), nullptr);
104+
}
106105

107-
// --- MATH ---
108-
double CalculateDistance(double x1, double y1, double x2, double y2) {
109-
return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
110-
}
106+
// --- MATH ---
107+
double CalculateDistance(double x1, double y1, double x2, double y2) {
108+
return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
109+
}
111110

112-
double CalculateYawToPosition(double x1, double y1, double x2, double y2) {
113-
return atan2(y2 - y1, x2 - x1) * 180 / M_PI + 90;
114-
}
111+
double CalculateYawToPosition(double x1, double y1, double x2, double y2) {
112+
return atan2(y2 - y1, x2 - x1) * 180 / M_PI + 90;
113+
}
115114

116-
double CalculatePitchToPosition(double x1, double y1, double z1, double x2, double y2, double z2) {
117-
return atan2(z2 - z1, CalculateDistance(x1, y1, x2, y2)) * 180 / M_PI;
118-
}
115+
double CalculatePitchToPosition(double x1, double y1, double z1, double x2, double y2, double z2) {
116+
return atan2(z2 - z1, CalculateDistance(x1, y1, x2, y2)) * 180 / M_PI;
117+
}
119118

120-
// --- UTIL ---
121-
LPCVOID AddressToPointerC(uintptr_t address) {
122-
return (LPCVOID)address;
123-
}
119+
// --- UTIL ---
120+
LPCVOID AddressToPointerC(uintptr_t address) {
121+
return (LPCVOID) address;
122+
}
124123

125-
LPVOID AddressToPointer(uintptr_t address) {
126-
return (LPVOID)address;
124+
LPVOID AddressToPointer(uintptr_t address) {
125+
return (LPVOID) address;
126+
}
127127
}

0 commit comments

Comments
 (0)