summaryrefslogtreecommitdiffstats
path: root/src/overlay.cpp
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-06 16:09:55 +0100
committersalmonik <salmonik@tuta.io>2026-11-06 16:09:55 +0100
commit33f5ed9ef58f26c6b3b52cf605dd4311d658a60d (patch)
treea97254872e465c9107b7ef19695ab56bb076d7e2 /src/overlay.cpp
parentItems: log the usable ammo table once (diff)
downloadhl2h-33f5ed9ef58f26c6b3b52cf605dd4311d658a60d.tar.gz
hl2h-33f5ed9ef58f26c6b3b52cf605dd4311d658a60d.zip
Fix audit findings: crash safety, correctness, rendering, performance
Crash/UB: - gate every hook behind an init-stage flag until config/surface/input are ready - publish module maps as immutable atomic snapshots instead of reallocating shared vectors under unlocked readers - validate the %ebp walk in the RandomSeed/RandomFloat hooks against the stack - bounds-check every RecvTable/RecvProp/string dereference with module_range() - preserve the Itanium vtable header when cloning (client, CInput, model render, studio render) - reject negative usercmd sequence numbers; guard config_load against a null section target; cap the bone parent walk; check mprotect; drop PROT_EXEC on the GOT patch; absorb server.so .bss tail Correctness: - filter dormant entities across ESP, aimbot, triggerbot, melee, items and projectiles (slot self-tested against the local player) - reset the server-health latch per map and only latch on valid model indices - bone cache sized for the 128-target scan; set valid=false on every failure; head_position keeps searching past an invalid bone - vischeck steps past glass by probing until clear, and ignores entities owned by the target (held weapons, bone followers) - aimbot: maxs no longer disables it, AABB-aware FOV prefilter, lock hysteresis, lead point re-checked for FOV and visibility - spread: seed hook arms on the no-spread toggle alone; engine toggle only controls the RandomFloat zeroing - resolve m_hOwnerEntity/m_hOwner; NPC lead velocity from the server entity - vector_angles pitch range, point_ground normal test, underwater jump+duck no longer skips combat, semi-auto press/release edge for synthetic fire - item/projectile markers and blast rings refresh origin per frame while discovery stays at 10 Hz; trajectory uses the real m_DmgRadius and honours the blast-radius toggle Rendering/GUI: - one overlay draw per engine frame (FRAME_RENDER_START boundary), fixing alpha stacking and the speed-graph flicker - clipped lines/outlines and ellipsised text instead of drawing past the content pane or shifting over neighbours - dropdown dismissal consumes the click; hover ignores hidden controls - chams: reset AlphaModulate, reference shared materials once, restore prop tint colour; fonts created once per handle - projection uses Source's 4:3 aspect scaling and roll; screen size refreshed each frame; FOV circle gated on the aim toggles, not the bind Performance: - TTL caches for NPC relation, friendly/neutral and damage class - model names memoised per model index - entity pointer -> index cache for the triggerbot (was a 4096-slot walk/tick) Build: - real Makefile with -MMD dependency tracking, debug/release objects and an always-relink rule; build.sh kept as a thin wrapper
Diffstat (limited to 'src/overlay.cpp')
-rw-r--r--src/overlay.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/overlay.cpp b/src/overlay.cpp
new file mode 100644
index 0000000..2445d95
--- /dev/null
+++ b/src/overlay.cpp
@@ -0,0 +1,140 @@
1// overlay.cpp — the single ISurface access layer.
2#include "hl2h.h"
3#include <ctime>
4
5ISurface *g_surface = nullptr;
6
7// ---------------------------------------------------------------------------
8// per-frame draw budget
9// ---------------------------------------------------------------------------
10
11static bool g_drawn_this_frame = false;
12static double g_frame_mark_at = 0.0;
13
14static double overlay_now() {
15 timespec ts;
16 clock_gettime(CLOCK_MONOTONIC, &ts);
17 return (double)ts.tv_sec + (double)ts.tv_nsec * 1e-9;
18}
19
20void overlay_frame_mark() {
21 g_drawn_this_frame = false;
22 g_frame_mark_at = overlay_now();
23}
24
25bool overlay_should_draw() {
26 if (g_drawn_this_frame && overlay_now() - g_frame_mark_at < 0.10)
27 return false;
28 g_drawn_this_frame = true;
29 return true;
30}
31
32void overlay_color(int r, int g, int b, int a) {
33 if (!g_surface)
34 return;
35 using Fn = void (*)(void *, int, int, int, int);
36 vfunc<Fn>(g_surface, SURF_DrawSetColor)(g_surface, r, g, b, a);
37}
38
39void overlay_fill(int x0, int y0, int x1, int y1) {
40 if (!g_surface)
41 return;
42 using Fn = void (*)(void *, int, int, int, int);
43 vfunc<Fn>(g_surface, SURF_DrawFilledRect)(g_surface, x0, y0, x1, y1);
44}
45
46void overlay_outline_rect(int x0, int y0, int x1, int y1) {
47 if (!g_surface)
48 return;
49 using Fn = void (*)(void *, int, int, int, int);
50 vfunc<Fn>(g_surface, SURF_DrawOutlinedRect)(g_surface, x0, y0, x1, y1);
51}
52
53void overlay_line(int x0, int y0, int x1, int y1) {
54 if (!g_surface)
55 return;
56 using Fn = void (*)(void *, int, int, int, int);
57 vfunc<Fn>(g_surface, SURF_DrawLine)(g_surface, x0, y0, x1, y1);
58}
59
60void overlay_text_font(HFont f) {
61 if (!g_surface)
62 return;
63 using Fn = void (*)(void *, HFont);
64 vfunc<Fn>(g_surface, SURF_DrawSetTextFont)(g_surface, f);
65}
66
67void overlay_text_color(int r, int g, int b, int a) {
68 if (!g_surface)
69 return;
70 using Fn = void (*)(void *, int, int, int, int);
71 vfunc<Fn>(g_surface, SURF_DrawSetTextColor)(g_surface, r, g, b, a);
72}
73
74void overlay_text_pos(int x, int y) {
75 if (!g_surface)
76 return;
77 using Fn = void (*)(void *, int, int);
78 vfunc<Fn>(g_surface, SURF_DrawSetTextPos)(g_surface, x, y);
79}
80
81void overlay_print_text(const wchar_t *text, int count, int draw_type) {
82 if (!g_surface || !text || count <= 0)
83 return;
84 using Fn = void (*)(void *, const wchar_t *, int, int);
85 vfunc<Fn>(g_surface, SURF_DrawPrintText)(g_surface, text, count, draw_type);
86}
87
88HFont overlay_create_font() {
89 if (!g_surface)
90 return 0;
91 using Fn = HFont (*)(void *);
92 return vfunc<Fn>(g_surface, SURF_CreateFont)(g_surface);
93}
94
95bool overlay_add_glyph_set(HFont f, const char *name, int tall, int weight,
96 int blur, int scanlines, int flags, int range_min,
97 int range_max) {
98 if (!g_surface || !name)
99 return false;
100 using Fn = bool (*)(void *, HFont, const char *, int, int, int, int, int, int,
101 int);
102 return vfunc<Fn>(g_surface, SURF_AddGlyphSetToFont)(
103 g_surface, f, name, tall, weight, blur, scanlines, flags, range_min,
104 range_max);
105}
106
107void overlay_screen_size(int &w, int &h) {
108 if (!g_surface)
109 return;
110 using Fn = void (*)(void *, int &, int &);
111 vfunc<Fn>(g_surface, SURF_GetScreenSize)(g_surface, w, h);
112}
113
114void overlay_text_size(HFont f, const wchar_t *text, int &w, int &h) {
115 if (!g_surface || !text)
116 return;
117 using Fn = void (*)(void *, HFont, const wchar_t *, int &, int &);
118 vfunc<Fn>(g_surface, SURF_GetTextSize)(g_surface, f, text, w, h);
119}
120
121int overlay_embedded_panel() {
122 if (!g_surface)
123 return 0;
124 using Fn = int (*)(void *);
125 return vfunc<Fn>(g_surface, SURF_GetEmbeddedPanel)(g_surface);
126}
127
128void overlay_push_make_current(int panel, bool use_insets) {
129 if (!g_surface)
130 return;
131 using Fn = void (*)(void *, int, bool);
132 vfunc<Fn>(g_surface, SURF_PushMakeCurrent)(g_surface, panel, use_insets);
133}
134
135void overlay_pop_make_current(int panel) {
136 if (!g_surface)
137 return;
138 using Fn = void (*)(void *, int);
139 vfunc<Fn>(g_surface, SURF_PopMakeCurrent)(g_surface, panel);
140}