From 9fe986306d2d323c2e69a25840a85cacc2c5f855 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Mon, 24 Jul 2023 18:02:05 +0200 Subject: [PATCH] Add different values for cv_esp 0 - Off 1 - 3D Box 2 - Name 3 - 3D Box + Name --- src/cvars.c | 2 +- src/features/esp.c | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cvars.c b/src/cvars.c index 9f942a1..c3d0a1d 100644 --- a/src/cvars.c +++ b/src/cvars.c @@ -11,7 +11,7 @@ DECL_CVAR(chams); bool cvars_init(void) { cv_bhop = REGISTER_CVAR("bhop", "1"); cv_autostrafe = REGISTER_CVAR("autostrafe", "0"); - cv_esp = REGISTER_CVAR("esp", "1"); + cv_esp = REGISTER_CVAR("esp", "3"); cv_chams = REGISTER_CVAR("chams", "1"); return true; diff --git a/src/features/esp.c b/src/features/esp.c index 729a592..3d564dc 100644 --- a/src/features/esp.c +++ b/src/features/esp.c @@ -5,6 +5,14 @@ #include "../include/cvars.h" #include "../include/util.h" +/* For cv_esp */ +enum esp_values { + ESP_OFF = 0, + ESP_BOX = 1, + ESP_NAME = 2, + /* ESP_ALL should be 3 but we can just OR box and name */ +}; + static bool gl_draw3dbox(vec3_t o, int bh, int bw, int lw) { /* * Parameters: @@ -61,7 +69,8 @@ static bool gl_draw3dbox(vec3_t o, int bh, int bw, int lw) { } void esp(void) { - if (!CVAR_ON(esp)) + const int setting = (int)cv_esp->value; + if (setting == ESP_OFF) return; /* Iterate all clients */ @@ -74,15 +83,23 @@ void esp(void) { const int bh = 70; const int bw = 25; - if (!gl_draw3dbox(ent->origin, bh, bw, 1)) + /* If ESP_BOX is enabled, draw it. If it returns false, continue */ + if (setting & ESP_BOX && !gl_draw3dbox(ent->origin, bh, bw, 1)) continue; + /* Rest of the loop is for name esp, if var is not enabled, continue */ + if (!(setting & ESP_NAME)) + continue; + + /* Draw name on top of the player. */ vec3_t top = vec3(ent->origin[0], ent->origin[1], ent->origin[2] + bh); vec2_t s_top; if (!world_to_screen(top, s_top)) continue; + /* TODO: Instead of -5px, center the player name to the player origin. + * I don't know how to get the text size before rendering. */ i_engine->pfnDrawSetTextColor(1, 1, 1); i_engine->pfnDrawConsoleString(s_top[0] - 5, s_top[1] - 2, get_name(ent->index));