// gui.cpp — custom immediate-mode GUI // // Categories, feature cards and controls are wired to the real settings in // menu.cpp. This is the only menu; Insert toggles it. #include "hl2h.h" #include #include #include #include #include #include #include #include #include // --------------------------------------------------------------------------- // ISurface drawing (same binary slots as menu.cpp / esp.cpp) // --------------------------------------------------------------------------- enum { GS_DrawSetColor = 10, GS_DrawFilledRect = 12, GS_DrawOutlinedRect = 14, GS_DrawLine = 15, GS_DrawSetTextFont = 17, GS_DrawSetTextColor = 18, GS_DrawSetTextPos = 20, GS_DrawPrintText = 22, GS_GetScreenSize = 38, GS_CreateFont = 66, GS_AddGlyphSet = 67, GS_GetTextSize = 75 }; static unsigned long g_font_body = 0; static unsigned long g_font_title = 0; static int g_body_h = 15; static int g_title_h = 20; static float g_font_scale = 0.0f; static int g_scr_w = 0, g_scr_h = 0; static void s_color(int r, int g, int b, int a) { using Fn = void (*)(void *, int, int, int, int); vfunc(g_surface, GS_DrawSetColor)(g_surface, r, g, b, a); } static void s_fill(int x0, int y0, int x1, int y1) { using Fn = void (*)(void *, int, int, int, int); vfunc(g_surface, GS_DrawFilledRect)(g_surface, x0, y0, x1, y1); } static void s_outline(int x0, int y0, int x1, int y1) { using Fn = void (*)(void *, int, int, int, int); vfunc(g_surface, GS_DrawOutlinedRect)(g_surface, x0, y0, x1, y1); } static void s_line(int x0, int y0, int x1, int y1) { using Fn = void (*)(void *, int, int, int, int); vfunc(g_surface, GS_DrawLine)(g_surface, x0, y0, x1, y1); } static void s_text_font(unsigned long f) { using Fn = void (*)(void *, unsigned long); vfunc(g_surface, GS_DrawSetTextFont)(g_surface, f); } static void s_text_color(int r, int g, int b, int a) { using Fn = void (*)(void *, int, int, int, int); vfunc(g_surface, GS_DrawSetTextColor)(g_surface, r, g, b, a); } static void s_text_pos(int x, int y) { using Fn = void (*)(void *, int, int); vfunc(g_surface, GS_DrawSetTextPos)(g_surface, x, y); } static void s_print(const wchar_t *text, int n) { using Fn = void (*)(void *, const wchar_t *, int, int); vfunc(g_surface, GS_DrawPrintText)(g_surface, text, n, 0); } static unsigned long s_create_font() { using Fn = unsigned long (*)(void *); return vfunc(g_surface, GS_CreateFont)(g_surface); } static bool s_set_font(unsigned long font, const char *name, int tall, int weight, int flags, int lo, int hi) { using Fn = bool (*)(void *, unsigned long, const char *, int, int, int, int, int, int, int); return vfunc(g_surface, GS_AddGlyphSet)(g_surface, font, name, tall, weight, 0, 0, flags, lo, hi); } static void s_screen(int &w, int &h) { using Fn = void (*)(void *, int &, int &); vfunc(g_surface, GS_GetScreenSize)(g_surface, w, h); } static void s_text_size(unsigned long font, const wchar_t *text, int &w, int &h) { using Fn = void (*)(void *, unsigned long, const wchar_t *, int &, int &); vfunc(g_surface, GS_GetTextSize)(g_surface, font, text, w, h); } // --------------------------------------------------------------------------- // SDL polling // --------------------------------------------------------------------------- using GetKeysFn = const unsigned char *(*)(int *); using GetMouseFn = unsigned int (*)(int *, int *); using ShowCursorFn = int (*)(int); using SetRelativeFn = int (*)(int); using GetRelativeFn = int (*)(void); using AddWatchFn = int (*)(int (*)(void *, void *), void *); using GetTicksFn = unsigned int (*)(void); static GetKeysFn sd_get_keys = nullptr; static GetMouseFn sd_get_mouse = nullptr; static ShowCursorFn sd_show_cursor = nullptr; static SetRelativeFn sd_set_relative = nullptr; static GetRelativeFn sd_get_relative = nullptr; static AddWatchFn sd_add_watch = nullptr; static GetTicksFn sd_get_ticks = nullptr; static bool g_sdl_ready = false; static bool g_sdl_init_tried = false; static std::atomic g_wheel{0}; static int sdl_event_watch(void *, void *event) { if (!event) return 0; const unsigned char *p = (const unsigned char *)event; unsigned int type = *(const unsigned int *)p; if (type == 0x403) { // SDL_MOUSEWHEEL int y = *(const int *)(p + 20); g_wheel.fetch_add(y); } return 0; } static void gui_init_sdl() { if (g_sdl_init_tried) return; g_sdl_init_tried = true; sd_get_keys = (GetKeysFn)dlsym(RTLD_DEFAULT, "SDL_GetKeyboardState"); sd_get_mouse = (GetMouseFn)dlsym(RTLD_DEFAULT, "SDL_GetMouseState"); sd_show_cursor = (ShowCursorFn)dlsym(RTLD_DEFAULT, "SDL_ShowCursor"); sd_set_relative = (SetRelativeFn)dlsym(RTLD_DEFAULT, "SDL_SetRelativeMouseMode"); sd_get_relative = (GetRelativeFn)dlsym(RTLD_DEFAULT, "SDL_GetRelativeMouseMode"); sd_add_watch = (AddWatchFn)dlsym(RTLD_DEFAULT, "SDL_AddEventWatch"); sd_get_ticks = (GetTicksFn)dlsym(RTLD_DEFAULT, "SDL_GetTicks"); g_sdl_ready = sd_get_keys && sd_get_mouse; if (!g_sdl_ready) { logf("gui: SDL polling unavailable"); toastf(TOAST_ERROR, "GUI input unavailable: SDL not found"); return; } if (sd_add_watch) sd_add_watch(&sdl_event_watch, nullptr); } // --------------------------------------------------------------------------- // Layout data (dummy shell) // --------------------------------------------------------------------------- struct Rect { int x, y, w, h; bool has(int px, int py) const { return px >= x && py >= y && px < x + w && py < y + h; } }; struct Col { int r, g, b, a; }; static const Col C_BG{17, 19, 23, 248}; static const Col C_PANEL{27, 30, 36, 248}; static const Col C_SIDEBAR{21, 23, 28, 248}; static const Col C_HEADER{36, 40, 48, 255}; static const Col C_BORDER{70, 76, 88, 255}; static const Col C_TEXT{229, 232, 238, 255}; static const Col C_DIM{150, 156, 168, 255}; static const Col C_ACCENT{255, 145, 64, 255}; static const Col C_ACCENT_DIM{120, 70, 32, 255}; static const Col C_GOOD{86, 210, 135, 255}; enum CtrlKind { CK_TOGGLE, CK_SLIDER, CK_BIND, CK_SECTION, CK_INFO, CK_BUTTON }; enum CtrlAction { ACT_NONE = 0, ACT_RELOAD, ACT_RESET }; struct Ctrl { int kind; const char *label; const char *desc; bool *bval; // CK_TOGGLE int *ival; // CK_SLIDER int min, max; int action; // CK_BUTTON bool zero_unlimited; // slider: value 0 displays as "All" }; struct Card { int cat; FeatureState *feat; // nullptr for non-feature cards (System) const char *title; const char *desc; bool expanded; int c0, n; }; static Ctrl g_ctrls[192]; static int g_nctrl = 0; static Card g_cards[40]; static int g_ncards = 0; static bool g_cards_built = false; static bool g_layout_loaded = false; static bool g_reset_armed = false; static double g_reset_armed_at = 0.0; static char g_config_label[512]; static char g_build_label[128]; static const char *g_cats[] = {"Movement", "Combat", "Visuals", "Weapons", "System"}; static constexpr int CAT_COUNT = 5; static int add_card(int cat, FeatureState *feat, const char *title, const char *desc, bool expanded) { Card &c = g_cards[g_ncards]; c.cat = cat; c.feat = feat; c.title = title; c.desc = desc; c.expanded = expanded; c.c0 = g_nctrl; c.n = 0; return g_ncards++; } static void add_ctrl(int card, int kind, const char *label, const char *desc, int min, int max, bool *bval, int *ival, int action) { int i = g_nctrl++; Ctrl &c = g_ctrls[i]; c.kind = kind; c.label = label; c.desc = desc; c.bval = bval; c.ival = ival; c.min = min; c.max = max; c.action = action; c.zero_unlimited = false; g_cards[card].n++; } static void add_toggle(int card, const char *label, const char *desc, bool *value) { add_ctrl(card, CK_TOGGLE, label, desc, 0, 1, value, nullptr, ACT_NONE); } static void add_slider(int card, const char *label, const char *desc, int min, int max, int *value) { add_ctrl(card, CK_SLIDER, label, desc, min, max, nullptr, value, ACT_NONE); } static void add_section(int card, const char *label) { add_ctrl(card, CK_SECTION, label, nullptr, 0, 0, nullptr, nullptr, ACT_NONE); } static void add_info(int card, const char *label) { add_ctrl(card, CK_INFO, label, nullptr, 0, 0, nullptr, nullptr, ACT_NONE); } static void add_button(int card, const char *label, const char *desc, int action) { add_ctrl(card, CK_BUTTON, label, desc, 0, 0, nullptr, nullptr, action); } static int ctrl_val(const Ctrl &c) { if (c.kind == CK_TOGGLE && c.bval) return *c.bval ? 1 : 0; if (c.kind == CK_SLIDER && c.ival) return *c.ival; return 0; } static void ctrl_set(Ctrl &c, int v) { if (c.kind == CK_TOGGLE && c.bval) { *c.bval = v != 0; config_save(); } else if (c.kind == CK_SLIDER && c.ival) { if (v < c.min) v = c.min; if (v > c.max) v = c.max; if (*c.ival != v) { *c.ival = v; // Slider drags persist on mouse release; discrete changes persist now. } } } static void build_cards() { if (g_cards_built) return; g_cards_built = true; int bhop = add_card(0, &g_bhop, "Bunnyhop", "Automatic jump on landing.", true); add_toggle(bhop, "Uni-directional auto-strafe", "Rotate airborne movement into the velocity.", &g_bhop_autostrafe); add_card(0, &g_abh, "ABH", "Accelerate on the jump tick by facing away " "from the velocity.", true); int jb = add_card(0, &g_jumpbug, "Jumpbug", "Duck+jump when landing would hurt.", true); add_toggle(jb, "Assist timing", "Nudge the final command into the unduck window.", &g_jumpbug_assist); int aim = add_card(1, &g_aimbot, "Aimbot", "Smoothly snap to a hostile target.", true); add_toggle(aim, "Vischeck", "Require world line of sight.", &g_aim_vischeck); add_slider(aim, "FOV", "Maximum angular distance from the crosshair.", 1, 180, &g_aim_fov); add_slider(aim, "Smoothness", "Maximum degrees per tick.", 1, 45, &g_aim_smooth); add_toggle(aim, "Show FOV circle", "Draw the acquisition cone on screen.", &g_aim_fov_circle); add_section(aim, "Bones"); static const char *bone_names[AIM_BONE_COUNT] = { "Head", "Torso", "Left arm", "Right arm", "Left leg", "Right leg"}; static const char *bone_descs[AIM_BONE_COUNT] = { "Aim at the head hitbox.", "Aim at the chest/stomach.", "Include the left arm.", "Include the right arm.", "Include the left leg.", "Include the right leg."}; for (int i = 0; i < AIM_BONE_COUNT; i++) add_toggle(aim, bone_names[i], bone_descs[i], &g_aim_bones[i]); int sil = add_card(1, &g_silentaim, "Silent aim", "Fire at the target without turning the rendered view.", true); add_slider(sil, "FOV", "Maximum angular distance from the crosshair.", 1, 180, &g_silent_fov); add_card(1, &g_triggerbot, "Triggerbot", "Fire when the crosshair is on a hostile.", true); add_card(1, &g_melee, "Melee killbot", "360-degree crowbar silent aim.", true); int esp = add_card(2, &g_esp, "ESP", "Draw hostile NPC information.", true); static const char *esp_names[ESP_OPT_COUNT] = { "Show neutral", "Show healthbar", "Show healthnum", "Show name", "Show skeleton", "Show box", "Show speed graph"}; static const char *esp_descs[ESP_OPT_COUNT] = { "Include neutral wildlife.", "Draw a health bar.", "Draw the numeric health value.", "Draw the model name.", "Draw the animated bone links.", "Draw a bounding box.", "Draw the lower-center speed graph."}; for (int i = 0; i < ESP_OPT_COUNT; i++) add_toggle(esp, esp_names[i], esp_descs[i], &g_esp_opt[i]); int items = add_card(2, &g_item_esp, "Valuable items", "Tag medkits, ammo, armor, weapons and supply crates.", true); add_toggle(items, "Medkits / health", "Tag health kits, health vials and health chargers.", &g_item_health); add_toggle(items, "Ammo", "Tag ammo boxes, crates and grenades.", &g_item_ammo); add_toggle(items, "Armor / suit", "Tag batteries, HEV suits and chargers.", &g_item_armor); add_toggle(items, "Weapons", "Tag world weapon pickups.", &g_item_weapons); add_toggle(items, "Supply crates", "Tag item and beacon crates.", &g_item_crates); add_toggle(items, "Show distance", "Append the distance in units.", &g_item_distance); add_slider(items, "Max distance", "0 = unlimited; otherwise items farther away are hidden.", 0, 10000, &g_item_max_dist); g_ctrls[g_nctrl - 1].zero_unlimited = true; int spread = add_card(3, &g_spread, "Spread control", "Choose a server shot seed that tightens the cone.", true); add_toggle(spread, "No spread", "Override the FireBullets seed with the best offset.", &g_spread_no_spread); int sys = add_card(4, nullptr, "System", "Configuration and maintenance.", true); snprintf(g_config_label, sizeof(g_config_label), "Config: %s", config_path_cstr()); snprintf(g_build_label, sizeof(g_build_label), "Build: %s %s", __DATE__, __TIME__); add_info(sys, g_config_label); add_info(sys, g_build_label); add_button(sys, "Reload config", "Re-read the INI without restarting.", ACT_RELOAD); add_button(sys, "Reset defaults", "Click twice to restore feature defaults; GUI layout kept.", ACT_RESET); } // --------------------------------------------------------------------------- // Window state / input // --------------------------------------------------------------------------- static bool g_open = false; static bool g_was_open = false; static bool g_dragging = false; static int g_drag_dx = 0, g_drag_dy = 0; static int g_win_x = 0, g_win_y = 0, g_win_w = 0, g_win_h = 0; static float g_scale = 1.0f; static bool g_positioned = false; static int g_cat = 0; static float g_scroll = 0.0f; static float g_scroll_max = 0.0f; static bool g_scroll_drag = false; static int g_scroll_drag_dy = 0; static float g_scroll_drag_start = 0.0f; static int g_hover_slider = -1; static int g_slider_drag = -1; static int g_capture_card = -1; static QAngle g_frozen{0, 0, 0}; static int g_mouse_x = 0, g_mouse_y = 0; static bool g_mouse_click = false; static bool g_mouse_down = false; static bool g_mouse_rclick = false; static unsigned int g_prev_mask = 0; static int g_mouse_press = 0; // 1..5 on the frame a button goes down static unsigned char g_prev_keys[512] = {}; static bool g_prev_cursor = true; static bool g_prev_relative = true; static double g_hover_since = 0.0; static const char *g_hover_desc = nullptr; static const char *g_hover_prev = nullptr; static int g_hover_x = 0, g_hover_y = 0; static int g_hover_last_mx = -1, g_hover_last_my = -1; static int S(float v) { return (int)(v * g_scale + 0.5f); } static float now_sec() { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (float)ts.tv_sec + (float)ts.tv_nsec * 1e-9f; } // --------------------------------------------------------------------------- // Toasts (shown even when the GUI is closed) // --------------------------------------------------------------------------- struct Toast { char text[256]; int level; double born; // 0 = waiting for the first draw double ttl; }; static Toast g_toasts[8]; static int g_ntoasts = 0; static pthread_mutex_t g_toast_mu = PTHREAD_MUTEX_INITIALIZER; void toastf(int level, const char *fmt, ...) { char buf[256]; va_list ap; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); pthread_mutex_lock(&g_toast_mu); for (int i = 0; i < g_ntoasts; i++) { if (strcmp(g_toasts[i].text, buf) == 0) { g_toasts[i].level = level; g_toasts[i].born = 0.0; pthread_mutex_unlock(&g_toast_mu); return; } } if (g_ntoasts == 8) { memmove(&g_toasts[0], &g_toasts[1], sizeof(Toast) * 7); g_ntoasts = 7; } Toast &t = g_toasts[g_ntoasts++]; snprintf(t.text, sizeof(t.text), "%s", buf); t.level = level; t.born = 0.0; t.ttl = level == TOAST_ERROR ? 12.0 : level == TOAST_WARN ? 9.0 : 6.0; pthread_mutex_unlock(&g_toast_mu); } bool gui_toasts_active() { pthread_mutex_lock(&g_toast_mu); bool active = g_ntoasts > 0; pthread_mutex_unlock(&g_toast_mu); return active; } static void ensure_fonts() { if (g_font_body && fabsf(g_font_scale - g_scale) < 0.001f) return; g_font_scale = g_scale; g_body_h = (int)(15.0f * g_scale + 0.5f); g_title_h = (int)(20.0f * g_scale + 0.5f); if (g_body_h < 11) g_body_h = 11; if (g_title_h < 15) g_title_h = 15; static const char *families[] = {"Liberation Sans", "DejaVu Sans", "Noto Sans", "Tahoma", "Verdana", "Arial", nullptr}; if (!g_font_body) { for (int i = 0; families[i] && !g_font_body; i++) { unsigned long f = s_create_font(); if (!f) break; if (s_set_font(f, families[i], g_body_h, 400, 0x400, 0x20, 0xFF)) g_font_body = f; } } if (!g_font_title) { for (int i = 0; families[i] && !g_font_title; i++) { unsigned long f = s_create_font(); if (!f) break; if (s_set_font(f, families[i], g_title_h, 400, 0x400, 0x20, 0xFF)) g_font_title = f; } } if (!g_font_title) g_font_title = g_font_body; if (!g_font_body) { logf("gui: no usable body font"); toastf(TOAST_ERROR, "No usable GUI font"); } } static int text_w(const char *s, int tall) { if (!s) return 0; unsigned long font = (g_font_title && tall == g_title_h) ? g_font_title : g_font_body; if (g_surface && font) { wchar_t wbuf[1024]; size_t n = mbstowcs(wbuf, s, 1023); if (n != (size_t)-1) { wbuf[n] = 0; int w = 0, h = 0; s_text_size(font, wbuf, w, h); if (w > 0) return w; } } // Fallback when the surface/font is not ready yet. return (int)(strlen(s) * tall * 0.52f + 0.5f); } static void draw_text_raw(int x, int y, const char *s, unsigned long font, int tall); // Break text into lines that fit max_w. Words that are too wide (paths, long // identifiers) are split by character so nothing is ever truncated. static void wrap_text(const char *text, int max_w, int tall, std::vector &out) { out.clear(); if (!text || !*text || max_w <= 0) return; const char *p = text; std::string line; while (*p) { while (*p == ' ') p++; if (!*p) break; const char *start = p; while (*p && *p != ' ') p++; std::string word(start, (size_t)(p - start)); if (!line.empty()) { std::string cand = line + " " + word; if (text_w(cand.c_str(), tall) <= max_w) { line = cand; continue; } out.push_back(line); line.clear(); } while (text_w(word.c_str(), tall) > max_w && word.size() > 1) { size_t n = word.size(); while (n > 1 && text_w(word.substr(0, n).c_str(), tall) > max_w) n--; out.push_back(word.substr(0, n)); word = word.substr(n); } line = word; } if (!line.empty()) out.push_back(line); } static int wrap_count(const char *text, int max_w, int tall) { std::vector lines; wrap_text(text, max_w, tall, lines); return (int)lines.size(); } static void draw_wrapped(const Rect &clip, int x, int y, const char *text, unsigned long font, int tall, int max_w, const Col &c, int line_gap = 2) { if (!text || !font) return; std::vector lines; wrap_text(text, max_w, tall, lines); s_text_color(c.r, c.g, c.b, c.a); int lh = tall + line_gap; for (size_t i = 0; i < lines.size(); i++) { int ly = y + (int)i * lh; if (ly < clip.y || ly + tall > clip.y + clip.h) continue; draw_text_raw(x, ly, lines[i].c_str(), font, tall); } } static void draw_text_raw(int x, int y, const char *s, unsigned long font, int tall) { (void)tall; if (!s || !font) return; wchar_t w[1024]; size_t n = mbstowcs(w, s, 1023); if (n == (size_t)-1) return; w[n] = 0; s_text_font(font); s_text_pos(x, y); s_print(w, (int)n); } static void text_in(const Rect &clip, int x, int y, const char *s, unsigned long font, int tall, int max_w, const Col &c) { (void)max_w; // callers must size the layout; text is never truncated if (!s || !font) return; if (y < clip.y || y + tall > clip.y + clip.h) return; if (x >= clip.x + clip.w) return; int w = text_w(s, tall); if (x + w > clip.x + clip.w) x = clip.x + clip.w - w; if (x < clip.x) x = clip.x; s_text_color(c.r, c.g, c.b, c.a); draw_text_raw(x, y, s, font, tall); } static Rect clip_rect(const Rect &r, const Rect &clip) { Rect o = r; int x0 = r.x > clip.x ? r.x : clip.x; int y0 = r.y > clip.y ? r.y : clip.y; int x1 = (r.x + r.w) < (clip.x + clip.w) ? (r.x + r.w) : (clip.x + clip.w); int y1 = (r.y + r.h) < (clip.y + clip.h) ? (r.y + r.h) : (clip.y + clip.h); o.x = x0; o.y = y0; o.w = x1 - x0; o.h = y1 - y0; return o; } static void fill(const Rect &r, const Col &c, const Rect *clip = nullptr) { if (r.w <= 0 || r.h <= 0) return; Rect q = clip ? clip_rect(r, *clip) : r; if (q.w <= 0 || q.h <= 0) return; s_color(c.r, c.g, c.b, c.a); s_fill(q.x, q.y, q.x + q.w, q.y + q.h); } static void outline(const Rect &r, const Col &c, const Rect *clip = nullptr) { if (r.w <= 0 || r.h <= 0) return; Rect q = clip ? clip_rect(r, *clip) : r; if (q.w <= 0 || q.h <= 0) return; s_color(c.r, c.g, c.b, c.a); s_outline(q.x, q.y, q.x + q.w, q.y + q.h); } static void line(int x0, int y0, int x1, int y1, const Col &c) { s_color(c.r, c.g, c.b, c.a); s_line(x0, y0, x1, y1); } static void layout() { int w = g_scr_w, h = g_scr_h; if (g_surface) { s_screen(w, h); if (w > 0) g_scr_w = w; if (h > 0) g_scr_h = h; } w = g_scr_w; h = g_scr_h; if (w <= 0 || h <= 0) return; float sc = fminf((float)w / 1920.0f, (float)h / 1080.0f); if (sc < 0.75f) sc = 0.75f; if (sc > 1.5f) sc = 1.5f; g_scale = sc; int nw = S(960.0f), nh = S(620.0f); if (!g_positioned || nw != g_win_w || nh != g_win_h) { if (!g_positioned) { g_win_x = (w - nw) / 2; g_win_y = (h - nh) / 2; g_positioned = true; } g_win_w = nw; g_win_h = nh; } if (g_win_x < 0) g_win_x = 0; if (g_win_y < 0) g_win_y = 0; if (g_win_x + g_win_w > w) g_win_x = w - g_win_w; if (g_win_y + g_win_h > h) g_win_y = h - g_win_h; } static int card_content_w() { return g_win_w - S(190.0f) - S(28.0f); } static int title_max_w() { return card_content_w() - S(210.0f); } static int header_h(const Card &c) { int n = wrap_count(c.title, title_max_w(), g_title_h); if (n < 1) n = 1; int h = n * (g_title_h + S(2.0f)) + S(12.0f); return h < S(36.0f) ? S(36.0f) : h; } static int label_max_w(const Ctrl &c) { if (c.kind == CK_SLIDER) return S(214.0f); return card_content_w() - S(16.0f) - S(110.0f); } static int button_w(const char *label) { int bw = text_w(label, g_body_h) + S(20.0f); if (bw < S(160.0f)) bw = S(160.0f); int maxw = card_content_w() - S(24.0f); if (bw > maxw) bw = maxw; return bw; } static int row_h(const Ctrl &c) { if (c.kind == CK_BUTTON) return S(32.0f); int maxw = (c.kind == CK_INFO || c.kind == CK_SECTION) ? card_content_w() - S(24.0f) : label_max_w(c); int n = wrap_count(c.label, maxw, g_body_h); if (n < 1) n = 1; int h = n * (g_body_h + S(2.0f)) + S(8.0f); int minh = (c.kind == CK_INFO) ? S(20.0f) : (c.kind == CK_SECTION) ? S(24.0f) : S(27.0f); return h < minh ? minh : h; } static int body_h(const Card &c) { if (!c.expanded) return 0; int h = S(6.0f); for (int i = 0; i < c.n; i++) h += row_h(g_ctrls[c.c0 + i]); return h + S(6.0f); } static int card_h(const Card &c) { return header_h(c) + body_h(c) + S(8.0f); } static Rect card_rect(int index, int y) { Card &c = g_cards[index]; int x = g_win_x + S(190.0f) + S(10.0f); int w = g_win_w - S(190.0f) - S(28.0f); return Rect{x, y, w, card_h(c)}; } static bool card_in_category(int i) { return g_cards[i].cat == g_cat; } static int content_height() { int h = S(8.0f); for (int i = 0; i < g_ncards; i++) if (card_in_category(i)) h += card_h(g_cards[i]); return h; } // --------------------------------------------------------------------------- // Input // --------------------------------------------------------------------------- static void close_gui() { if (!g_open) return; g_open = false; g_capture_card = -1; g_dragging = false; g_scroll_drag = false; g_slider_drag = -1; g_reset_armed = false; input_clear_mouse_states(); if (g_sdl_ready) { if (sd_set_relative) sd_set_relative(g_prev_relative ? 1 : 0); if (sd_show_cursor) sd_show_cursor(g_prev_cursor ? 1 : 0); } config_save(); logf("gui: closed"); } static void open_gui() { if (g_open) return; int w = 0, h = 0; if (g_surface) { s_screen(w, h); if (w > 0) g_scr_w = w; if (h > 0) g_scr_h = h; } if (!g_iface.engine) { g_frozen = QAngle{0, 0, 0}; } else { using GetViewFn = void (*)(void *, QAngle *); QAngle v{0, 0, 0}; vfunc(g_iface.engine, 19)(g_iface.engine, &v); g_frozen = v; } if (g_sdl_ready) { if (sd_get_relative) g_prev_relative = sd_get_relative() != 0; if (sd_show_cursor) g_prev_cursor = sd_show_cursor(-1) != 0; if (sd_set_relative) sd_set_relative(0); if (sd_show_cursor) sd_show_cursor(1); } input_clear_mouse_states(); g_open = true; g_capture_card = -1; g_wheel.exchange(0); g_scroll = 0.0f; if (g_cat < 0 || g_cat >= CAT_COUNT) g_cat = 0; logf("gui: opened"); } static void update_mouse() { if (!g_sdl_ready) return; int mx = 0, my = 0; unsigned int mask = sd_get_mouse(&mx, &my); g_mouse_x = mx; g_mouse_y = my; g_mouse_down = (mask & 1u) != 0; g_mouse_press = 0; unsigned int pressed = mask & ~g_prev_mask; for (int b = 0; b < 5; b++) { if (pressed & (1u << b)) { g_mouse_press = b + 1; break; } } g_mouse_click = g_mouse_press == 1; g_mouse_rclick = g_mouse_press == 2; if (g_mouse_x < 0) g_mouse_x = 0; if (g_mouse_y < 0) g_mouse_y = 0; g_prev_mask = mask; } static void handle_capture(const unsigned char *keys) { if (g_capture_card < 0) return; if (!g_open) { g_capture_card = -1; return; } if (keys[41]) { // Esc cancels g_capture_card = -1; return; } Card &card = g_cards[g_capture_card]; if (g_mouse_press >= 1 && g_mouse_press <= 5 && card.feat) { card.feat->bind = 600 + (g_mouse_press - 1); // Consume the click: it must not immediately re-arm capture on the same // bind box. g_mouse_click = false; g_mouse_rclick = false; g_capture_card = -1; config_save(); toastf(TOAST_INFO, "%s bound to %s", card.title, scancode_name(card.feat->bind)); if (!card.feat->active) toastf(TOAST_WARN, "%s is not Active yet", card.title); return; } for (int k = 0; k < 512; k++) { if (!keys[k] || g_prev_keys[k]) continue; if (k == 73) // Insert is reserved for opening/closing the GUI continue; if (card.feat) card.feat->bind = k; g_capture_card = -1; config_save(); if (card.feat) { toastf(TOAST_INFO, "%s bound to %s", card.title, scancode_name(card.feat->bind)); if (!card.feat->active) toastf(TOAST_WARN, "%s is not Active yet", card.title); } return; } } static void handle_mouse_click() { if (!g_mouse_click) return; int mx = g_mouse_x, my = g_mouse_y; // title bar: drag Rect title{g_win_x, g_win_y, g_win_w, S(38.0f)}; if (title.has(mx, my)) { g_dragging = true; g_drag_dx = mx - g_win_x; g_drag_dy = my - g_win_y; return; } // sidebar int side_x = g_win_x; int side_y = g_win_y + S(38.0f); int side_w = S(190.0f); int cat_h = S(34.0f); for (int i = 0; i < CAT_COUNT; i++) { Rect r{side_x, side_y + i * cat_h, side_w, cat_h}; if (r.has(mx, my)) { g_cat = i; g_scroll = 0.0f; config_save(); return; } } // content Rect content{g_win_x + S(190.0f), g_win_y + S(38.0f), g_win_w - S(190.0f), g_win_h - S(38.0f) - S(30.0f)}; if (!content.has(mx, my)) return; // scrollbar int sb_x = content.x + content.w - S(8.0f); if (mx >= sb_x) { if (g_scroll_max > 0.5f) { int thumb_h = (int)((float)content.h * (float)content.h / (float)(content.h + (int)g_scroll_max)); if (thumb_h < S(24.0f)) thumb_h = S(24.0f); int travel = content.h - thumb_h; int thumb_y = content.y + (int)((g_scroll_max > 0.0f) ? (g_scroll / g_scroll_max) * travel : 0); if (my >= thumb_y && my < thumb_y + thumb_h) { g_scroll_drag = true; g_scroll_drag_dy = my - thumb_y; g_scroll_drag_start = g_scroll; } else { float t = (float)(my - content.y) / (float)content.h; g_scroll = t * g_scroll_max; } } return; } int y = content.y - (int)g_scroll + S(8.0f); for (int i = 0; i < g_ncards; i++) { if (!card_in_category(i)) continue; Card &c = g_cards[i]; Rect cr = card_rect(i, y); int ch = card_h(c); int hh = header_h(c); if (my >= cr.y && my < cr.y + ch) { // header if (my < cr.y + hh) { if (c.feat) { Rect active{cr.x + cr.w - S(170.0f), cr.y + (hh - S(18.0f)) / 2, S(18.0f), S(18.0f)}; Rect bind{cr.x + cr.w - S(112.0f), cr.y + (hh - S(22.0f)) / 2, S(100.0f), S(22.0f)}; if (active.has(mx, my)) { c.feat->active = !c.feat->active; config_save(); return; } if (bind.has(mx, my)) { if (mx >= bind.x + bind.w - S(18.0f)) { c.feat->bind = 0; config_save(); toastf(TOAST_INFO, "%s unbound (always-on)", c.title); return; } g_capture_card = i; return; } } c.expanded = !c.expanded; config_save(); return; } // body int by = cr.y + hh + S(6.0f); for (int j = 0; j < c.n; j++) { Ctrl &ct = g_ctrls[c.c0 + j]; int rh = row_h(ct); if (my < by || my >= by + rh) { by += rh; continue; } if (ct.kind == CK_TOGGLE) { ctrl_set(ct, !ctrl_val(ct)); return; } if (ct.kind == CK_SLIDER) { Rect track{cr.x + S(16.0f) + S(230.0f), by + (rh - S(8.0f)) / 2, cr.w - S(16.0f) - S(230.0f) - S(64.0f), S(8.0f)}; if (mx >= track.x && mx < track.x + track.w) { float t = (float)(mx - track.x) / (float)track.w; int v = ct.min + (int)(t * (ct.max - ct.min) + 0.5f); if (v < ct.min) v = ct.min; if (v > ct.max) v = ct.max; ctrl_set(ct, v); g_slider_drag = c.c0 + j; } return; } if (ct.kind == CK_BUTTON) { int bw = button_w(ct.label); Rect b{cr.x + cr.w - S(16.0f) - bw, by + (rh - S(26.0f)) / 2, bw, S(26.0f)}; if (b.has(mx, my)) { if (ct.action == ACT_RELOAD) { config_reload(); logf("gui: config reloaded"); } else if (ct.action == ACT_RESET) { double now = now_sec(); if (g_reset_armed && now - g_reset_armed_at < 3.0) { config_reset_defaults(); g_reset_armed = false; logf("gui: defaults restored"); toastf(TOAST_INFO, "Feature defaults restored"); } else { g_reset_armed = true; g_reset_armed_at = now; } } return; } } return; } } y += ch; } } static void handle_hover() { g_hover_desc = nullptr; g_hover_slider = -1; int mx = g_mouse_x, my = g_mouse_y; Rect content{g_win_x + S(190.0f), g_win_y + S(38.0f), g_win_w - S(190.0f), g_win_h - S(38.0f) - S(30.0f)}; if (!content.has(mx, my)) return; int y = content.y - (int)g_scroll + S(8.0f); for (int i = 0; i < g_ncards; i++) { if (!card_in_category(i)) continue; Card &c = g_cards[i]; Rect cr = card_rect(i, y); int ch = card_h(c); int hh = header_h(c); if (my >= cr.y && my < cr.y + ch) { if (my < cr.y + hh) { if (c.feat) { Rect active{cr.x + cr.w - S(170.0f), cr.y + (hh - S(18.0f)) / 2, S(18.0f), S(18.0f)}; Rect bind{cr.x + cr.w - S(112.0f), cr.y + (hh - S(22.0f)) / 2, S(100.0f), S(22.0f)}; if (active.has(mx, my)) g_hover_desc = "Enable this feature. A bind, when set, must be " "held for it to run."; else if (bind.has(mx, my)) g_hover_desc = (mx >= bind.x + bind.w - S(18.0f)) ? "Clear the bind. An unbound feature is " "always-on." : "Click, then press a key or mouse button. " "Esc cancels."; else g_hover_desc = c.desc; } else { g_hover_desc = c.desc; } return; } int by = cr.y + hh + S(6.0f); for (int j = 0; j < c.n; j++) { Ctrl &ct = g_ctrls[c.c0 + j]; int rh = row_h(ct); if (my >= by && my < by + rh) { g_hover_desc = ct.desc; if (ct.kind == CK_SLIDER) g_hover_slider = c.c0 + j; return; } by += rh; } return; } y += ch; } } void gui_handle_input() { gui_init_sdl(); if (!g_surface) return; build_cards(); layout(); if (g_scr_w <= 0 || g_scr_h <= 0) return; ensure_fonts(); if (!g_sdl_ready) return; int nk = 0; const unsigned char *keys = sd_get_keys(&nk); if (!keys) return; if (nk > 512) nk = 512; update_mouse(); bool toggle_key = (nk > 73) && keys[73]; bool toggle_edge = toggle_key && !g_prev_keys[73]; bool esc = (nk > 41) && keys[41]; bool esc_edge = esc && !g_prev_keys[41]; bool left = (nk > 80) && keys[80]; bool right = (nk > 79) && keys[79]; bool left_edge = left && !g_prev_keys[80]; bool right_edge = right && !g_prev_keys[79]; if (toggle_edge) { if (g_open) close_gui(); else open_gui(); } if (!g_open) { memcpy(g_prev_keys, keys, nk); g_was_open = false; return; } if (esc_edge && g_capture_card >= 0) g_capture_card = -1; // Keep the native cursor free even if the game re-grabs it. if (sd_set_relative) sd_set_relative(0); if (sd_show_cursor) sd_show_cursor(1); if (g_iface.engine) { QAngle f = g_frozen; using SetViewFn = void (*)(void *, QAngle *); vfunc(g_iface.engine, 20)(g_iface.engine, &f); } handle_capture(keys); if (g_dragging) { if (!g_mouse_down) { g_dragging = false; config_save(); } else { g_win_x = g_mouse_x - g_drag_dx; g_win_y = g_mouse_y - g_drag_dy; if (g_win_x < 0) g_win_x = 0; if (g_win_y < 0) g_win_y = 0; if (g_win_x + g_win_w > g_scr_w) g_win_x = g_scr_w - g_win_w; if (g_win_y + g_win_h > g_scr_h) g_win_y = g_scr_h - g_win_h; } } else { handle_mouse_click(); } if (g_slider_drag >= 0) { if (!g_mouse_down) { g_slider_drag = -1; config_save(); } else { Ctrl &ct = g_ctrls[g_slider_drag]; Rect content{g_win_x + S(190.0f), g_win_y + S(38.0f), g_win_w - S(190.0f), g_win_h - S(38.0f) - S(30.0f)}; int x0 = g_win_x + S(190.0f) + S(16.0f) + S(230.0f); int x1 = g_win_x + g_win_w - S(28.0f) - S(64.0f); (void)content; float t = (float)(g_mouse_x - x0) / (float)(x1 - x0); int v = ct.min + (int)(t * (ct.max - ct.min) + 0.5f); ctrl_set(ct, v); } } if (g_scroll_drag) { if (!g_mouse_down) { g_scroll_drag = false; } else { Rect content{g_win_x + S(190.0f), g_win_y + S(38.0f), g_win_w - S(190.0f), g_win_h - S(38.0f) - S(30.0f)}; int thumb_h = (int)((float)content.h * (float)content.h / (float)(content.h + (int)g_scroll_max)); if (thumb_h < S(24.0f)) thumb_h = S(24.0f); int travel = content.h - thumb_h; if (travel > 0) { float t = (float)(g_mouse_y - content.y - g_scroll_drag_dy) / (float)travel; g_scroll = t * g_scroll_max; } } } int wheel = g_wheel.exchange(0); if (wheel != 0) g_scroll -= wheel * S(44.0f); if (left_edge || right_edge) { if (g_hover_slider >= 0) { Ctrl &ct = g_ctrls[g_hover_slider]; ctrl_set(ct, ctrl_val(ct) + (right_edge ? 1 : -1)); config_save(); } } int total = content_height(); Rect content{g_win_x + S(190.0f), g_win_y + S(38.0f), g_win_w - S(190.0f), g_win_h - S(38.0f) - S(30.0f)}; g_scroll_max = (float)(total + S(8.0f) - content.h); if (g_scroll_max < 0.0f) g_scroll_max = 0.0f; if (g_scroll < 0.0f) g_scroll = 0.0f; if (g_scroll > g_scroll_max) g_scroll = g_scroll_max; handle_hover(); { double now = now_sec(); int dx = abs(g_mouse_x - g_hover_last_mx); int dy = abs(g_mouse_y - g_hover_last_my); if (g_hover_desc != g_hover_prev || dx > 2 || dy > 2) { g_hover_prev = g_hover_desc; g_hover_last_mx = g_mouse_x; g_hover_last_my = g_mouse_y; g_hover_since = now; g_hover_x = g_mouse_x; g_hover_y = g_mouse_y; } } memcpy(g_prev_keys, keys, nk); g_was_open = true; } // --------------------------------------------------------------------------- // Draw // --------------------------------------------------------------------------- static void draw_checkbox(int x, int y, bool on) { Rect box{x, y, S(15.0f), S(15.0f)}; fill(box, on ? C_ACCENT : Col{30, 34, 42, 255}); outline(box, C_BORDER); if (on) { line(x + S(3.0f), y + S(8.0f), x + S(7.0f), y + S(12.0f), C_BG); line(x + S(7.0f), y + S(12.0f), x + S(13.0f), y + S(4.0f), C_BG); } } static void draw_slider(const Rect &clip, const Rect &cr, int y, int rh, const Ctrl &ct) { int track_x = cr.x + S(16.0f) + S(230.0f); int track_w = cr.w - S(16.0f) - S(230.0f) - S(64.0f); if (track_w < S(30.0f)) track_w = S(30.0f); int track_y = y + (rh - S(8.0f)) / 2; Rect track{track_x, track_y, track_w, S(8.0f)}; fill(track, Col{38, 42, 50, 255}, &clip); int value = ctrl_val(ct); float t = (ct.max > ct.min) ? (float)(value - ct.min) / (float)(ct.max - ct.min) : 0.0f; int fw = (int)(track_w * t + 0.5f); fill(Rect{track.x, track.y, fw, track.h}, C_ACCENT_DIM, &clip); int kx = track.x + fw - S(4.0f); fill(Rect{kx, track.y - S(4.0f), S(8.0f), S(16.0f)}, C_ACCENT, &clip); char val[32]; if (ct.zero_unlimited && value == 0) snprintf(val, sizeof(val), "All"); else snprintf(val, sizeof(val), "%d", value); text_in(clip, cr.x + cr.w - S(52.0f), y + (rh - g_body_h) / 2, val, g_font_body, g_body_h, 0, C_TEXT); } static void draw_card(const Rect &clip, int index, int y) { Card &c = g_cards[index]; Rect cr = card_rect(index, y); Rect bg = clip_rect(cr, clip); if (bg.w <= 0 || bg.h <= 0) return; fill(cr, C_PANEL, &clip); outline(cr, Col{52, 57, 67, 255}, &clip); int hh = header_h(c); Rect head{cr.x, cr.y, cr.w, hh}; fill(head, C_HEADER, &clip); // expand arrow int ax = cr.x + S(10.0f), ay = cr.y + (hh - S(8.0f)) / 2; if (c.expanded) { line(ax, ay, ax + S(4.0f), ay + S(5.0f), C_DIM); line(ax + S(4.0f), ay + S(5.0f), ax + S(8.0f), ay, C_DIM); } else { line(ax, ay, ax + S(5.0f), ay + S(4.0f), C_DIM); line(ax + S(5.0f), ay + S(4.0f), ax, ay + S(8.0f), C_DIM); } // title (wraps instead of truncating) std::vector title_lines; wrap_text(c.title, title_max_w(), g_title_h, title_lines); int tlh = g_title_h + S(2.0f); int title_h = (int)title_lines.size() * tlh - S(2.0f); int ty = cr.y + (hh - title_h) / 2; draw_wrapped(clip, cr.x + S(24.0f), ty, c.title, g_font_title, g_title_h, title_max_w(), C_TEXT, S(2.0f)); if (c.feat) { bool active = c.feat->active; int active_y = cr.y + (hh - S(18.0f)) / 2; draw_checkbox(cr.x + cr.w - S(170.0f), active_y, active); text_in(clip, cr.x + cr.w - S(148.0f), active_y + (S(18.0f) - g_body_h) / 2, active ? "On" : "Off", g_font_body, g_body_h, 0, active ? C_GOOD : C_DIM); Rect bind{cr.x + cr.w - S(112.0f), cr.y + (hh - S(22.0f)) / 2, S(100.0f), S(22.0f)}; fill(bind, Col{45, 50, 60, 255}, &clip); outline(bind, C_BORDER, &clip); const char *bl = (g_capture_card == index) ? "Press..." : scancode_name(c.feat->bind); text_in(clip, bind.x + S(7.0f), bind.y + (bind.h - g_body_h) / 2, bl, g_font_body, g_body_h, 0, C_TEXT); text_in(clip, bind.x + bind.w - S(16.0f), bind.y + (bind.h - g_body_h) / 2, "x", g_font_body, g_body_h, 0, C_DIM); } if (!c.expanded) return; int by = cr.y + hh + S(6.0f); for (int j = 0; j < c.n; j++) { Ctrl &ct = g_ctrls[c.c0 + j]; int rh = row_h(ct); if (ct.kind == CK_SECTION) { draw_wrapped(clip, cr.x + S(16.0f), by + S(3.0f), ct.label, g_font_body, g_body_h, card_content_w() - S(24.0f), C_ACCENT, S(2.0f)); } else if (ct.kind == CK_INFO) { draw_wrapped(clip, cr.x + S(16.0f), by + S(3.0f), ct.label, g_font_body, g_body_h, card_content_w() - S(24.0f), C_DIM, S(2.0f)); } else if (ct.kind == CK_BUTTON) { int bw = button_w(ct.label); Rect b{cr.x + cr.w - S(16.0f) - bw, by + (rh - S(26.0f)) / 2, bw, S(26.0f)}; fill(b, Col{45, 50, 60, 255}, &clip); outline(b, C_BORDER, &clip); const char *label = ct.label; if (ct.action == ACT_RESET && g_reset_armed) { if (now_sec() - g_reset_armed_at >= 3.0) g_reset_armed = false; else label = "Confirm reset"; } text_in(clip, b.x + S(10.0f), b.y + (b.h - g_body_h) / 2, label, g_font_body, g_body_h, 0, C_TEXT); } else { int maxw = label_max_w(ct); std::vector lines; wrap_text(ct.label, maxw, g_body_h, lines); int lh = g_body_h + S(2.0f); int text_h = (int)lines.size() * lh - S(2.0f); int ly = by + (rh - text_h) / 2; draw_wrapped(clip, cr.x + S(16.0f), ly, ct.label, g_font_body, g_body_h, maxw, C_TEXT, S(2.0f)); if (ct.kind == CK_TOGGLE) { bool on = ctrl_val(ct) != 0; draw_checkbox(cr.x + cr.w - S(31.0f), by + (rh - S(15.0f)) / 2, on); text_in(clip, cr.x + cr.w - S(58.0f), by + (rh - g_body_h) / 2, on ? "On" : "Off", g_font_body, g_body_h, 0, on ? C_GOOD : C_DIM); } else if (ct.kind == CK_SLIDER) { draw_slider(clip, cr, by, rh, ct); } } by += rh; } } static void draw_tooltip() { if (!g_hover_desc || !g_hover_desc[0]) return; float d = now_sec() - (float)g_hover_since; if (d < 0.4f) return; int maxw = S(380.0f); if (maxw > g_scr_w - S(32.0f)) maxw = g_scr_w - S(32.0f); std::vector lines; wrap_text(g_hover_desc, maxw, g_body_h, lines); if (lines.empty()) return; int line_w = 0; for (auto &line : lines) { int w = text_w(line.c_str(), g_body_h); if (w > line_w) line_w = w; } int line_h = g_body_h + S(3.0f); int tw = line_w + S(16.0f); int th = (int)lines.size() * line_h + S(12.0f) - S(3.0f); int x = g_hover_x + S(14.0f); int y = g_hover_y + S(16.0f); if (x + tw > g_scr_w - S(4.0f)) x = g_hover_x - tw - S(10.0f); if (y + th > g_scr_h - S(4.0f)) y = g_hover_y - th - S(10.0f); if (x < S(4.0f)) x = S(4.0f); if (y < S(4.0f)) y = S(4.0f); Rect r{x, y, tw, th}; fill(r, Col{12, 14, 18, 248}); outline(r, C_ACCENT_DIM); s_text_font(g_font_body); s_text_color(C_TEXT.r, C_TEXT.g, C_TEXT.b, C_TEXT.a); for (size_t i = 0; i < lines.size(); i++) draw_text_raw(x + S(7.0f), y + S(6.0f) + (int)i * line_h, lines[i].c_str(), g_font_body, g_body_h); } // --------------------------------------------------------------------------- // Toast drawing // --------------------------------------------------------------------------- void gui_draw_toasts() { if (!g_surface) return; ensure_fonts(); if (!g_font_body || g_scr_w <= 0 || g_scr_h <= 0) return; Toast local[8]; int n = 0; double now = now_sec(); pthread_mutex_lock(&g_toast_mu); for (int i = 0; i < g_ntoasts; i++) { Toast &t = g_toasts[i]; if (t.born == 0.0) t.born = now; if (now - t.born > t.ttl) continue; local[n++] = t; } g_ntoasts = 0; for (int i = 0; i < n; i++) g_toasts[g_ntoasts++] = local[i]; pthread_mutex_unlock(&g_toast_mu); int margin = S(16.0f); int overhead = S(12.0f) * 2 + S(6.0f); // panel padding + accent stripe gap int max_w = S(420.0f); if (max_w + overhead > g_scr_w - margin * 2) max_w = g_scr_w - margin * 2 - overhead; if (max_w < S(60.0f)) max_w = S(60.0f); int y = margin; for (int i = 0; i < n; i++) { const Toast &t = local[i]; float age = (float)(now - t.born); float a = 1.0f; if (age < 0.2f) a = age / 0.2f; else if (age > t.ttl - 0.5f) a = (float)((t.ttl - age) / 0.5); if (a < 0.0f) a = 0.0f; if (a > 1.0f) a = 1.0f; int alpha = (int)(a * 255.0f); std::vector lines; wrap_text(t.text, max_w, g_body_h, lines); int nl = (int)lines.size(); if (nl == 0) continue; int line_w = 0; for (int j = 0; j < nl; j++) { int w = text_w(lines[j].c_str(), g_body_h); if (w > line_w) line_w = w; } int pad = S(12.0f); int line_h = g_body_h + S(4.0f); int panel_w = line_w + pad * 2 + S(6.0f); int panel_h = nl * line_h + pad * 2 - S(4.0f); int x = g_scr_w - margin - panel_w; if (x < margin) x = margin; Col accent = t.level == TOAST_ERROR ? Col{240, 90, 90, 255} : t.level == TOAST_WARN ? Col{255, 200, 80, 255} : C_ACCENT; fill(Rect{x, y, panel_w, panel_h}, Col{16, 18, 22, (int)(235 * a)}); outline(Rect{x, y, panel_w, panel_h}, Col{accent.r, accent.g, accent.b, alpha}); fill(Rect{x, y, S(4.0f), panel_h}, Col{accent.r, accent.g, accent.b, alpha}); s_text_font(g_font_body); s_text_color(C_TEXT.r, C_TEXT.g, C_TEXT.b, alpha); for (int j = 0; j < nl; j++) { s_text_pos(x + pad + S(6.0f), y + pad + j * line_h); wchar_t w[256]; size_t wn = mbstowcs(w, lines[j].c_str(), 255); if (wn == (size_t)-1) continue; w[wn] = 0; s_print(w, (int)wn); } y += panel_h + S(8.0f); } } void gui_draw() { if (!g_open || !g_surface) return; layout(); ensure_fonts(); int w = g_scr_w, h = g_scr_h; if (w <= 0 || h <= 0) return; Rect win{g_win_x, g_win_y, g_win_w, g_win_h}; fill(Rect{win.x + S(6.0f), win.y + S(6.0f), win.w, win.h}, Col{0, 0, 0, 100}); fill(win, C_BG); outline(win, C_BORDER); Rect title{win.x, win.y, win.w, S(38.0f)}; fill(title, Col{31, 35, 42, 255}); fill(Rect{win.x, win.y, S(4.0f), win.h}, C_ACCENT); text_in(win, win.x + S(16.0f), win.y + S(7.0f), "HL2hake", g_font_title, g_title_h, win.w - S(80.0f), C_TEXT); text_in(win, win.x + S(110.0f), win.y + S(10.0f), "Settings", g_font_body, g_body_h, win.w - S(180.0f), C_DIM); Rect side{win.x, win.y + S(38.0f), S(190.0f), win.h - S(38.0f) - S(30.0f)}; fill(side, C_SIDEBAR); int cat_h = S(34.0f); for (int i = 0; i < CAT_COUNT; i++) { Rect r{side.x, side.y + i * cat_h, side.w, cat_h}; if (i == g_cat) { fill(r, Col{42, 45, 54, 255}); fill(Rect{r.x, r.y, S(3.0f), r.h}, C_ACCENT); } text_in(side, r.x + S(18.0f), r.y + S(8.0f), g_cats[i], g_font_body, g_body_h, r.w - S(24.0f), i == g_cat ? C_TEXT : C_DIM); } Rect content{win.x + S(190.0f), win.y + S(38.0f), win.w - S(190.0f), win.h - S(38.0f) - S(30.0f)}; fill(content, Col{20, 22, 27, 255}); Rect clip{content.x + S(4.0f), content.y + S(4.0f), content.w - S(20.0f), content.h - S(8.0f)}; int y = content.y - (int)g_scroll + S(8.0f); for (int i = 0; i < g_ncards; i++) { if (!card_in_category(i)) continue; Card &c = g_cards[i]; int ch = card_h(c); if (y + ch >= clip.y && y <= clip.y + clip.h) draw_card(clip, i, y); y += ch; } // scrollbar if (g_scroll_max > 0.5f) { Rect track{content.x + content.w - S(8.0f), content.y, S(8.0f), content.h}; fill(track, Col{30, 33, 40, 255}); int thumb_h = (int)((float)content.h * (float)content.h / (float)(content.h + (int)g_scroll_max)); if (thumb_h < S(24.0f)) thumb_h = S(24.0f); int travel = content.h - thumb_h; int thumb_y = content.y + (int)((g_scroll_max > 0.0f) ? (g_scroll / g_scroll_max) * travel : 0); fill(Rect{track.x, thumb_y, track.w, thumb_h}, C_ACCENT_DIM); } Rect foot{win.x, win.y + win.h - S(30.0f), win.w, S(30.0f)}; fill(foot, Col{24, 27, 33, 255}); line(foot.x, foot.y, foot.x + foot.w, foot.y, C_BORDER); const char *hint = g_capture_card >= 0 ? "press a key / Esc" : "INS close"; int hint_w = text_w(hint, g_body_h); int hint_x = foot.x + foot.w - hint_w - S(12.0f); if (hint_x < foot.x + S(12.0f)) hint_x = foot.x + S(12.0f); text_in(foot, hint_x, foot.y + S(6.0f), hint, g_font_body, g_body_h, 0, C_DIM); draw_tooltip(); } bool gui_is_open() { return g_open; } bool gui_bind_capture_active() { return g_open && g_capture_card >= 0; } QAngle gui_frozen_view() { return g_frozen; } // --------------------------------------------------------------------------- // [gui] layout persistence // --------------------------------------------------------------------------- static void gui_load_layout() { FILE *f = fopen(config_path_cstr(), "r"); if (!f) return; bool in_gui = false, have_x = false, have_y = false; int x = 0, y = 0, cat = 0; unsigned expanded = 0; bool have_expanded = false; char line[256]; while (fgets(line, sizeof(line), f)) { line[strcspn(line, "\r\n")] = 0; if (line[0] == '[') { in_gui = strstr(line, "[gui]") != nullptr; continue; } if (!in_gui) continue; char *eq = strchr(line, '='); if (!eq) continue; *eq = 0; const char *key = line, *val = eq + 1; if (strcmp(key, "x") == 0) { x = atoi(val); have_x = true; } else if (strcmp(key, "y") == 0) { y = atoi(val); have_y = true; } else if (strcmp(key, "category") == 0) { cat = atoi(val); } else if (strcmp(key, "expanded") == 0) { expanded = (unsigned)strtoul(val, nullptr, 10); have_expanded = true; } } fclose(f); if (have_x && have_y) { g_win_x = x; g_win_y = y; g_positioned = true; } if (cat >= 0 && cat < CAT_COUNT) g_cat = cat; if (have_expanded) { for (int i = 0; i < g_ncards && i < 32; i++) g_cards[i].expanded = (expanded & (1u << i)) != 0; } } void gui_config_init() { build_cards(); if (g_layout_loaded) return; g_layout_loaded = true; gui_load_layout(); } void gui_config_write(FILE *f) { if (!f || !g_cards_built || !g_positioned) return; unsigned expanded = 0; for (int i = 0; i < g_ncards && i < 32; i++) if (g_cards[i].expanded) expanded |= 1u << i; fprintf(f, "[gui]\nx=%d\ny=%d\ncategory=%d\nexpanded=%u\n", g_win_x, g_win_y, g_cat, expanded); } // --------------------------------------------------------------------------- // SDL cursor interposition // --------------------------------------------------------------------------- // The game re-asserts relative mouse mode / hides the cursor every frame. While // the GUI is open, force the opposite so the native cursor stays usable. static int (*real_show_cursor)(int) = nullptr; static int (*real_set_relative)(int) = nullptr; static void (*real_warp_mouse)(void *, int, int) = nullptr; static void (*real_set_grab)(void *, int) = nullptr; extern "C" __attribute__((visibility("default"))) int SDL_ShowCursor(int toggle) { if (!real_show_cursor) real_show_cursor = (int (*)(int))dlsym(RTLD_NEXT, "SDL_ShowCursor"); if (g_open && toggle != -1) { if (real_show_cursor) real_show_cursor(1); return 1; } return real_show_cursor ? real_show_cursor(toggle) : 0; } extern "C" __attribute__((visibility("default"))) int SDL_SetRelativeMouseMode(int enabled) { if (!real_set_relative) real_set_relative = (int (*)(int))dlsym(RTLD_NEXT, "SDL_SetRelativeMouseMode"); if (g_open) { if (real_set_relative) real_set_relative(0); return 0; } return real_set_relative ? real_set_relative(enabled) : 0; } extern "C" __attribute__((visibility("default"))) void SDL_WarpMouseInWindow(void *window, int x, int y) { if (!real_warp_mouse) real_warp_mouse = (void (*)(void *, int, int))dlsym(RTLD_NEXT, "SDL_WarpMouseInWindow"); if (g_open) return; if (real_warp_mouse) real_warp_mouse(window, x, y); } extern "C" __attribute__((visibility("default"))) void SDL_SetWindowGrab(void *window, int grabbed) { if (!real_set_grab) real_set_grab = (void (*)(void *, int))dlsym(RTLD_NEXT, "SDL_SetWindowGrab"); if (g_open) { if (real_set_grab) real_set_grab(window, 0); return; } if (real_set_grab) real_set_grab(window, grabbed); } static void (*real_set_mouse_grab)(void *, int) = nullptr; static void (*real_warp_global)(int, int) = nullptr; extern "C" __attribute__((visibility("default"))) void SDL_SetWindowMouseGrab(void *window, int grabbed) { if (!real_set_mouse_grab) real_set_mouse_grab = (void (*)(void *, int))dlsym(RTLD_NEXT, "SDL_SetWindowMouseGrab"); if (g_open) { if (real_set_mouse_grab) real_set_mouse_grab(window, 0); return; } if (real_set_mouse_grab) real_set_mouse_grab(window, grabbed); } extern "C" __attribute__((visibility("default"))) void SDL_WarpMouseGlobal(int x, int y) { if (!real_warp_global) real_warp_global = (void (*)(int, int))dlsym(RTLD_NEXT, "SDL_WarpMouseGlobal"); if (g_open) return; if (real_warp_global) real_warp_global(x, y); } static unsigned int (*real_get_rel_mouse)(int *, int *) = nullptr; static int (*real_poll_event)(void *) = nullptr; extern "C" __attribute__((visibility("default"))) unsigned int SDL_GetRelativeMouseState(int *x, int *y) { if (!real_get_rel_mouse) real_get_rel_mouse = (unsigned int (*)(int *, int *))dlsym(RTLD_NEXT, "SDL_GetRelativeMouseState"); unsigned int mask = real_get_rel_mouse ? real_get_rel_mouse(x, y) : 0; if (g_open) { if (x) *x = 0; if (y) *y = 0; } return mask; } extern "C" __attribute__((visibility("default"))) int SDL_PollEvent(void *event) { if (!real_poll_event) real_poll_event = (int (*)(void *))dlsym(RTLD_NEXT, "SDL_PollEvent"); if (!real_poll_event) return 0; for (;;) { int r = real_poll_event(event); if (!r) return 0; if (!g_open || !event) return r; unsigned int type = *(unsigned int *)event; if (type != 0x400) // SDL_MOUSEMOTION return r; // Drop motion while the GUI is open: the game must not accumulate look // deltas. The GUI uses absolute SDL_GetMouseState polling. } }