summaryrefslogtreecommitdiffstats
path: root/src/hl2h.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hl2h.h')
-rw-r--r--src/hl2h.h445
1 files changed, 10 insertions, 435 deletions
diff --git a/src/hl2h.h b/src/hl2h.h
index 541b31b..32d6463 100644
--- a/src/hl2h.h
+++ b/src/hl2h.h
@@ -1,442 +1,17 @@
1#ifndef HL2H_H 1#ifndef HL2H_H
2#define HL2H_H 2#define HL2H_H
3 3
4#include <cstdint> 4// Umbrella header. Declaration groups live in:
5#include <cstdio> 5// core.h — logging, init stage, module snapshots, interfaces, netvars,
6#include <cstring> 6// CUserCmd, engine constants, vector math
7#include <string> 7// settings.h — feature ids, feature state and every user setting
8#include <vector> 8// features.h — cross-module function declarations
9 9// overlay.h — the single ISurface access layer
10#include <dlfcn.h> 10// hooks.h — vtable install/restore
11#include <pthread.h> 11#include "core.h"
12#include <unistd.h> 12#include "features.h"
13
14#include "hooks.h" 13#include "hooks.h"
15#include "overlay.h" 14#include "overlay.h"
15#include "settings.h"
16 16
17// Shared float-precision constant. More digits than a float can hold are
18// rounded at compile time and have no runtime cost; a coarse value would only
19// hurt angular accuracy, never performance.
20constexpr float PI_F = 3.14159265f;
21
22// ---------------------------------------------------------------------------
23// logging
24// ---------------------------------------------------------------------------
25
26void logf(const char *fmt, ...);
27void logd(const char *fmt, ...); // debug-only (HL2H_DEBUG=1)
28
29// ---------------------------------------------------------------------------
30// init readiness
31// ---------------------------------------------------------------------------
32//
33// setup_thread runs detached while the game threads are already live, and some
34// hooks are installed lazily from the game thread. Hooks therefore always stay
35// installed but pass straight through to the original until setup reaches
36// INIT_LIVE, so the game can never observe half-initialised state. INIT_FAILED
37// is terminal: the cheat stays inert instead of half-working.
38enum {
39 INIT_FAILED = -1,
40 INIT_NONE = 0,
41 INIT_INTERFACES = 1, // modules + interfaces + netvars resolved
42 INIT_READY = 2, // config loaded, ISurface/fonts resolved
43 INIT_LIVE = 3 // hooks may run their bodies
44};
45void init_set_stage(int stage);
46int init_stage(); // acquire load
47inline bool init_live() { return init_stage() == INIT_LIVE; }
48
49// Clone a vtable into a new array, preserving the Itanium ABI header at
50// [-2]/[-1] (offset-to-top and typeinfo) so RTTI on the hooked object still
51// works. Returns the slot-0 pointer to install (i.e. the clone + 2).
52void **vtable_clone(void *iface, size_t slots);
53
54// ---------------------------------------------------------------------------
55// on-screen toasts
56// ---------------------------------------------------------------------------
57
58enum ToastLevel { TOAST_INFO = 0, TOAST_WARN, TOAST_ERROR };
59void toastf(int level, const char *fmt, ...);
60bool gui_toasts_active();
61void gui_draw_toasts();
62
63// ---------------------------------------------------------------------------
64// module discovery
65// ---------------------------------------------------------------------------
66
67struct Module {
68 struct Range {
69 uintptr_t lo, hi;
70 bool file;
71 };
72 std::vector<Range> ranges;
73 std::string path;
74 bool valid() const { return !ranges.empty(); }
75 bool contains(uintptr_t p) const {
76 for (auto &r : ranges)
77 if (p >= r.lo && p < r.hi)
78 return true;
79 return false;
80 }
81};
82// Immutable module snapshots. A reader gets a reference that stays valid for
83// the whole process: find_modules() publishes a new snapshot instead of
84// mutating the old one, and retired snapshots are intentionally never freed, so
85// a concurrent refresh can never invalidate a reference already in use.
86const Module &mod_client();
87const Module &mod_engine();
88const Module &mod_server();
89
90// True only when the whole byte range [p, p+n) lies inside one known module
91// range. Use before dereferencing pointers read out of engine memory.
92bool module_range(uintptr_t p, size_t n);
93
94// ---------------------------------------------------------------------------
95// game interfaces
96// ---------------------------------------------------------------------------
97
98using CreateInterfaceFn = void *(*)(const char *, int *);
99
100struct GameInterfaces {
101 void *client = nullptr;
102 void *entitylist = nullptr;
103 void *engine = nullptr;
104 void *modelinfo = nullptr; // IVModelInfoClient006 (model index -> model name)
105 void *engineserver = nullptr; // IVEngineServer021 (edict access, incl. server entities)
106 void *debugoverlay = nullptr; // IVDebugOverlay003 (engine-accurate world->screen)
107 void *enginetrace = nullptr; // EngineTraceClient003 (world vischeck)
108 void *cvar = nullptr; // VEngineCvar004 (mat_fullbright etc.)
109 void *modelrender = nullptr; // VEngineModel016 (chams)
110 void *renderview = nullptr; // VEngineRenderView014 (alpha/color modulation)
111};
112extern GameInterfaces g_iface;
113
114#define VTABLE(obj) (*(void ***)(obj))
115template <typename Fn> inline Fn vfunc(void *obj, size_t idx) {
116 return reinterpret_cast<Fn>(VTABLE(obj)[idx]);
117}
118
119// ---------------------------------------------------------------------------
120// netvars
121// ---------------------------------------------------------------------------
122struct NetVars {
123 int flags = -1;
124 int velocity = -1;
125 int movetype = -1;
126 int health = -1;
127 int maxhealth = -1;
128 int teamnum = -1;
129 int origin = -1;
130 int viewoffset = -1;
131 int mins = -1;
132 int maxs = -1;
133 int lifestate = -1;
134 int modelindex = -1;
135 int absvelocity = -1; // client C_BaseEntity::m_vecAbsVelocity (prediction)
136 int activeweapon = -1; // client m_hActiveWeapon handle
137 int owner = -1; // client m_hOwnerEntity handle
138 int weapon_owner = -1; // client m_hOwner handle (C_BaseCombatWeapon)
139 int clr_render = -1; // client m_clrRender (entity render colour)
140 int punch = -1; // client m_vecPunchAngle (aim punch)
141 int default_fov = -1; // client m_iDefaultFOV (camera fov)
142 int dmg_radius = -1; // client C_BaseGrenade::m_DmgRadius
143 int my_weapons = -1; // client m_hMyWeapons[48] array base
144 int ammo = -1; // client m_iAmmo[] array base
145 // ponytail: mins/maxs may be absent from some HL2 netvar tables; esp.cpp falls back to h=72
146 bool ok() const { return flags >= 0 && velocity >= 0 && movetype >= 0; }
147 // ponytail: m_iMaxHealth isn't a netvar in HL2 SP; esp.cpp falls back to 100.
148 // m_iHealth only ever updates for players — NPCs are detected via m_lifeState.
149 bool esp_ok() const { return ok() && health >= 0 && teamnum >= 0 && origin >= 0 && viewoffset >= 0; }
150};
151extern NetVars g_net;
152
153// ---------------------------------------------------------------------------
154// CInput
155// ---------------------------------------------------------------------------
156
157extern uintptr_t g_input;
158
159// ---------------------------------------------------------------------------
160// console output
161// ---------------------------------------------------------------------------
162
163extern void (*g_conmsg)(const char *, ...);
164
165// ---------------------------------------------------------------------------
166// CUserCmd
167// ---------------------------------------------------------------------------
168
169struct CUserCmd {
170 void *vtable;
171 int command_number;
172 int tick_count;
173 float viewangles[3];
174 float forwardmove;
175 float sidemove;
176 float upmove;
177 int buttons;
178 uint8_t impulse;
179 int weaponselect;
180 int weaponsubtype;
181 int random_seed;
182 short mousedx;
183 short mousedy;
184 bool hasbeenpredicted;
185};
186
187// ---------------------------------------------------------------------------
188// engine constants
189// ---------------------------------------------------------------------------
190
191enum { IN_ATTACK = 1 << 0, IN_JUMP = 1 << 1, IN_DUCK = 1 << 2, IN_USE = 1 << 5, IN_ATTACK2 = 1 << 11, IN_SPEED = 1 << 17 };
192enum { FL_ONGROUND = 1 << 0, FL_DUCKING = 1 << 1, FL_INWATER = 1 << 9 };
193enum { MOVETYPE_WALK = 2, MOVETYPE_NOCLIP = 8, MOVETYPE_LADDER = 9 };
194
195// ---------------------------------------------------------------------------
196// vector math
197// ---------------------------------------------------------------------------
198
199struct Vector { float x, y, z; };
200struct QAngle { float x, y, z; };
201// camera state captured each CreateMove (used by ESP / future aimbot)
202extern Vector g_cam_eye;
203extern Vector g_cam_view;
204QAngle vector_angles(const Vector &forward);
205Vector angle_forward_vector(const QAngle &angles);
206float getfov(const QAngle &my_view, const QAngle &aim_ang);
207bool aimbot_apply(CUserCmd *cmd);
208bool triggerbot_apply(CUserCmd *cmd);
209bool silent_aim_apply(CUserCmd *cmd);
210bool melee_weapon_active(void *local_ent);
211bool gravity_gun_active(void *local_ent);
212bool melee_aimbot_apply(CUserCmd *cmd, bool gravity);
213bool spread_control_apply(CUserCmd *cmd, void *local_ent);
214int spread_best_seed(int pellets);
215extern int g_spread_pellets;
216enum FeatureId {
217 FEAT_BHOP = 0,
218 FEAT_ABH = 1,
219 FEAT_ESP = 2,
220 FEAT_AIMBOT = 3,
221 FEAT_TRIGGERBOT = 4,
222 FEAT_SILENTAIM = 5,
223 FEAT_JUMPBUG = 6,
224 FEAT_MELEE = 7,
225 FEAT_SPREAD = 8,
226 FEAT_ITEM_ESP = 9,
227 FEAT_FULLBRIGHT = 10,
228 FEAT_WORLD_TINT = 11,
229 FEAT_FOG = 12,
230 FEAT_SKYBOX = 13,
231 FEAT_PROJECTILES = 14,
232 FEAT_CHAMS = 15,
233 FEAT_COUNT = 16
234};
235enum EspOption {
236 ESP_OPT_SHOW_NEUTRAL = 0,
237 ESP_OPT_SHOW_HEALTHBAR = 1,
238 ESP_OPT_SHOW_HEALTHNUM = 2,
239 ESP_OPT_SHOW_NAME = 3,
240 ESP_OPT_SHOW_SKELETON = 4,
241 ESP_OPT_SHOW_BOX = 5,
242 ESP_OPT_SHOW_SPEEDGRAPH = 6,
243 ESP_OPT_DAMAGE_TAGS = 7,
244 ESP_OPT_ALERT = 8,
245 ESP_OPT_WEAPON = 9,
246 ESP_OPT_ARROWS = 10,
247 ESP_OPT_COUNT = 11
248};
249enum AimBone {
250 AIM_BONE_HEAD = 0,
251 AIM_BONE_TORSO,
252 AIM_BONE_LARM,
253 AIM_BONE_RARM,
254 AIM_BONE_LLEG,
255 AIM_BONE_RLEG,
256 AIM_BONE_COUNT
257};
258
259// ---------------------------------------------------------------------------
260// feature state / settings (owned by menu.cpp alongside config)
261// ---------------------------------------------------------------------------
262
263struct FeatureState {
264 bool active;
265 int bind; // SDL scancode, 0 = none (always-on)
266};
267
268extern FeatureState g_bhop, g_abh, g_jumpbug, g_melee, g_spread, g_esp,
269 g_aimbot, g_triggerbot, g_silentaim, g_item_esp, g_fullbright,
270 g_world_tint, g_fog, g_skybox, g_projectiles, g_chams;
271extern bool g_proj_fuse, g_proj_radius, g_proj_traj;
272
273// Chams settings per relationship, and separate visible / through-wall
274// (invisible) material and colour. The viewmodel has a single style.
275struct ChamsGroup {
276 bool vis_on;
277 int vis_mat;
278 int vis_rgb[4]; // r, g, b, a (0..255)
279 bool inv_on;
280 int inv_mat;
281 int inv_rgb[4];
282};
283extern ChamsGroup g_chams_hostile, g_chams_neutral, g_chams_friendly;
284extern bool g_chams_viewmodel;
285extern int g_chams_vm_mat;
286extern int g_chams_vm_rgb[4];
287extern bool g_tint_world_on, g_tint_sky_on, g_tint_prop_on;
288extern int g_tint_world_rgb[3], g_tint_sky_rgb[3], g_tint_prop_rgb[3];
289extern bool g_fog_skybox, g_fog_disable;
290extern int g_fog_rgb[3], g_fog_start, g_fog_end;
291const char *config_file_cstr(const char *name);
292extern bool g_bhop_autostrafe;
293extern bool g_jumpbug_assist;
294extern bool g_spread_no_spread;
295extern bool g_item_health;
296extern bool g_item_ammo;
297extern bool g_item_armor;
298extern bool g_item_weapons;
299extern bool g_item_crates;
300extern bool g_item_distance;
301extern bool g_item_usable;
302extern int g_item_max_dist;
303extern bool g_aim_bones[AIM_BONE_COUNT];
304extern int g_aim_smooth;
305extern bool g_aim_vischeck;
306extern int g_aim_fov;
307extern bool g_aim_fov_circle;
308extern bool g_aim_punch;
309extern bool g_spread_engine;
310extern bool g_auto_crouchjump;
311extern bool g_edge_jump;
312extern int g_fov_camera;
313extern int g_fov_viewmodel;
314extern int g_tonemap;
315extern int g_esp_col_hostile[3];
316extern int g_esp_col_neutral[3];
317extern int g_esp_col_friendly[3];
318extern bool g_esp_opt[ESP_OPT_COUNT];
319
320const char *scancode_name(int sc);
321void config_save();
322void config_reload();
323void config_reset_defaults();
324const char *config_path_cstr();
325
326// ---------------------------------------------------------------------------
327// cross-file declarations
328// ---------------------------------------------------------------------------
329void note_modified(const CUserCmd *cmd, int flags, const float *vel);
330CUserCmd *get_usercmd(int seq);
331void input_clear_mouse_states();
332void fix_verified_crc(int seq, uint32_t crc);
333uint32_t usercmd_checksum(const CUserCmd *c);
334bool find_input_global();
335void resolve_netvars();
336bool console_cmd(const char *cmd);
337bool cvar_set_int(const char *name, int value);
338void fullbright_update();
339void fullbright_invalidate();
340void world_tint_update();
341void world_tint_invalidate();
342void fog_update();
343void fog_invalidate();
344void skybox_update();
345void skybox_invalidate();
346void skybox_reload_image();
347bool resolve_server_netvars();
348int server_entity_health(int idx, int *maxhealth, int *lifestate, void **base_out);
349// Authoritative server velocity; client-side m_vecVelocity is not networked for
350// NPCs. Returns false when the server interface or datamap field is missing.
351bool server_entity_velocity(int idx, Vector *out);
352bool server_set_velocity_z(int idx, float vz);
353int server_active_weapon(int idx);
354int server_npc_relation(int idx, int local_idx);
355bool server_npc_has_follow_target(int idx);
356int server_npc_state(int idx);
357int server_npc_takedamage(int idx);
358int server_player_armor(int idx);
359int server_player_ammo(int idx, int type);
360uint32_t server_player_weapon(int idx, int slot);
361float server_grenade_detonate(int idx);
362float server_grenade_radius(int idx);
363int server_grenade_thrower(int idx);
364int server_item_juice(int idx);
365int server_entity_count();
366void *server_entity_base(int idx);
367const char *server_entity_classname(int idx);
368bool server_trigger_info(int idx, char *map, size_t mapn, Vector &mins,
369 Vector &maxs);
370int server_npc_turret_flags(int idx);
371int server_model_index(void *base);
372void find_modules();
373bool module_jump_slot(const char *path, const char *name, uintptr_t *vaddr,
374 uintptr_t *bias);
375void init_conmsg();
376bool feature_active(int feature); // enabled AND bind held (or unbound)
377bool feature_enabled(int feature); // enabled, regardless of bind
378bool feature_has_bind(int feature);
379bool feature_bind_held(int feature);
380bool esp_option(int opt);
381bool bhop_autostrafe_enabled();
382bool jumpbug_assist_enabled();
383bool spread_no_spread_enabled();
384bool spread_engine_enabled();
385bool aim_punch_enabled();
386unsigned aimbot_bone_mask();
387int aimbot_smooth_step();
388bool aimbot_vischeck_enabled();
389int aimbot_fov();
390bool aimbot_fov_circle();
391void aimbot_reset_lock();
392void silentaim_reset_lock();
393void *entitylist_get(int idx);
394bool esp_is_npc_index(int idx);
395bool esp_is_viewmodel_index(int idx);
396int esp_npc_relation(int idx);
397void *world_find_material(const char *name);
398void chams_init();
399void chams_preload();
400int engine_get_local_player();
401void draw_text_col(int x, int y, const char *s, int r, int g, int b);
402void draw_text_small_col(int x, int y, const char *s, int r, int g, int b);
403void esp_draw();
404void esp_draw_fov_circle(); // aimbot cone, independent of the ESP toggle
405void esp_reset_session(); // map change / respawn: clear per-map latches
406void esp_draw_items();
407void esp_draw_projectiles();
408void prop_tint_update();
409void studio_props_init();
410bool world_to_screen(const Vector &w, float &sx, float &sy);
411void set_silent_restore(const QAngle &angles);
412bool is_visible(const Vector &eye, const Vector &point,
413 void *self = nullptr, void *target = nullptr);
414void *trace_entity(const Vector &start, const Vector &end, void *ignore);
415bool trace_solid_segment(const Vector &start, const Vector &end, void *ignore,
416 Vector &out_end, Vector &out_normal);
417float ground_distance(const Vector &origin, void *ignore, float max_dist);
418bool point_ground(const Vector &point, void *ignore);
419
420// bones.cpp — client-side animated skeleton / hitbox access (see there)
421bool bones_update(int idx, void *ent);
422int bones_count(int idx);
423int bone_find(int idx, const char *name);
424int bone_parent(int idx, int bone);
425bool bone_pos(int idx, int bone, Vector &out);
426bool bone_is_skeleton_core(int idx, int bone);
427int bone_nearest_core_parent(int idx, int bone);
428bool bones_is_humanoid(int idx);
429bool hitbox_center(int idx, const char *hitbox_name, Vector &out);
430void bones_clear();
431bool head_position(int idx, Vector &out);
432int aim_points(int idx, unsigned group_mask, Vector *out, int max);
433
434void outer_draw();
435void gui_handle_input();
436void gui_draw();
437bool gui_is_open();
438bool gui_bind_capture_active();
439QAngle gui_frozen_view();
440void gui_config_init();
441void gui_config_write(FILE *f);
442#endif 17#endif