From ccdcd4ad0483b98c9c20bd1304ad062ef8af3a4b Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 26 Oct 2026 16:39:11 +0100 Subject: Aimbot: head-only nearest-to-crosshair with bounded smoothing - select the hostile NPC whose (approximate) head is closest in angle to the crosshair, then refine to its actual head hitbox/bone - aimbot menu feature (Active + Bind, default Mouse5, rebindable via the existing bind chooser); config [aimbot] active/bind - never snap: move at most 5 degrees per tick toward the target, shortest-path yaw, pitch clamped to +/-89, 0.05 degree deadzone; no overshoot/oscillation - fixes the usercmd CRC after modifying viewangles - skip when dead; ignores friendly/neutral entities (crows, citizens, ...) --- src/esp.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'src/esp.cpp') diff --git a/src/esp.cpp b/src/esp.cpp index 34a702a..1cb8b70 100644 --- a/src/esp.cpp +++ b/src/esp.cpp @@ -316,6 +316,123 @@ static void draw_skeleton(const EspTarget &t) { } } +// --------------------------------------------------------------------------- +// aimbot v1: nearest hostile NPC head to the crosshair. +// Bounded smoothing: never snap, never overshoot. Each tick moves at most +// MAX_STEP degrees toward the target and stops inside DEADZONE. +// --------------------------------------------------------------------------- + +static QAngle angle_to(const Vector &from, const Vector &to) { + float dx = to.x - from.x, dy = to.y - from.y, dz = to.z - from.z; + float horiz = sqrtf(dx * dx + dy * dy); + if (horiz < 0.001f) + horiz = 0.001f; + QAngle a{}; + a.x = -atan2f(dz, horiz) * 180.0f / PI_F; // Source: positive pitch = down + a.y = atan2f(dy, dx) * 180.0f / PI_F; + a.z = 0.0f; + return a; +} + +bool aimbot_apply(CUserCmd *cmd) { + if (!g_iface.entitylist || g_net.origin < 0 || g_net.maxs < 0) + return false; + int local = engine_get_local_player(); + if (local <= 0) + return false; + void *local_ent = entitylist_get(local); + if (!local_ent) + return false; + if (g_net.health >= 0 && + *(int *)((uintptr_t)local_ent + g_net.health) <= 0) + return false; + + QAngle view{cmd->viewangles[0], cmd->viewangles[1], 0.0f}; + + using Fn = int (*)(void *); + int hi = vfunc(g_iface.entitylist, 6)(g_iface.entitylist); + if (hi < 0 || hi > 4096) + hi = 4096; + + constexpr float MAX_FOV = 60.0f; // only things near the crosshair + float best_fov = MAX_FOV; + int best_idx = -1; + Vector best_head{}; + + for (int idx = 1; idx <= hi; idx++) { + if (idx == local) + continue; + void *ent = entitylist_get(idx); + if (!ent) + continue; + void *net = entity_networkable(idx); + if (!net) + continue; + const char *cls = entity_class_name(net, nullptr); + if (!cls || !is_npc_class(cls)) + continue; + + uintptr_t e = (uintptr_t)ent; + int life = g_net.lifestate >= 0 + ? (int)*(unsigned char *)(e + g_net.lifestate) + : -1; + if (life != LIFE_ALIVE) + continue; + const char *model = entity_model_name(ent); + if (model_is_friendly(model) || model_is_neutral(model)) + continue; + + float maxz = g_net.maxs >= 0 ? *(float *)(e + g_net.maxs + 8) : 72.0f; + if (!(maxz > 4.0f && maxz < 512.0f)) + maxz = 72.0f; + Vector origin{*(float *)(e + g_net.origin), + *(float *)(e + g_net.origin + 4), + *(float *)(e + g_net.origin + 8)}; + Vector approx{origin.x, origin.y, origin.z + maxz * 0.9f}; + float fov = getfov(view, angle_to(g_cam_eye, approx)); + if (fov >= best_fov) + continue; + best_fov = fov; + best_idx = idx; + best_head = approx; + } + + if (best_idx < 0) + return false; + + // Refine to the actual head hitbox/bone for the chosen target only. + void *best_ent = entitylist_get(best_idx); + if (best_ent && bones_update(best_idx, best_ent)) { + Vector head; + if (head_position(best_idx, head) && + getfov(view, angle_to(g_cam_eye, head)) <= MAX_FOV) + best_head = head; + } + + QAngle desired = angle_to(g_cam_eye, best_head); + float dp = desired.x - cmd->viewangles[0]; + float dy = desired.y - cmd->viewangles[1]; + while (dy > 180.0f) dy -= 360.0f; + while (dy < -180.0f) dy += 360.0f; + + constexpr float DEADZONE = 0.05f; + constexpr float MAX_STEP = 5.0f; + float maxd = fmaxf(fabsf(dp), fabsf(dy)); + if (maxd <= DEADZONE) + return false; + + float scale = (maxd > MAX_STEP) ? (MAX_STEP / maxd) : 1.0f; + float np = cmd->viewangles[0] + dp * scale; + float ny = cmd->viewangles[1] + dy * scale; + if (np > 89.0f) np = 89.0f; + if (np < -89.0f) np = -89.0f; + while (ny > 180.0f) ny -= 360.0f; + while (ny < -180.0f) ny += 360.0f; + cmd->viewangles[0] = np; + cmd->viewangles[1] = ny; + return true; +} + void esp_draw() { if (!g_surface || !g_iface.entitylist || !g_net.esp_ok()) return; if (!g_scr_w) { -- cgit v1.2.3