summaryrefslogtreecommitdiffstats
path: root/src/esp.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/esp.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/esp.cpp b/src/esp.cpp
index c0edd2e..78a357c 100644
--- a/src/esp.cpp
+++ b/src/esp.cpp
@@ -29,6 +29,12 @@ static int g_ntargets = 0;
29static int g_scr_w = 0, g_scr_h = 0; 29static int g_scr_w = 0, g_scr_h = 0;
30static bool g_esp_logged = false; 30static bool g_esp_logged = false;
31 31
32// Speed graph: 100 samples at 0.1 s = the last 10 seconds.
33static constexpr int SPEED_SAMPLES = 100;
34static float g_speed_samples[SPEED_SAMPLES] = {};
35static int g_speed_head = 0;
36static double g_speed_last_sample = 0.0;
37
32static double esp_now() { 38static double esp_now() {
33 timespec ts; 39 timespec ts;
34 clock_gettime(CLOCK_MONOTONIC, &ts); 40 clock_gettime(CLOCK_MONOTONIC, &ts);
@@ -332,6 +338,67 @@ static void draw_fov_circle() {
332 } 338 }
333} 339}
334 340
341// Speed graph: 100 samples at 0.1 s = the last 10 seconds; min is 0, max is
342// the window maximum. Small and centered in the lower half of the screen.
343static void speed_graph_sample() {
344 double now = esp_now();
345 if (now - g_speed_last_sample < 0.1)
346 return;
347 g_speed_last_sample = now;
348 float speed = 0.0f;
349 int local = engine_get_local_player();
350 if (local > 0 && g_net.velocity >= 0) {
351 void *ent = entitylist_get(local);
352 if (ent) {
353 const float *v = (const float *)((uintptr_t)ent + g_net.velocity);
354 speed = sqrtf(v[0] * v[0] + v[1] * v[1]);
355 }
356 }
357 g_speed_samples[g_speed_head] = speed;
358 g_speed_head = (g_speed_head + 1) % SPEED_SAMPLES;
359}
360
361static void draw_speed_graph() {
362 if (!esp_option(ESP_OPT_SHOW_SPEEDGRAPH))
363 return;
364 speed_graph_sample();
365
366 float maxv = 0.0f;
367 for (int i = 0; i < SPEED_SAMPLES; i++)
368 if (g_speed_samples[i] > maxv)
369 maxv = g_speed_samples[i];
370 float scale = maxv > 1.0f ? maxv : 1.0f;
371
372 const int w = 240, h = 64;
373 int x = (g_scr_w - w) / 2;
374 int y = (g_scr_h * 7) / 10 - h / 2;
375 if (x < 0) x = 0;
376 if (y < 0) y = 0;
377
378 surf_color(0, 0, 0, 120);
379 surf_rect(1, x, y, x + w, y + h);
380 surf_color(80, 80, 80, 180);
381 surf_rect(0, x, y, x + w, y + h);
382
383 surf_color(0, 255, 200, 220);
384 int px = 0, py = 0;
385 for (int i = 0; i < SPEED_SAMPLES; i++) {
386 int idx = (g_speed_head + i) % SPEED_SAMPLES; // oldest -> newest
387 float v = g_speed_samples[idx];
388 int sx = x + 1 + (i * (w - 2)) / (SPEED_SAMPLES - 1);
389 int sy = y + h - 2 - (int)((v / scale) * (float)(h - 4));
390 if (sy < y + 1) sy = y + 1;
391 if (i > 0)
392 surf_line(px, py, sx, sy);
393 px = sx;
394 py = sy;
395 }
396
397 char label[32];
398 snprintf(label, sizeof(label), "max %d", (int)maxv);
399 draw_text_col(x + 3, y + 2, label, 200, 200, 200);
400}
401
335// Draw the parent->child bone links. Bone snapshots are world-space matrices 402// Draw the parent->child bone links. Bone snapshots are world-space matrices
336// from SetupBones; project each bone once and reuse for both endpoints. 403// from SetupBones; project each bone once and reuse for both endpoints.
337static void draw_skeleton(const EspTarget &t) { 404static void draw_skeleton(const EspTarget &t) {
@@ -844,4 +911,6 @@ void esp_draw() {
844 } 911 }
845 } 912 }
846 } 913 }
914
915 draw_speed_graph();
847} 916}