summaryrefslogtreecommitdiffstats
path: root/src/hl2h.cpp
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-28 12:24:10 +0100
committersalmonik <salmonik@tuta.io>2026-10-28 12:24:10 +0100
commit16546e5818408f35adc60c2d937cf4541ff7840a (patch)
tree19c405c2c226e69f082d9465f9325c67bb1d0d92 /src/hl2h.cpp
parentItem ESP: recover CPhysicsProp model names from the server (diff)
downloadhl2h-16546e5818408f35adc60c2d937cf4541ff7840a.tar.gz
hl2h-16546e5818408f35adc60c2d937cf4541ff7840a.zip
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.
Diffstat (limited to '')
-rw-r--r--src/hl2h.cpp76
1 files changed, 56 insertions, 20 deletions
diff --git a/src/hl2h.cpp b/src/hl2h.cpp
index 8c6b5db..256b9ab 100644
--- a/src/hl2h.cpp
+++ b/src/hl2h.cpp
@@ -10,21 +10,56 @@
10// logging 10// logging
11// --------------------------------------------------------------------------- 11// ---------------------------------------------------------------------------
12 12
13void logf(const char *fmt, ...) { 13static FILE *g_log = nullptr;
14 va_list ap, ap2; 14static bool g_log_debug = false;
15 va_start(ap, fmt); 15static pthread_mutex_t g_log_mu = PTHREAD_MUTEX_INITIALIZER;
16 va_copy(ap2, ap); 16
17 fprintf(stderr, "hl2hake: "); 17static void log_close() {
18 vfprintf(stderr, fmt, ap2); 18 pthread_mutex_lock(&g_log_mu);
19 fprintf(stderr, "\n"); 19 if (g_log) {
20 fclose(g_log);
21 g_log = nullptr;
22 }
23 pthread_mutex_unlock(&g_log_mu);
24}
25
26// Open once per process and truncate, so /tmp/hl2hake.log only ever contains
27// the current session. HL2H_DEBUG=1 enables logd() noise.
28static void log_open() {
29 const char *dbg = getenv("HL2H_DEBUG");
30 g_log_debug = dbg && *dbg && strcmp(dbg, "0") != 0;
31 g_log = fopen("/tmp/hl2hake.log", "w");
32 if (g_log)
33 setvbuf(g_log, nullptr, _IOLBF, 0);
34 atexit(log_close);
35}
36
37static void log_write(const char *fmt, va_list ap) {
38 char buf[4096];
39 vsnprintf(buf, sizeof(buf), fmt, ap);
40 pthread_mutex_lock(&g_log_mu);
41 fprintf(stderr, "hl2hake: %s\n", buf);
20 fflush(stderr); 42 fflush(stderr);
21 va_end(ap2); 43 if (g_log) {
22 if (FILE *f = fopen("/tmp/hl2hake.log", "a")) { 44 fprintf(g_log, "hl2hake: %s\n", buf);
23 fprintf(f, "hl2hake: "); 45 fflush(g_log);
24 vfprintf(f, fmt, ap);
25 fprintf(f, "\n");
26 fclose(f);
27 } 46 }
47 pthread_mutex_unlock(&g_log_mu);
48}
49
50void logf(const char *fmt, ...) {
51 va_list ap;
52 va_start(ap, fmt);
53 log_write(fmt, ap);
54 va_end(ap);
55}
56
57void logd(const char *fmt, ...) {
58 if (!g_log_debug)
59 return;
60 va_list ap;
61 va_start(ap, fmt);
62 log_write(fmt, ap);
28 va_end(ap); 63 va_end(ap);
29} 64}
30 65
@@ -93,7 +128,7 @@ void note_modified(const CUserCmd *cmd, int flags, const float *vel) {
93 fix_verified_crc(cmd->command_number, usercmd_checksum(cmd)); 128 fix_verified_crc(cmd->command_number, usercmd_checksum(cmd));
94 129
95 if (g_modified_logged < 5) { 130 if (g_modified_logged < 5) {
96 logf("cmd modified: seq=%d flags=0x%X buttons=0x%X fw=%.2f " 131 logd("cmd modified: seq=%d flags=0x%X buttons=0x%X fw=%.2f "
97 "vel=(%.1f,%.1f,%.1f)", 132 "vel=(%.1f,%.1f,%.1f)",
98 cmd->command_number, flags, cmd->buttons, cmd->forwardmove, vel[0], 133 cmd->command_number, flags, cmd->buttons, cmd->forwardmove, vel[0],
99 vel[1], vel[2]); 134 vel[1], vel[2]);
@@ -311,7 +346,7 @@ static bool jumpbug_apply(CUserCmd *cmd, int local, void *ent, int flags,
311 } 346 }
312 if (!jb_tracked) { 347 if (!jb_tracked) {
313 jb_tracked = true; 348 jb_tracked = true;
314 logf("jumpbug: tracking x=%.1f vz=%.1f impact=%.1f", x, vz, impact); 349 logd("jumpbug: tracking x=%.1f vz=%.1f impact=%.1f", x, vz, impact);
315 } 350 }
316 351
317 bool assist = jumpbug_assist_enabled(); 352 bool assist = jumpbug_assist_enabled();
@@ -345,7 +380,7 @@ static bool jumpbug_apply(CUserCmd *cmd, int local, void *ent, int flags,
345 jb_tracked = false; 380 jb_tracked = false;
346 if (jb_logs < 30) { 381 if (jb_logs < 30) {
347 jb_logs++; 382 jb_logs++;
348 logf("jumpbug: trigger x=%.2f drop=%.2f vz=%.1f assist=%d", x, jb_drop, 383 logd("jumpbug: trigger x=%.2f drop=%.2f vz=%.1f assist=%d", x, jb_drop,
349 vz, (int)assist); 384 vz, (int)assist);
350 } 385 }
351 } else { 386 } else {
@@ -357,7 +392,7 @@ static bool jumpbug_apply(CUserCmd *cmd, int local, void *ent, int flags,
357 if (jb_force_next_distance(local, ent, vel, x, JB_TARGET_DIST)) { 392 if (jb_force_next_distance(local, ent, vel, x, JB_TARGET_DIST)) {
358 if (jb_logs < 30) { 393 if (jb_logs < 30) {
359 jb_logs++; 394 jb_logs++;
360 logf("jumpbug: assist duck x=%.2f next=%.2f -> vz=%.1f", x, 395 logd("jumpbug: assist duck x=%.2f next=%.2f -> vz=%.1f", x,
361 next_x, vel[2]); 396 next_x, vel[2]);
362 } 397 }
363 } else { 398 } else {
@@ -391,10 +426,10 @@ static bool jumpbug_apply(CUserCmd *cmd, int local, void *ent, int flags,
391 if (jb_logs < 30) { 426 if (jb_logs < 30) {
392 jb_logs++; 427 jb_logs++;
393 if (assist) 428 if (assist)
394 logf("jumpbug: setup assist x=%.2f drop=%.2f vz=%.1f ok=%d", x, 429 logd("jumpbug: setup assist x=%.2f drop=%.2f vz=%.1f ok=%d", x,
395 jb_drop, vel[2], (int)forced); 430 jb_drop, vel[2], (int)forced);
396 else 431 else
397 logf("jumpbug: setup x=%.2f drop=%.2f pred=%.2f vz=%.1f", x, 432 logd("jumpbug: setup x=%.2f drop=%.2f pred=%.2f vz=%.1f", x,
398 jb_drop, x + JB_DUCK_RAISE - jb_drop, vz); 433 jb_drop, x + JB_DUCK_RAISE - jb_drop, vz);
399 } 434 }
400 } 435 }
@@ -458,7 +493,7 @@ static void hkdSrvRandomSeed(int seed) {
458 if (trace && (bullet_site || logs < 12)) { 493 if (trace && (bullet_site || logs < 12)) {
459 if (logs < 200) { 494 if (logs < 200) {
460 logs++; 495 logs++;
461 logf("srvseed: seed=%d off=0x%lx bullet=%d self=%p local=%d", seed, off, 496 logd("srvseed: seed=%d off=0x%lx bullet=%d self=%p local=%d", seed, off,
462 (int)bullet_site, self, (int)local); 497 (int)bullet_site, self, (int)local);
463 } 498 }
464 } 499 }
@@ -893,6 +928,7 @@ static void *setup_thread(void *) {
893__attribute__((constructor)) static void hl2hake_load() { 928__attribute__((constructor)) static void hl2hake_load() {
894 if (!is_hl2_process()) 929 if (!is_hl2_process())
895 return; 930 return;
931 log_open();
896 logf("loaded (pid %d) build %s %s", getpid(), __DATE__, __TIME__); 932 logf("loaded (pid %d) build %s %s", getpid(), __DATE__, __TIME__);
897 pthread_t t; 933 pthread_t t;
898 if (pthread_create(&t, nullptr, setup_thread, nullptr) == 0) 934 if (pthread_create(&t, nullptr, setup_thread, nullptr) == 0)