From cc5e5ede87ae3b8c58221ce41b1a0b74fd173d1e Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 12 Sep 2026 19:22:29 +0200 Subject: Remove Climb feature; keep bind system for aimbot prep (mouse buttons bindable) --- src/hl2h.cpp | 13 +----- src/hl2h.h | 5 +-- src/menu.cpp | 133 +++++++++++++++++++++-------------------------------------- 3 files changed, 49 insertions(+), 102 deletions(-) diff --git a/src/hl2h.cpp b/src/hl2h.cpp index a4a1a88..c6c0aeb 100644 --- a/src/hl2h.cpp +++ b/src/hl2h.cpp @@ -152,21 +152,11 @@ static void do_move(int seq) { bool onground = (flags & FL_ONGROUND) != 0; bool inwater = (flags & FL_INWATER) != 0; - bool climb_on = feature_active(FEAT_CLIMB); // bind held (or middle mouse when unbound) bool bhop_on = feature_active(FEAT_BHOP); static bool lastground = false; - if (climb_on) { - if (cmd->command_number % 2) { - cmd->buttons &= ~IN_JUMP; - cmd->buttons |= IN_USE; - } else { - cmd->buttons &= ~IN_USE; - cmd->buttons |= IN_JUMP; - } - note_modified(cmd, flags, (float *)(e + g_net.velocity)); - } else if (bhop_on && (cmd->buttons & IN_JUMP)) { + if (bhop_on && (cmd->buttons & IN_JUMP)) { if (inwater && (cmd->buttons & IN_DUCK)) { lastground = onground; return; @@ -282,7 +272,6 @@ static void install_hook() { extern void find_modules(); extern void resolve_netvars(); extern bool find_input_global(); -extern void init_x11(); extern void init_conmsg(); extern void install_menu(); diff --git a/src/hl2h.h b/src/hl2h.h index 68ddab6..88c6c0d 100644 --- a/src/hl2h.h +++ b/src/hl2h.h @@ -125,7 +125,7 @@ float getfov(const QAngle &my_view, const QAngle &aim_ang); // --------------------------------------------------------------------------- // feature ids shared by menu (feature_active) and hl2h.cpp (do_move) -enum FeatureId { FEAT_CLIMB = 0, FEAT_BHOP = 1, FEAT_ABH = 2 }; +enum FeatureId { FEAT_BHOP = 0, FEAT_ABH = 1 }; void note_modified(const CUserCmd *cmd, int flags, const float *vel); CUserCmd *get_usercmd(int seq); void fix_verified_crc(int seq, uint32_t crc); @@ -133,10 +133,7 @@ uint32_t usercmd_checksum(const CUserCmd *c); bool find_input_global(); void resolve_netvars(); void find_modules(); -void install_menu(); void init_conmsg(); -void init_x11(); -bool middle_mouse_down(); bool feature_active(int feature); void outer_draw(); // raw ISurface slot calls used by the PaintTraverseEx hook (hl2h.cpp) diff --git a/src/menu.cpp b/src/menu.cpp index c62db47..6dccf1c 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -26,55 +26,6 @@ void init_conmsg() { if (h) g_conmsg = (decltype(g_conmsg))dlsym(h, "_Z6ConMsgPKcz"); } - -// --------------------------------------------------------------------------- -// X11 middle mouse (for climb feature) -// --------------------------------------------------------------------------- - -static struct { - void *handle = nullptr; - void *dpy = nullptr; - int (*query)(void *, unsigned long, unsigned long *, unsigned long *, int *, - int *, int *, int *, unsigned int *) = nullptr; - int (*default_screen)(void *) = nullptr; - unsigned long (*root_window)(void *, int) = nullptr; - bool ok = false; -} g_x11; - -static constexpr unsigned int BUTTON2_MASK = 1u << 9; // X11 Button2Mask - -void init_x11() { - g_x11.handle = dlopen("libX11.so.6", RTLD_LAZY | RTLD_GLOBAL); - if (!g_x11.handle) - return; - g_x11.query = (decltype(g_x11.query))dlsym(g_x11.handle, "XQueryPointer"); - g_x11.default_screen = - (decltype(g_x11.default_screen))dlsym(g_x11.handle, "XDefaultScreen"); - g_x11.root_window = - (decltype(g_x11.root_window))dlsym(g_x11.handle, "XRootWindow"); - auto open_display = - (void *(*)(const char *))dlsym(g_x11.handle, "XOpenDisplay"); - if (!g_x11.query || !g_x11.default_screen || !g_x11.root_window || - !open_display) - return; - g_x11.dpy = open_display(nullptr); - if (g_x11.dpy) - g_x11.ok = true; -} - -bool middle_mouse_down() { - if (!g_x11.ok) - return false; - unsigned long root = - g_x11.root_window(g_x11.dpy, g_x11.default_screen(g_x11.dpy)); - unsigned long rret, cret; - int rx, ry, wx, wy; - unsigned int mask = 0; - if (!g_x11.query(g_x11.dpy, root, &rret, &cret, &rx, &ry, &wx, &wy, &mask)) - return false; - return (mask & BUTTON2_MASK) != 0; -} - // --------------------------------------------------------------------------- // menu tree structure // --------------------------------------------------------------------------- @@ -100,15 +51,11 @@ struct FeatureState { int bind; // SDL scancode, 0 = none }; -static FeatureState g_climb{true, 0}; static FeatureState g_bhop{true, 0}; static FeatureState g_abh{true, 0}; // tree static MenuNode g_root{NODE_ROOT, "HL2hake", true, 0, {}, nullptr, nullptr, nullptr}; -static MenuNode g_climb_feat{NODE_FEATURE, "Climb", true, 2, {}, nullptr, nullptr, nullptr}; -static MenuNode g_climb_active{NODE_TOGGLE, "Active", false, 0, {}, &g_climb.active, nullptr, nullptr}; -static MenuNode g_climb_bind{NODE_BIND, "Bind", false, 0, {}, nullptr, &g_climb.bind, "None"}; static MenuNode g_bhop_feat{NODE_FEATURE, "Bunnyhop", true, 1, {}, nullptr, nullptr, nullptr}; static MenuNode g_bhop_active{NODE_TOGGLE, "Active", false, 0, {}, &g_bhop.active, nullptr, nullptr}; static MenuNode g_abh_feat{NODE_FEATURE, "ABH", true, 1, {}, nullptr, nullptr, nullptr}; @@ -123,14 +70,11 @@ bool g_menu_open = false; static bool g_bind_mode = false; // true = waiting for key press static void build_tree() { - g_climb_feat.children[0] = &g_climb_active; - g_climb_feat.children[1] = &g_climb_bind; g_bhop_feat.children[0] = &g_bhop_active; g_abh_feat.children[0] = &g_abh_active; - g_root.children[0] = &g_climb_feat; - g_root.children[1] = &g_bhop_feat; - g_root.children[2] = &g_abh_feat; - g_root.child_count = 3; + g_root.children[0] = &g_bhop_feat; + g_root.children[1] = &g_abh_feat; + g_root.child_count = 2; } static int g_depth[16]; // depth of each visible row (for indentation) @@ -190,7 +134,6 @@ static void config_save() { FILE *f = fopen(config_path().c_str(), "w"); if (!f) return; - fprintf(f, "[climb]\nactive=%d\nbind=%d\n", g_climb.active, g_climb.bind); fprintf(f, "[bhop]\nactive=%d\nbind=%d\n", g_bhop.active, g_bhop.bind); fprintf(f, "[abh]\nactive=%d\nbind=%d\n", g_abh.active, g_abh.bind); fclose(f); @@ -205,9 +148,7 @@ static void config_load() { while (fgets(line, sizeof(line), f)) { line[strcspn(line, "\r\n")] = 0; if (line[0] == '[') { - if (strstr(line, "[climb]")) - cur = &g_climb; - else if (strstr(line, "[bhop]")) + if (strstr(line, "[bhop]")) cur = &g_bhop; else if (strstr(line, "[abh]")) cur = &g_abh; @@ -265,18 +206,42 @@ static const char *scancode_name(int sc) { case 87: return "F1"; case 88: return "F2"; case 89: return "F3"; case 90: return "F4"; case 91: return "F5"; case 92: return "F6"; case 93: return "F7"; case 94: return "F8"; + case 600: return "MouseL"; case 601: return "MouseR"; + case 602: return "MouseM"; case 603: return "Mouse4"; + case 604: return "Mouse5"; default: return scancode_name(0); // "None" for unmapped } } // get a snapshot of key states: returns array of currently-held scancodes -static bool g_prev_key_state[512] = {}; -static bool g_key_down[512] = {}; // true for ONE frame on press +static bool g_prev_key_state[608] = {}; +static bool g_key_down[608] = {}; // true for ONE frame on press // read SDL_GetKeyboardState — the game's own SDL is in-process using SDL_GetKeyboardState_fn = const uint8_t *(*)(int *); static SDL_GetKeyboardState_fn SDL_GetKeyboardState_real = nullptr; +// mouse buttons map to pseudo-scancodes 600..604 +static constexpr int MOUSE_BASE = 600; // 600=L 601=R 602=M 603=X1 604=X2 +using SDL_GetMouseState_fn = unsigned (*)(int *, int *); +static SDL_GetMouseState_fn SDL_GetMouseState_real = nullptr; + +static void poll_mouse() { + if (!SDL_GetMouseState_real) + SDL_GetMouseState_real = + (SDL_GetMouseState_fn)dlsym(RTLD_DEFAULT, "SDL_GetMouseState"); + if (!SDL_GetMouseState_real) + return; + int mx, my; + unsigned mask = SDL_GetMouseState_real(&mx, &my); + for (int b = 0; b < 5; b++) { + bool down = (mask & (1u << b)) != 0; // SDL buttons 1..5 = bits 0..4 + int sc = MOUSE_BASE + b; + g_key_down[sc] = down && !g_prev_key_state[sc]; + g_prev_key_state[sc] = down; + } +} + static void poll_keyboard() { if (!SDL_GetKeyboardState_real) SDL_GetKeyboardState_real = @@ -285,36 +250,32 @@ static void poll_keyboard() { return; int numkeys = 0; const uint8_t *state = SDL_GetKeyboardState_real(&numkeys); - if (!state) - return; - for (int i = 0; i < numkeys && i < 512; i++) { - g_key_down[i] = state[i] && !g_prev_key_state[i]; - g_prev_key_state[i] = state[i]; - } + if (state) + for (int i = 0; i < numkeys && i < MOUSE_BASE; i++) { + g_key_down[i] = state[i] && !g_prev_key_state[i]; + g_prev_key_state[i] = state[i]; + } + poll_mouse(); } static bool key_pressed(int sc) { - return sc >= 0 && sc < 512 && g_key_down[sc]; + return sc >= 0 && sc < MOUSE_BASE + 5 && g_key_down[sc]; } [[maybe_unused]] static bool key_held(int sc) { - return sc >= 0 && sc < 512 && g_prev_key_state[sc]; + return sc >= 0 && sc < MOUSE_BASE + 5 && g_prev_key_state[sc]; } // feature gate queried from hl2h.cpp do_move(): feature must be Active AND -// the activation condition met. Climb activates on its bind key held (falls -// back to the historic middle-mouse behavior when unbound); other features -// activate on their bind key held, or are always-on when unbound. +// its bind key held (always-on when unbound). bool feature_active(int feature) { - static FeatureState *feats[3] = {&g_climb, &g_bhop, &g_abh}; - if (feature < 0 || feature > 2) + static FeatureState *feats[2] = {&g_bhop, &g_abh}; + if (feature < 0 || feature > 1) return false; FeatureState *f = feats[feature]; if (!f->active) return false; - if (f->bind == 0) - return feature == FEAT_CLIMB ? middle_mouse_down() : true; - return key_held(f->bind); + return f->bind == 0 || key_held(f->bind); } static void menu_handle_input() { @@ -333,7 +294,7 @@ static void menu_handle_input() { // menu is open if (g_bind_mode) { // wait for any key press (except Insert, Up, Down, Escape, Enter) - for (int i = 0; i < 512; i++) { + for (int i = 0; i < MOUSE_BASE + 5; i++) { if (!g_key_down[i]) continue; if (i == SCAN_INSERT || i == SCAN_UP || i == SCAN_DOWN || @@ -359,7 +320,7 @@ static void menu_handle_input() { MenuNode *n = g_visible[g_selected]; if (n->bind_ptr) { // clear same bind from other features - FeatureState *features[] = {&g_climb, &g_bhop, &g_abh}; + FeatureState *features[] = {&g_bhop, &g_abh}; for (auto *f : features) if (&f->bind != n->bind_ptr && f->bind == i) f->bind = 0; @@ -549,10 +510,10 @@ void outer_draw() { draw_text(200, 10 + i * 20, "[press key]"); else { /* stable name for current bind */ - static char bn[3][32]; - static FeatureState *feats[] = {&g_climb, &g_bhop, &g_abh}; + static char bn[2][32]; + static FeatureState *feats[] = {&g_bhop, &g_abh}; int fi = 0; - for (int k = 0; k < 3; k++) + for (int k = 0; k < 2; k++) if (n->bind_ptr == &feats[k]->bind) fi = k; snprintf(bn[fi], 32, "[%s]", scancode_name(*n->bind_ptr)); -- cgit v1.2.3