-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMemory.cpp
More file actions
295 lines (238 loc) · 8.6 KB
/
Copy pathMemory.cpp
File metadata and controls
295 lines (238 loc) · 8.6 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
#include <Windows.h>
#include <Psapi.h>
#include "Memory.h"
#include "Globals.h"
//All offset variables hardcoded
//namespace Jubs
//namespace MPGH
namespace Offset {
DWORD_PTR GameManager = 0x473A3D0;
DWORD_PTR EntityList = 0xC0;
DWORD_PTR Entity = 0x0008;
DWORD_PTR EntityRef = 0x20;
DWORD_PTR EntityInfo = 0x18;
DWORD_PTR MainComponent = 0xB8;
DWORD_PTR ChildComponent = 0x8;
DWORD_PTR Health = 0x108;
DWORD_PTR PlayerInfo = 0x270;
DWORD_PTR PlayerInfoDeref = 0x0;
DWORD_PTR PlayerTeamId = 0x140;
DWORD_PTR PlayerName = 0x158;
DWORD_PTR FeetPosition = 0x190;
DWORD_PTR HeadPosition = 0x130;
DWORD_PTR weaponComp = 0x38;
DWORD_PTR WeaponProcessor = 0xF0;
DWORD_PTR Weapon = 0x0;
DWORD_PTR WeaponInfo = 0x100;
DWORD_PTR Spread = 0x2B0; //float
DWORD_PTR Recoil = 0x2E8; //float
DWORD_PTR Recoil2 = 0x354; //float
DWORD_PTR Recoil3 = 0x304; //Vector4
DWORD_PTR AdsRecoil = 0x330; //Vector2
DWORD_PTR Renderer = 0x46F0800;
DWORD_PTR GameRenderer = 0x0;
DWORD_PTR EngineLink = 0xd8;
DWORD_PTR Engine = 0x218;
DWORD_PTR Camera = 0x38;
DWORD_PTR ViewTranslastion = 0x1A0;
DWORD_PTR ViewRight = 0x170;
DWORD_PTR ViewUp = 0x180;
DWORD_PTR ViewForward = 0x190;
DWORD_PTR FOVX = 0x1B0;
DWORD_PTR FOVY = 0x1C4;
}
Mem::Mem() {};
BOOL Mem::SetBaseAddress() {
HMODULE hMods[1024];
DWORD cbNeeded;
unsigned int i;
if (EnumProcessModules(Global::GameHandle, hMods, sizeof(hMods), &cbNeeded))
{
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
{
TCHAR szModName[MAX_PATH];
if (GetModuleFileNameEx(Global::GameHandle, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR)))
{
std::wstring wstrModName = szModName;
std::wstring wstrModContain = L"RainbowSix.exe";
if (wstrModName.find(wstrModContain) != std::string::npos)
{
Global::BaseAddress = hMods[i];
return true;
}
}
}
}
return false;
}
DWORD_PTR Mem::GetBaseAddress() {
return (DWORD_PTR)Global::BaseAddress;
}
template<typename T> T Mem::RPM(SIZE_T address) {
//The buffer for data that is going to be read from memory
T buffer;
//The actual RPM
ReadProcessMemory(Global::GameHandle, (LPCVOID)address, &buffer, sizeof(T), NULL);
//Return our buffer
return buffer;
}
std::string Mem::RPMString(SIZE_T address) {
//Make a char array of 20 bytes
char name[20];
//The actual RPM
ReadProcessMemory(Global::GameHandle, (LPCVOID)address, &name, sizeof(name), NULL);
//Add each char to our string
//While also checking for a null terminator to end the string
std::string nameString;
for (int i = 0; i < sizeof(name); i++) {
if (name[i] == 0)
break;
else
nameString += name[i];
}
return nameString;
}
template<typename T> void Mem::WPM(SIZE_T address, T buffer) {
//A couple checks to try and avoid crashing
//These don't actually make sense, feel free to remove redundent ones
if (address == 0 || (LPVOID)address == nullptr || address == NULL) {
return;
}
WriteProcessMemory(Global::GameHandle, (LPVOID)address, &buffer, sizeof(buffer), NULL);
}
void Mem::UpdateAddresses() {
//Game manager pointer from games base address + the GameManager offset
pGameManager = RPM<DWORD_PTR>(GetBaseAddress() + Offset::GameManager);
//Entity list pointer from the GameManager + EntityList offset
pEntityList = RPM<DWORD_PTR>(pGameManager + Offset::EntityList);
//Renderer pointer from games base address + Renderer offset
pRender = RPM<DWORD_PTR>(GetBaseAddress() + Offset::Renderer);
//Game Renderer pointer from Renderer + GameRenderer offset
pGameRender = RPM<DWORD_PTR>(pRender + Offset::GameRenderer);
//EngineLink pointer from GameRenderer + EngineLink offset
pEngineLink = RPM<DWORD_PTR>(pGameRender + Offset::EngineLink);
//Engine pointer from EngineLink + Engine offset
pEngine = RPM<DWORD_PTR>(pEngineLink + Offset::Engine);
//Camera pointer from Engine + Camera offset
pCamera = RPM<DWORD_PTR>(pEngine + Offset::Camera);
}
DWORD_PTR Mem::GetEntity(int i) {
DWORD_PTR entityBase = RPM<DWORD_PTR>(pEntityList + (i * Offset::Entity));
return RPM<DWORD_PTR>(entityBase + Offset::EntityRef);
}
DWORD_PTR Mem::GetLocalEntity() {
//Loop through the first 12
for (int i = 0; i < 12; i++) {
//get current entity
DWORD_PTR entity = GetEntity(i);
//get that entity's name
std::string entityName = GetEntityPlayerName(entity);
//check it against our local name
if (strcmp(entityName.c_str(), Global::LocalName.c_str()) == 0) {
return entity;
}
}
//return the first entity if we didn't find anything
return GetEntity(0);
}
DWORD Mem::GetEntityHealth(DWORD_PTR entity) {
//Entity info pointer from the Entity
DWORD_PTR EntityInfo = RPM<DWORD_PTR>(entity + Offset::EntityInfo);
//Main component pointer from the entity info
DWORD_PTR MainComponent = RPM<DWORD_PTR>(EntityInfo + Offset::MainComponent);
//Child component pointer form the main component
DWORD_PTR ChildComponent = RPM<DWORD_PTR>(MainComponent + Offset::ChildComponent);
//Finally health from the child component
return RPM<DWORD>(ChildComponent + Offset::Health);
}
Vector3 Mem::GetEntityFeetPosition(DWORD_PTR entity) {
//We get the feet position straight from the entity
return RPM<Vector3>(entity + Offset::FeetPosition);
}
Vector3 Mem::GetEntityHeadPosition(DWORD_PTR entity) {
//We get the head position straight from the entity
return RPM<Vector3>(entity + Offset::HeadPosition);
}
std::string Mem::GetEntityPlayerName(DWORD_PTR entity) {
DWORD_PTR playerInfo = RPM<DWORD_PTR>(entity + Offset::PlayerInfo);
DWORD_PTR playerInfoD = RPM<DWORD_PTR>(playerInfo + Offset::PlayerInfoDeref);
return RPMString(RPM<DWORD_PTR>(playerInfoD + Offset::PlayerName) + 0x0);
}
BYTE Mem::GetEntityTeamId(DWORD_PTR entity) {
//Team id comes from player info
DWORD_PTR playerInfo = RPM<DWORD_PTR>(entity + Offset::PlayerInfo);
//We have to derefrnce it as 0x0
DWORD_PTR playerInfoD = RPM<DWORD_PTR>(playerInfo + Offset::PlayerInfoDeref);
return RPM<BYTE>(playerInfoD + Offset::PlayerTeamId);
}
PlayerInfo Mem::GetAllEntityInfo(DWORD_PTR entity) {
PlayerInfo p;
p.Health = GetEntityHealth(entity);
p.Name = GetEntityPlayerName(entity);
p.Position = GetEntityFeetPosition(entity);
p.w2s = WorldToScreen(p.Position);
p.w2sHead = WorldToScreen(GetEntityHeadPosition(entity));
p.TeamId = GetEntityTeamId(entity);
return p;
}
void Mem::ZeroRecoilSpread(DWORD_PTR entity) {
DWORD_PTR entityInfo = RPM<DWORD_PTR>(entity + Offset::EntityInfo);
DWORD_PTR mainComp = RPM<DWORD_PTR>(entityInfo + Offset::MainComponent);
DWORD_PTR weaponComp = RPM<DWORD_PTR>(mainComp + Offset::weaponComp);
DWORD_PTR weaponProc = RPM<DWORD_PTR>(weaponComp + Offset::WeaponProcessor);
DWORD_PTR weapon = RPM<DWORD_PTR>(weaponProc + Offset::Weapon);
DWORD_PTR weaponInfo = RPM<DWORD_PTR>(weapon + Offset::WeaponInfo);
float recoil = RPM<float>(weaponInfo + Offset::Recoil);
float recoil2 = RPM<float>(weaponInfo + Offset::Recoil2);
Vector4 recoil3 = RPM<Vector4>(weaponInfo + Offset::Recoil3);
Vector2 adsRecoil = RPM<Vector2>(weaponInfo + Offset::AdsRecoil);
float spread = RPM<float>(weaponInfo + Offset::Spread);
//Make sure values aren't already 0 before we set them to 0, avoids wasting some time and writes
if (recoil != 0) {
WPM<float>(weaponInfo + Offset::Recoil, 0);
}
if (recoil2 != 0) {
WPM<float>(weaponInfo + Offset::Recoil2, 0);
}
if (!(recoil3.x == 0 && recoil3.y == 0 && recoil3.z == 0 && recoil3.w == 0)) {
WPM<Vector4>(weaponInfo + Offset::Recoil3, Vector4(0, 0, 0, 0));
}
if (!(adsRecoil.x == 0 && adsRecoil.y == 0)) {
WPM<Vector2>(weaponInfo + Offset::AdsRecoil, Vector2(0, 0));
}
if (spread != 0) {
WPM<float>(weaponInfo + Offset::Spread, 0);
}
}
Vector3 Mem::GetViewTranslation() {
//View translation comes straight from the camera
return RPM<Vector3>(pCamera + Offset::ViewTranslastion);
}
Vector3 Mem::GetViewRight() {
//View right comes directly from the camera
return RPM<Vector3>(pCamera + Offset::ViewRight);
}
Vector3 Mem::GetViewUp() {
//View up comes directly from the camera
return RPM<Vector3>(pCamera + Offset::ViewUp);
}
Vector3 Mem::GetViewForward() {
//View forward comes directly from the camera
return RPM<Vector3>(pCamera + Offset::ViewForward);
}
float Mem::GetFOVX() {
//FOV comes directly from the camera
return RPM<float>(pCamera + Offset::FOVX);
}
float Mem::GetFOVY() {
//FOV comes directly from the camera
return RPM<float>(pCamera + Offset::FOVY);
}
//Shout out to RangeMachine's SDK for this one
Vector3 Mem::WorldToScreen(Vector3 position) {
Vector3 temp = position - GetViewTranslation();
float x = temp.Dot(GetViewRight());
float y = temp.Dot(GetViewUp());
float z = temp.Dot(GetViewForward() * -1);
return Vector3((displayWidth / 2) * (1 + x / GetFOVX() / z), (displayHeight / 2) * (1 - y / GetFOVY() / z), z);
}