-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.h
More file actions
59 lines (47 loc) · 1.35 KB
/
Memory.h
File metadata and controls
59 lines (47 loc) · 1.35 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
#pragma once
#include <Windows.h>
#include <iostream>
#include <vector>
#include "Geom.h"
class Memory {
private:
DWORD id = 0; //process id
HANDLE process = NULL;
public:
Memory(const std::string processName);
~Memory();
DWORD GetProcessId();
HANDLE GetProcessHandle();
uintptr_t GetModuleAddress(const std::string moduleName);
uintptr_t FindDMAAddy(uintptr_t ptr, std::vector<unsigned int> offsets);
bool isValidAddress(uintptr_t address);
bool isValidEntity(uint32_t address);
template <typename T>
T Read(uintptr_t address, int size = -1) {
T value;
const int res = ReadProcessMemory(this->process, (LPCVOID)address, &value, size == -1 ? sizeof(T) : size, NULL);
return value;
}
std::string ReadString(uintptr_t address, int size) {
char res[128];
ReadProcessMemory(this->process, (LPCVOID)address, &res, sizeof(res), NULL);
res[strlen(res)] = '\0';
std::string final = std::string(res);
return final;
}
Vec3 ReadVec3(uintptr_t address) {
byte buf[4 * 3];
ReadProcessMemory(this->process, (LPCVOID)address, &buf, sizeof(buf), NULL);
float x;
float y;
float z;
memcpy(&x, buf, 4);
memcpy(&y, buf + 4, 4);
memcpy(&z, buf + 8, 4);
return Vec3{ x,y,z };
}
template <typename T>
bool Write(uintptr_t address, T value) {
return WriteProcessMemory(this->process, (LPVOID)address, &value, sizeof(T), NULL);
}
};