-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathWorld.cpp
More file actions
237 lines (181 loc) · 6.7 KB
/
World.cpp
File metadata and controls
237 lines (181 loc) · 6.7 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
#include "World.h"
TransData* World::GetTransData()
{
uintptr_t world = *(uintptr_t*)(this->offsets.base + this->offsets.gWorld);
if(!world) return NULL;
uintptr_t camera = *(uintptr_t*)(world + this->offsets.camera);
if (!camera) return NULL;
TransData* trans = (TransData*)(camera);
if(!trans) return NULL;
return trans;
}
uintptr_t World::GetCameraOnEntity()
{
uintptr_t world = *(uintptr_t*)(this->offsets.base + this->offsets.gWorld);
if (!world) return NULL;
uintptr_t cameraOn = *(uintptr_t*)(world + this->offsets.CameraOn);
if (!cameraOn) return NULL;
uintptr_t entity = *(uintptr_t*)(cameraOn + 0x8); //Read out of unitinfo link.
if (!entity) return NULL;
return entity;
}
uintptr_t World::GetWorld()
{
uintptr_t world = *(uintptr_t*)(this->offsets.base + this->offsets.gWorld);
if(!world) return NULL;
return world;
}
D3DXVECTOR3 World::GetEntityPosition(uintptr_t entity, COORD_TYPE type, bool localPlayer)
{
uintptr_t manVisualState;
if (localPlayer)
{
manVisualState = *(uintptr_t*)(entity + this->offsets.manVisualState);
}
else
{
manVisualState = *(uintptr_t*)(entity + this->offsets.renderVisualState);
}
if (!manVisualState) D3DXVECTOR3(0,0,0);
D3DXVECTOR3 position;
if (type == COORD_FEET)
{
position = *(D3DXVECTOR3*)(manVisualState + this->offsets.feetPos);
}
if (type == COORD_HEAD)
{
position = *(D3DXVECTOR3*)(manVisualState + this->offsets.headPos);
}
return position;
}
extern uintptr_t centerEntity;
void World::UnlockVehicle()
{
uintptr_t cameraOn = this->GetCameraOnEntity();
uintptr_t world = this->GetWorld();
uintptr_t playerOn = *(uintptr_t*)(world + this->offsets.LocalPlayer); if (!playerOn) return;
uintptr_t localEnt = *(uintptr_t*)(playerOn + 0x8); if(!localEnt) return;
if (localEnt != cameraOn)
{
uintptr_t inGameUI = *(uintptr_t*)(world + this->offsets.InGameUI); if (!inGameUI) return;
uintptr_t cursorTarget = *(uintptr_t*)(inGameUI + this->offsets.CursorTarget); if (!cursorTarget) return;
uintptr_t cursorEntity = *(uintptr_t*)(cursorTarget + 0x8); if (!cursorEntity) return; //0x8 is unit info link dereference.
int currLockState = *(int*)(cursorEntity + this->offsets.vehicleLockState);
if (currLockState != 2)
{
*(int*)(cursorEntity + this->offsets.vehicleLockState) = 2;
}
else
{
*(int*)(cursorEntity + this->offsets.vehicleLockState) = 0;
}
}
else
{
int currLockState = *(int*)(cameraOn + this->offsets.vehicleLockState);
if (currLockState != 2)
{
*(int*)(cameraOn + this->offsets.vehicleLockState) = 2;
}
else
{
*(int*)(cameraOn + this->offsets.vehicleLockState) = 0;
}
}
}
void World::RepairCurrentObject()
{
uintptr_t cameraOn = this->GetCameraOnEntity();
if(!cameraOn) return;
uintptr_t partsTable = *(uintptr_t*)(cameraOn + this->offsets.parts);
if (partsTable)
{
int partsTableSz = *(int*)(cameraOn + this->offsets.parts + 0x8); //TArray, size follows + 0x8 from table pointer.
for (size_t i = 0; i < partsTableSz; i++)
{
*(float*)(partsTable + (i * 0x4)) = 0.f; //0 = fully repaired.
}
}
}
char* World::GetPlayerName(int playerId)
{
uintptr_t networkManager = *(uintptr_t*)(this->offsets.base + this->offsets.gNetworkManager);
if(!networkManager) return NULL;
uintptr_t networkClient = *(uintptr_t*)(networkManager + this->offsets.networkClient);
if(!networkClient) return NULL;
uintptr_t scoreboard = *(uintptr_t*)(networkClient + this->offsets.scoreboard);
if (!scoreboard) return NULL;
int scoreboardSz = *(int*)(networkClient + this->offsets.scoreboard + 0x8);
for (size_t i = 0; i < scoreboardSz; i++)
{
int scoreboardPId = *(int*)(scoreboard + (i * this->offsets.scoreboardObjectSize) + 0x8);
if (scoreboardPId == playerId)
{
uintptr_t usernamePtr = *(uintptr_t*)(scoreboard + (i * this->offsets.scoreboardObjectSize) + this->offsets.usernamePtr);
if (usernamePtr)
{
char* name = (char*)(usernamePtr + 0x10);
if (name) return name;
else return NULL;
}
}
}
return NULL;
}
#include <locale>
#include <codecvt>
#include <string>
Entity World::SetupEntity(uintptr_t entity)
{
Entity ent;
ent.type = ENTITY_BAD_TYPE;
uintptr_t modelptr = *(uintptr_t*)(entity + this->offsets.model);
if(!modelptr) return ent;
uintptr_t modelStrPtr = *(uintptr_t*)(modelptr + this->offsets.modelName);
if(!modelStrPtr) return ent;
int nameSz = *(int*)(modelStrPtr + 0x8);
if(nameSz <= 0) return ent;
char* modelname = (char*)(modelStrPtr + 0x10);
if(!modelname) return ent;
int playerId = *(int*)(entity + this->offsets.playerId);
if (strstr(modelname, "character"))
{
if (playerId > 1)
{
ent.type = ENTITY_PLAYER;
char* playername = this->GetPlayerName(playerId);
if(!playername)
{
ent.type = ENTITY_BAD_TYPE;
return ent;
}
std::string tmp(playername);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring wide = converter.from_bytes(tmp);
ent.info = wide;
ent.sideId = *(int*)(entity + this->offsets.sideid); //sideid offset
return ent;
}
else
{
ent.type = ENTITY_AI;
ent.info = L"";
return ent;
}
}
else if ((strstr(modelname, "soft_f") != NULL) || (strstr(modelname, "armor_f") != NULL)
|| (strstr(modelname, "air_f") != NULL) || (strstr(modelname, "boat_f") != NULL)
|| (strstr(modelname, "vehicle") != NULL) || (strstr(modelname, "hmg") != NULL)
|| (strstr(modelname, "exile") != NULL))
{
ent.type = ENTITY_VEHICLE;
std::string tmp(modelname);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring wide = converter.from_bytes(tmp);
wide = wide.substr(wide.find_last_of(L"\\") + 1, (wide.find_last_of(L"_") - 1 - wide.find_last_of(L"\\")));
ent.info = wide;
return ent;
}
ent.type = ENTITY_BAD_TYPE;
return ent;
}