-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeadlock.h
278 lines (235 loc) · 7.51 KB
/
deadlock.h
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
#pragma once
#include <frong.h>
#include <memory>
#include "log.h"
#include "math.h"
#include <string>
#include <list>
#include <unordered_map>
#include <Imgui/imgui.h>
namespace {
std::unique_ptr<frg::process> game;
uintptr_t client = 0;
uintptr_t entity_list = 0;
uintptr_t camera_manager = 0;
std::vector<std::string> bone_names = {
"pelvis",
"neck_0",
"head",
"clavicle_L",
"arm_upper_L",
"arm_lower_L",
"hand_L",
"clavicle_R",
"arm_upper_R",
"arm_lower_R",
"hand_R",
"leg_upper_L",
"leg_lower_L",
"ankle_L",
"leg_upper_R",
"leg_lower_R",
"ankle_R",
};
std::unordered_map<std::string, std::array<int, 17>> bone_indexes;
namespace offsets {
uintptr_t entity_list = 0x1F220C8;
uintptr_t local_player = 0x1DCB588;
uintptr_t view_matrix = 0x20DFA20;
uintptr_t camera_manager = 0x1F439C0;
ptrdiff_t m_hpawn = 0x60c;
ptrdiff_t m_pgamescenenode = 0x328;
ptrdiff_t m_modelstate = 0x170;
ptrdiff_t m_hmodel = 0x00D0;
ptrdiff_t m_modelname = 0x00D8;
ptrdiff_t m_voldorigin = 0x0EDC;
ptrdiff_t m_iteamnum = 0x03eb;
ptrdiff_t m_playerdataglobal = 0x0750;
ptrdiff_t m_imaxhealth = 0x0010; // int32
ptrdiff_t m_ihealth = 0x0048;
// int32
}// namespace offsets
}
namespace deadlock {
bool init() {
game = std::make_unique<frg::process>(L"project8.exe", true);
if (!game->valid()) {
ERROR("Failed to attach to game\n");
return false;
}
client = (uintptr_t)game->module(L"client.dll").value().base();
if (!client) {
ERROR("Failed to find client.dll base\n");
return false;
}
LOG("client.dll base: 0x{:x}\n", client);
LOG("Game initialized\n");
return true;
}
void update() {
entity_list = game->read<uintptr_t>((void*)(client + offsets::entity_list));
camera_manager = game->read<uintptr_t>((void*)(client + offsets::camera_manager + 0x28));
}
void* get_entity_by_idx(const int32_t idx)
{
if (idx > 0x7FFE) {
return nullptr;
}
if ((idx >> 9) > 0x3F) {
return nullptr;
}
const auto entry_list =
game->read<uintptr_t>((void*)(entity_list + 8i64 * (idx >> 9) + 16));
if (!entry_list)
return nullptr;
const auto player_controller = (uint32_t*)(120i64 * (idx & 0x1FF) + entry_list);
if (!player_controller)
return nullptr;
return game->read<void*>(player_controller);
}
void* get_player_pawn(uintptr_t entity) {
auto pawn_handle = game->read<uint32_t>((void*)(entity + offsets::m_hpawn ));
return get_entity_by_idx(pawn_handle & 0x7fff);
}
uintptr_t get_local_player() {
auto loacl_entity = game->read<uintptr_t>((void*)(client + offsets::local_player));
return (uintptr_t )get_player_pawn(loacl_entity);
}
uintptr_t get_node(uintptr_t entity) {
return game->read<uintptr_t>((void*)(entity + offsets::m_pgamescenenode));
}
vec3 get_bone_position(uintptr_t node, int bone_index) {
uintptr_t boneArray = game->read<uintptr_t>((void*)(node + offsets::m_modelstate + 0x80));
if (!boneArray) return vec3();
uintptr_t boneAddress = boneArray + bone_index * 0x20;
return game->read<vec3>((void*)boneAddress);
}
uintptr_t get_model(uintptr_t node) {
uintptr_t hmodel = game->read<uintptr_t>((void*)(node + offsets::m_modelstate + offsets::m_hmodel));
return game->read<uintptr_t>((void*)hmodel);
}
std::string get_bone_name(uintptr_t model, int bone_index) {
const auto names_count = game->read<uint32_t>((void*)(model + 0x178));
if (names_count < 0 || bone_index >= names_count)
return "root";
const auto names_ptr = game->read<uintptr_t>((void*)(model + 0x168));
const auto bone_name_address = game->read<uintptr_t>((void*)(names_ptr + bone_index * 8));
char buffer[64]{};
game->read((void*)bone_name_address, &buffer, 64);
return std::string{ buffer };
}
void loop_bone_name(uintptr_t model) {
const auto names_count = game->read<uint32_t>((void*)(model + 0x178));
for (int idx = 0; idx < names_count; idx++) {
LOG("Bone idx {} name {}", idx, get_bone_name(model, idx));
}
}
view_matrix_t get_view_matrix() {
view_matrix_t view_matrix;
game->read((void*)(client + offsets::view_matrix), &view_matrix, sizeof(view_matrix));
return view_matrix;
}
vec3 get_player_position(uintptr_t entity) {
return game->read<vec3>((void*)(entity + offsets::m_voldorigin));
}
std::string get_model_name(uintptr_t node) {
uintptr_t hmodel = game->read<uintptr_t>((void*)(node + offsets::m_modelstate + offsets::m_modelname));
if (!hmodel)return {"none"};
char buffer[64]{};
game->read((void*)hmodel, &buffer, 64);
std::string model_path(buffer);
return model_path.substr(model_path.rfind("/") + 1, model_path.rfind(".") - model_path.rfind("/") - 1);
}
uint8_t get_team_num(uintptr_t entity) {
return game->read<uint8_t>((void*)(entity + offsets::m_iteamnum));
}
std::array<int, 17> get_bone_indexes(uintptr_t node) {
std::string bone_name = get_model_name(node);
if (bone_indexes.find(bone_name) != bone_indexes.end()) {
return bone_indexes[bone_name];
}
auto model = get_model(node);
const auto names_count = game->read<uint32_t>((void*)(model + 0x178));
std::array<int, 17> res{};
for (int idx = 0; idx < 17;++idx) {
for (int cur = 0; cur < 64; cur++) {
if (bone_names[idx] == get_bone_name(model, cur)) {
res[idx] = cur;
break;
}
}
}
bone_indexes[bone_name] = res;
return res;
}
vec3 get_player_head_position(uintptr_t entity) {
auto node = get_node(entity);
auto bone_indexes = get_bone_indexes(node);
return get_bone_position(node, bone_indexes[2]);
}
void draw_bone(uintptr_t entity, view_matrix_t view_matrix) {
static std::list<std::list<int>> bones = {
{1,0},
{1,4,5,6},
{1,8,9,10},
{0,11,12,13},
{0,14,15,16},
};
auto node = deadlock::get_node(entity);
auto bone_indexes = deadlock::get_bone_indexes(node);
for (auto& part : bones) {
vec3 previous = vec3();
for (auto index : part) {
auto bone_position = deadlock::get_bone_position(node, bone_indexes[index]);
vec3 screen_position;
if(!math::world_to_screen({ 1920, 1080 }, bone_position, screen_position, view_matrix))
return ;
if (screen_position.x == 0.0 && screen_position.y == 0.0) {
return ;
}
if (previous.x == 0.0)
{
previous = screen_position;
continue;
}
ImGui::GetForegroundDrawList()->
AddLine({ previous.x, previous.y }, { screen_position.x, screen_position.y }, IM_COL32(255, 0, 0, 255));
previous = screen_position;
}
}
}
int get_max_entity_count() {
return game->read<int>((void*)(entity_list + 0x1520));
}
int get_health(uintptr_t entity) {
return game->read<int>((void*)(entity + 0x034C));
}
int get_max_health(uintptr_t entity) {
return game->read<int>((void*)(entity + 0x0348));
}
void set_view_angle(float pitch, float yaw) {
vec2 angles{ pitch, yaw };
game->write((void*)(camera_manager + 0x44), &angles, sizeof(angles));
};
vec4 get_box_rect(vec3 top, vec3 bottom) {
vec4 ret{};
ret.h = (int)(bottom.y - top.y);
ret.w = ret.h / 2;
ret.x = (int)(top.x - ret.w / 2);
ret.y = (int)(top.y);
return ret;
}
void draw_health_bar(uintptr_t entity,vec2 pos,int width) {
int health = get_health(entity);
int max_health = get_max_health(entity);
if (max_health <= 0) return ;
int HealthMaxWidth = width * 0.9f;
int HealthWidth = HealthMaxWidth * health / max_health;
ImGui::GetForegroundDrawList()->AddRectFilledMultiColor(
ImVec2(pos.x - HealthMaxWidth / 2, pos.y - 7),
ImVec2(pos.x - HealthMaxWidth / 2 + HealthWidth, pos.y - 3),
IM_COL32(255, 0, 0, 255), IM_COL32(0, 255, 0, 255),
IM_COL32(0, 255, 0, 255), IM_COL32(255, 0, 0, 255));
ImGui::GetForegroundDrawList()->AddRect(ImVec2(pos.x - HealthMaxWidth / 2, pos.y - 7), ImVec2(pos.x - HealthMaxWidth / 2 + HealthMaxWidth, pos.y - 7 + 5), ImGui::ColorConvertFloat4ToU32(ImVec4(0.3f, 0.3f, 0.3f, 0.8f)), 0, 15, 1.f);
}
}// namespace deadlock