From 16546e5818408f35adc60c2d937cf4541ff7840a Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 28 Oct 2026 12:24:10 +0100 Subject: Logging: per-session file and debug-gated verbose logs - Open /tmp/hl2hake.log once in the library constructor with "w" so each session starts clean, use line buffering, flush each line, and close it via atexit. No more fopen/fclose per message. - Add logd() for verbose diagnostics, enabled only with HL2H_DEBUG=1. - Move ESP/NPC scans, item-prop/item-classification logs, aimbot/silent-aim/ melee/triggerbot/spread details, jumpbug tracking, bone dumps, netvar dumps, cmd-modified and ground-trace noise to logd(). - Keep logf() for lifecycle, config, warnings/errors, GUI open/close, item category/tagging summaries and item-crate detections so crate debugging works without the ESP stream. - Supply crates now respect the max-distance slider (user change), with the stale comment and CONTEXT updated. - Document HL2H_DEBUG=1 in play.sh and CONTEXT. --- src/esp.cpp | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'src/esp.cpp') diff --git a/src/esp.cpp b/src/esp.cpp index ec3e94b..50549a1 100644 --- a/src/esp.cpp +++ b/src/esp.cpp @@ -208,7 +208,7 @@ static void esp_collect(int local_idx) { g_net.modelindex >= 0 ? *(int *)(e + g_net.modelindex) : -1; int srv_mi = server_model_index(sbase); srv_trusted = (cli_mi == srv_mi); - logf("ESP server check: idx=%d base=%p cli_model=%d srv_model=%d " + logd("ESP server check: idx=%d base=%p cli_model=%d srv_model=%d " "hp=%d maxhp=%d life=%d trusted=%d", idx, sbase, cli_mi, srv_mi, shp, smax, slife, (int)srv_trusted); if (!srv_trusted) @@ -223,7 +223,7 @@ static void esp_collect(int local_idx) { if (dbg && npc && dbg_lines < 40) { dbg_lines++; - logf("ESP npc %d cls=%s life=%d(cli %d) hp=%d(cli %d) maxhp=%d model=%s", + logd("ESP npc %d cls=%s life=%d(cli %d) hp=%d(cli %d) maxhp=%d model=%s", idx, cls, life, cli_life, hp, cli_hp, maxhp, model ? model : "?"); } @@ -266,10 +266,10 @@ static void esp_collect(int local_idx) { } if (dbg) - logf("ESP scan: hi=%d npc_alive=%d targets=%d", hi, npc_alive, g_ntargets); + logd("ESP scan: hi=%d npc_alive=%d targets=%d", hi, npc_alive, g_ntargets); if (g_ntargets && !g_esp_logged) { g_esp_logged = true; - logf("ESP: first targets, %d", g_ntargets); + logd("ESP: first targets, %d", g_ntargets); } } @@ -442,7 +442,7 @@ static void draw_skeleton(const EspTarget &t) { static int logged = 0; if (core_count > 0 && logged < 4) { logged++; - logf("skeleton: idx=%d bones=%d core=%d humanoid=%d", t.idx, n, core_count, + logd("skeleton: idx=%d bones=%d core=%d humanoid=%d", t.idx, n, core_count, (int)bones_is_humanoid(t.idx)); } if (t.friendly) @@ -565,7 +565,7 @@ static bool select_aim_target(const QAngle &view, unsigned bone_mask, static int lock_logs = 0; if (lock_logs < 5) { lock_logs++; - logf("%s: lock idx=%d fov=%.2f", tag, out_idx, f); + logd("%s: lock idx=%d fov=%.2f", tag, out_idx, f); } return true; } @@ -636,7 +636,7 @@ static bool select_aim_target(const QAngle &view, unsigned bone_mask, double now = esp_now(); if (now - last_none >= 2.0) { last_none = now; - logf("%s: no hostile target within %.0f deg", tag, max_fov); + logd("%s: no hostile target within %.0f deg", tag, max_fov); } return false; } @@ -654,7 +654,7 @@ static bool select_aim_target(const QAngle &view, unsigned bone_mask, static int sel_logs = 0; if (sel_logs < 5) { sel_logs++; - logf("%s: target idx=%d fov=%.2f vischeck=%d", tag, out_idx, f, + logd("%s: target idx=%d fov=%.2f vischeck=%d", tag, out_idx, f, (int)vischeck); } return true; @@ -664,7 +664,7 @@ static bool select_aim_target(const QAngle &view, unsigned bone_mask, double now = esp_now(); if (now - last_vis >= 2.0) { last_vis = now; - logf("%s: no visible aim point (vischeck=%d)", tag, (int)vischeck); + logd("%s: no visible aim point (vischeck=%d)", tag, (int)vischeck); } return false; } @@ -688,7 +688,7 @@ bool aimbot_apply(CUserCmd *cmd) { static int want_logs = 0; if (want_logs < 10) { want_logs++; - logf("aimbot: target=%d aim=(%.1f %.1f %.1f) fov=%.2f want=%.2f/%.2f", + logd("aimbot: target=%d aim=(%.1f %.1f %.1f) fov=%.2f want=%.2f/%.2f", target, point.x, point.y, point.z, fov, desired.x, desired.y); } float dp = desired.x - cmd->viewangles[0]; @@ -723,7 +723,7 @@ bool aimbot_apply(CUserCmd *cmd) { static int mod_logs = 0; if (mod_logs < 10) { mod_logs++; - logf("aimbot: view %.2f/%.2f -> %.2f/%.2f", old_pitch, old_yaw, np, ny); + logd("aimbot: view %.2f/%.2f -> %.2f/%.2f", old_pitch, old_yaw, np, ny); } return true; } @@ -785,7 +785,7 @@ bool silent_aim_apply(CUserCmd *cmd) { static int logs = 0; if (logs < 5) { logs++; - logf("silentaim: fire idx=%d fov=%.2f aim=%.2f/%.2f", target, fov, np, ny); + logd("silentaim: fire idx=%d fov=%.2f aim=%.2f/%.2f", target, fov, np, ny); } return true; } @@ -855,7 +855,7 @@ bool melee_weapon_active(void *local_ent) { if (idx != last_idx || crowbar != last_crowbar) { last_idx = idx; last_crowbar = crowbar; - logf("melee: active idx=%d cls=%s model=%s crowbar=%d", idx, + logd("melee: active idx=%d cls=%s model=%s crowbar=%d", idx, cls ? cls : "?", model ? model : "?", (int)crowbar); } return crowbar; @@ -1033,7 +1033,7 @@ bool melee_aimbot_apply(CUserCmd *cmd) { static int logs = 0; if (logs < 10) { logs++; - logf("melee: swing idx=%d dist=%.1f aim=(%.1f %.1f %.1f)", c.idx, + logd("melee: swing idx=%d dist=%.1f aim=(%.1f %.1f %.1f)", c.idx, c.dist, aim.x, aim.y, aim.z); } return true; @@ -1043,7 +1043,7 @@ bool melee_aimbot_apply(CUserCmd *cmd) { double now = esp_now(); if (now - last_none >= 2.0) { last_none = now; - logf("melee: no visible target within %.0f", MELEE_RANGE); + logd("melee: no visible target within %.0f", MELEE_RANGE); } return false; } @@ -1132,7 +1132,7 @@ static void spread_compute() { g_spread_seed12 = window(12, 0); seed(0); - logf("spread: seeds single=%d shotgun8=%d shotgun12=%d", g_spread_seed1, + logd("spread: seeds single=%d shotgun8=%d shotgun12=%d", g_spread_seed1, g_spread_seed8, g_spread_seed12); g_spread_ready = true; } @@ -1182,7 +1182,7 @@ bool spread_control_apply(CUserCmd *cmd, void *local_ent) { static int logs = 0; if (logs < 10) { logs++; - logf("spread: seed=%d pellets=%d", seed, pellets); + logd("spread: seed=%d pellets=%d", seed, pellets); } return true; } @@ -1243,7 +1243,7 @@ bool triggerbot_apply(CUserCmd *cmd) { static int logs = 0; if (logs < 5) { logs++; - logf("triggerbot: fire idx=%d model=%s", idx, model ? model : "?"); + logd("triggerbot: fire idx=%d model=%s", idx, model ? model : "?"); } return true; } @@ -1255,7 +1255,7 @@ void esp_draw() { if (!g_scr_w) { using Fn = void (*)(void *, int &, int &); vfunc(g_surface, SURF_GetScreenSize)(g_surface, g_scr_w, g_scr_h); - logf("ESP: screen %dx%d", g_scr_w, g_scr_h); + logd("ESP: screen %dx%d", g_scr_w, g_scr_h); if (!g_scr_w) return; } draw_fov_circle(); @@ -1323,7 +1323,7 @@ void esp_draw() { static int no_head = 0; if (no_head < 4) { no_head++; - logf("head: idx=%d no head hitbox/bone", t.idx); + logd("head: idx=%d no head hitbox/bone", t.idx); } continue; } @@ -1334,7 +1334,7 @@ void esp_draw() { surf_rect(1, (int)hx - 2, (int)hy - 2, (int)hx + 3, (int)hy + 3); if (!head_logged) { head_logged = true; - logf("bone debug: idx=%d bones=%d head=(%.1f %.1f %.1f)", t.idx, + logd("bone debug: idx=%d bones=%d head=(%.1f %.1f %.1f)", t.idx, bones_count(t.idx), head.x, head.y, head.z); } } @@ -1700,7 +1700,7 @@ static void items_collect(int local_idx) { if (propish && dist < 1500.0f && prop_logs < 40) { prop_logs++; - logf("item prop: idx=%d cls=%s model=%s kind=%d dist=%.0f " + logd("item prop: idx=%d cls=%s model=%s kind=%d dist=%.0f " "origin=(%.0f %.0f %.0f)", idx, cls ? cls : "?", model ? model : "?", kind, dist, origin.x, origin.y, origin.z); @@ -1721,10 +1721,8 @@ static void items_collect(int local_idx) { if (idx == active_idx || item_weapon_is_owned(ent)) continue; } - // Crates are rare and always worth knowing about; the distance slider - // filters the common ammo/health clutter. - if (kind != IK_CRATE && g_item_max_dist > 0 && - dist > (float)g_item_max_dist) + // Distance applies to every tag, including supply crates. + if (g_item_max_dist > 0 && dist > (float)g_item_max_dist) continue; ItemTarget &t = g_item_targets[g_nitems++]; @@ -1734,7 +1732,7 @@ static void items_collect(int local_idx) { snprintf(t.label, sizeof(t.label), "%s", label); if (dbg_lines < 8) { dbg_lines++; - logf("item: idx=%d kind=%d cls=%s model=%s", idx, kind, + logd("item: idx=%d kind=%d cls=%s model=%s", idx, kind, cls ? cls : "?", model ? model : "?"); } } -- cgit v1.2.3