forked from Doctor-Coomer/TeamFortress2-Linux-Internal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
332 lines (248 loc) · 12.5 KB
/
Copy pathmain.cpp
File metadata and controls
332 lines (248 loc) · 12.5 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include "print.hpp"
#include "random_seed.hpp"
#include "classes/keyvalues.hpp"
#include <unistd.h>
#include "interfaces/engine.hpp"
#include "interfaces/client.hpp"
#include "interfaces/entity_list.hpp"
#include "interfaces/debug_overlay.hpp"
#include "interfaces/surface.hpp"
#include "interfaces/engine_trace.hpp"
#include "interfaces/render_view.hpp"
#include "interfaces/material_system.hpp"
#include "interfaces/model_render.hpp"
#include "interfaces/convar_system.hpp"
#include "interfaces/prediction.hpp"
#include "interfaces/steam_client.hpp"
#include "interfaces/steam_friends.hpp"
#include "interfaces/input.hpp"
#include "interfaces/attribute_manager.hpp"
#include "interfaces/global_vars.hpp"
#include "interfaces/move_helper.hpp"
#include "interfaces/game_movement.hpp"
#include "interfaces/client_state.hpp"
#include "hooks/hooks.cpp"
#include "libsigscan/libsigscan.h"
#include "funchook/funchook.h"
#include "hooks/sdl.cpp"
//#include "hooks/vulkan.cpp"
#include "hooks/client_mode_create_move.cpp"
#include "hooks/client_create_move.cpp"
#include "hooks/cl_move.cpp"
#include "hooks/paint_traverse.cpp"
#include "hooks/override_view.cpp"
#include "hooks/draw_view_model.cpp"
#include "hooks/in_cond.cpp"
#include "hooks/draw_model_execute.cpp"
#include "hooks/load_white_list.cpp"
#include "hooks/should_draw_local_player.cpp"
#include "hooks/should_draw_this_player.cpp"
#include "hooks/draw_view_models.cpp"
#include "vec.hpp"
void** client_mode_vtable;
void** vgui_vtable;
void** client_vtable;
void** model_render_vtable;
funchook_t* funchook;
__attribute__((constructor))
void entry() {
// Interfaces
client = (Client*)get_interface("./tf/bin/linux64/client.so", "VClient017");
engine = (Engine*)get_interface("./bin/linux64/engine.so", "VEngineClient014");
vgui = get_interface("./bin/linux64/vgui2.so", "VGUI_Panel009");
surface = (Surface*)get_interface("./bin/linux64/vguimatsurface.so", "VGUI_Surface030");
unsigned long func_address = (unsigned long)sigscan_module("client.so", "48 8D 05 ? ? ? ? 48 8B 38 48 8B 07 FF 90 ? ? ? ? 48 8D 15 ? ? ? ? 84 C0");
unsigned int input_eaddr = *(unsigned int*)(func_address + 0x3);
unsigned long next_instruction = (unsigned long)(func_address + 0x7);
input = (Input*)(*(void**)(next_instruction + input_eaddr));
unsigned long check_stuck_address = (unsigned long)sigscan_module("client.so", "48 8D 05 ? ? ? ? 48 89 85 ? ? ? ? 74 ? 48 8B 38");
unsigned int move_helper_eaddr = *(unsigned int*)(check_stuck_address + 0x3);
unsigned long check_stuck_next_instruction = (unsigned long)(check_stuck_address + 0x7);
move_helper = (MoveHelper*)(*(void**)(check_stuck_next_instruction + move_helper_eaddr));
unsigned long rcon_addr_change_address = (unsigned long)sigscan_module("engine.so", "48 8D 05 ? ? ? ? 4C 8B 40");
unsigned int client_state_eaddr = *(unsigned int*)(rcon_addr_change_address + 0x3);
unsigned long rcon_addr_change_next_instruction = (unsigned long)(rcon_addr_change_address + 0x7);
client_state = (ClientState*)((void*)(rcon_addr_change_next_instruction + client_state_eaddr));
prediction = (Prediction*)get_interface("./tf/bin/linux64/client.so", "VClientPrediction001");
game_movement = (GameMovement*)get_interface("./tf/bin/linux64/client.so", "GameMovement001");
overlay = (DebugOverlay*)get_interface("./bin/linux64/engine.so", "VDebugOverlay003");
entity_list = (EntityList*)get_interface("./tf/bin/linux64/client.so", "VClientEntityList003");
render_view = (RenderView*)get_interface("./bin/linux64/engine.so", "VEngineRenderView014");
engine_trace = (EngineTrace*)get_interface("./bin/linux64/engine.so", "EngineTraceClient003");
model_render = (ModelRender*)get_interface("./bin/linux64/engine.so", "VEngineModel016");
material_system = (MaterialSystem*)get_interface("./bin/linux64/materialsystem.so", "VMaterialSystem082");
convar_system = (ConvarSystem*)get_interface("./bin/linux64/libvstdlib.so", "VEngineCvar004");
prediction = (Prediction*)get_interface("./tf/bin/linux64/client.so", "VClientPrediction001");
steam_client = (SteamClient*)get_interface("../../../linux64/steamclient.so", "SteamClient020");
int steam_pipe = steam_client->create_steam_pipe();
int steam_user = steam_client->connect_to_global_user(steam_pipe);
steam_friends = (SteamFriends*)steam_client->get_steam_friends_interface(steam_user, steam_pipe, "SteamFriends017");
client_vtable = *(void ***)client;
void* hud_process_input_addr = client_vtable[10];
__uint32_t client_mode_eaddr = *(__uint32_t *)((__uint64_t)(hud_process_input_addr) + 0x3);
void* client_mode_next_instruction = (void *)((__uint64_t)(hud_process_input_addr) + 0x7);
void* client_mode_interface = *(void **)((__uint64_t)(client_mode_next_instruction) + client_mode_eaddr);
unsigned long hud_update = (unsigned long)client_vtable[11];
unsigned int global_vars_eaddr = *(unsigned int *)(hud_update + 0x16);
unsigned long global_vars_next_instruction = (unsigned long)(hud_update + 0x1A);
global_vars = (GlobalVars*)(*(void **)(global_vars_next_instruction + global_vars_eaddr));
// VMT Function Hooks
client_mode_vtable = *(void***)client_mode_interface;
client_mode_create_move_original = (bool (*)(void*, float, user_cmd*))client_mode_vtable[22];
if (!write_to_table(client_mode_vtable, 22, (void*)client_mode_create_move_hook)) {
print("ClientModeShared::CreateMove hook failed\n");
} else {
print("ClientModeShared::CreateMove hooked\n");
}
client_create_move_original = (void (*)(void*, int, float, bool))client_vtable[21];
if (!write_to_table(client_vtable, 21, (void*)client_create_move_hook)) {
print("Client::CreateMove hook failed\n");
} else {
print("Client::CreateMove hooked\n");
}
override_view_original = (void (*)(void*, view_setup*))client_mode_vtable[17];
if (!write_to_table(client_mode_vtable, 17, (void*)override_view_hook)) {
print("OverrideView hook failed\n");
} else {
print("OverrideView hooked\n");
}
draw_view_model_original = (bool (*)(void*))client_mode_vtable[25];
if (!write_to_table(client_mode_vtable, 25, (void*)draw_view_model_hook)) {
print("ShouldDrawViewModel hook failed\n");
} else {
print("ShouldDrawViewModel hooked\n");
}
vgui_vtable = *(void ***)vgui;
paint_traverse_original = (void (*)(void*, void*, __int8_t, __int8_t))vgui_vtable[42];
if (!write_to_table(vgui_vtable, 42, (void*)paint_traverse_hook)) {
print("PaintTraverse hook failed\n");
} else {
print("PaintTraverse hooked\n");
}
model_render_vtable = *(void ***)model_render;
draw_model_execute_original = (void (*)(void*, void*, ModelRenderInfo_t*, VMatrix*))model_render_vtable[19];
if (!write_to_table(model_render_vtable, 19, (void*)draw_model_execute_hook)) {
print("DrawModelExecute hook failed\n");
} else {
print("DrawModelExecute hooked\n");
}
// Non-VMT Function hooks
funchook = funchook_create();
in_cond_original = (bool (*)(void*, int))sigscan_module("client.so", "55 83 FE ? 48 89 E5 41 54 41 89 F4");
load_white_list_original = (void* (*)(void*, const char*))sigscan_module("engine.so", "55 48 89 E5 41 55 41 54 49 89 FC 48 83 EC ? 48 8B 07 FF 50");
cl_move_original = (void (*)(float, bool))sigscan_module("engine.so", "55 48 89 E5 41 57 41 56 41 55 41 54 53 48 83 EC ? 83 3D ? ? ? ? ? F3 0F 11 85");
should_draw_local_player_original = (bool (*)(void*))sigscan_module("client.so", "55 48 89 E5 41 54 48 83 EC ? 48 8D 05 ? ? ? ? 48 8B 38 48 85 FF 74 ? 48 8B 07 FF 50");
should_draw_this_player_original = (bool (*)(void*))sigscan_module("client.so", "55 48 89 E5 41 54 53 E8 ? ? ? ? 84 C0 75");
draw_view_models_original = (void (*)(void*, view_setup*, bool))sigscan_module("client.so", "55 31 C0 48 89 E5 41 57 41 56 41 55 41 89 D5 41 54 49 89 FC 53 48 89 F3 48 81 EC");
attribute_hook_value_float_original = (float (*)(float, const char*, Entity*, void*, bool))sigscan_module("client.so", "55 31 C0 48 89 E5 41 57 41 56 41 55 49 89 F5 41 54 49 89 FC 53 89 CB");
int rv;
rv = funchook_prepare(funchook, (void**)&in_cond_original, (void*)in_cond_hook);
if (rv != 0) {
}
rv = funchook_prepare(funchook, (void**)&load_white_list_original, (void*)load_white_list_hook);
if (rv != 0) {
}
rv = funchook_prepare(funchook, (void**)&cl_move_original, (void*)cl_move_hook);
if (rv != 0) {
}
rv = funchook_prepare(funchook, (void**)&should_draw_local_player_original, (void*)should_draw_local_player_hook);
if (rv != 0) {
}
rv = funchook_prepare(funchook, (void**)&should_draw_this_player_original, (void*)should_draw_this_player_hook);
if (rv != 0) {
}
rv = funchook_prepare(funchook, (void**)&draw_view_models_original, (void*)draw_view_models_hook);
if (rv != 0) {
}
key_values_constructor_original = (KeyValues* (*)(void*, const char*))sigscan_module("client.so", "55 31 C0 66 0F EF C0 48 89 E5 53");
rv = funchook_install(funchook, 0);
if (rv != 0) {
print("Non-VMT related hooks failed\n");
} else {
print("InCond hooked\n");
print("LoadWhiteList hooked\n");
print("CL_Move hooked\n");
//print("vkQueuePresentKHR hooked\n");
}
// Bespoke SDL hooking
void* lib_sdl_handle = dlopen("/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0", RTLD_LAZY | RTLD_NOLOAD);
if (!lib_sdl_handle) {
print("Failed to load SDL2\n");
return;
}
print("SDL2 loaded at %p\n", lib_sdl_handle);
if (!sdl_hook(lib_sdl_handle, "SDL_PollEvent", (void*)poll_event_hook, (void **)&poll_event_original)) {
print("Failed to hook SDL_PollEvent\n");
return;
}
if (!sdl_hook(lib_sdl_handle, "SDL_GL_SwapWindow", (void*)swap_window_hook, (void **)&swap_window_original)) {
print("Failed to hook SDL_GL_SwapWindow\n");
return;
}
dlclose(lib_sdl_handle);
// TODO: Hook vulkan
/*
void* lib_vulkan_handle = dlopen("/run/host/usr/lib/libvulkan.so.1.4.313", RTLD_LAZY | RTLD_NOLOAD);
if (!lib_vulkan_handle) {
print("Failed to load vulkan\n");
return;
}
queue_present_original = (VkResult (*)(VkQueue, const VkPresentInfoKHR*))dlsym(lib_vulkan_handle, "vkQueuePresentKHR");
if (!queue_present_original) {
print("Failed to locate vkQueuePresentKHR\n");
} else {
print("vkQueuePresentKHR located at %p\n", queue_present_original);
}
rv = funchook_prepare(funchook, (void**)&queue_present_original, (void*)queue_present_hook);
if (rv != 0) {
}
*/
//dlclose(lib_vulkan_handle);
// Misc static variables and hookable things
unsigned long func_address_2 = (unsigned long)sigscan_module("client.so", "48 8D 05 ? ? ? ? BA ? ? ? ? 89 10"); // credz: vannie / @clsendmove on github
unsigned int random_seed_eaddr = *(unsigned int*)(func_address_2 + 0x3);
unsigned long func_address_2_next_instruction = (unsigned long)(func_address_2 + 0x7);
random_seed = (uint32_t*)((void*)(func_address_2_next_instruction + random_seed_eaddr));
return;
}
__attribute__((destructor))
void exit() {
// Unhook VMT Functions
if (!write_to_table(client_mode_vtable, 22, (void*)client_mode_create_move_original)) {
print("ClientMode::CreateMove failed to restore hook\n");
}
if (!write_to_table(client_vtable, 21, (void*)client_create_move_original)) {
print("Client::CreateMove failed to restore hook\n");
}
if (!write_to_table(client_mode_vtable, 17, (void*)override_view_original)) {
print("OverrideView failed to restore hook\n");
}
if (!write_to_table(client_mode_vtable, 25, (void*)draw_view_model_original)) {
print("ShouldDrawViewModel failed to restore hook\n");
}
if (!write_to_table(vgui_vtable, 42, (void*)paint_traverse_original)) {
print("PaintTraverse failed to restore hook\n");
}
if (!write_to_table(model_render_vtable, 19, (void*)draw_model_execute_original)) {
print("DrawModelExecute failed to restore hook\n");
}
// Unhook Non-VMT Functions
funchook_uninstall(funchook, 0);
// Unhook SDL
void *lib_sdl_handle = dlopen("/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0", RTLD_LAZY | RTLD_NOLOAD);
if (!restore_sdl_hook(lib_sdl_handle, "SDL_GL_SwapWindow", (void*)swap_window_original)) {
print("Failed to restore SDL_GL_SwapWindow\n");
}
if (!restore_sdl_hook(lib_sdl_handle, "SDL_PollEvent", (void*)poll_event_original)) {
print("Failed to restore SDL_PollEvent\n");
}
dlclose(lib_sdl_handle);
// Fix thirdperson hack still being enabled when not injected
{
Player* localplayer = entity_list->get_localplayer();
localplayer->set_thirdperson(false);
}
// Fix cursor visibility when we've removed/unhooked the menu
if (menu_focused == true)
surface->set_cursor_visible(!menu_focused);
}