From 5adb4303c8ac4969312fa1afd4f254cba65f6ecc Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 27 Oct 2026 12:43:59 +0100 Subject: Aimbot/silent aim: settable FOV, FOV circle, target locking - Aimbot -> FOV and Silent aim -> FOV values (1..180 deg from the crosshair) - Aimbot -> Show FOV circle: projects the FOV cone through the engine's world->screen transform (hidden for >=89 deg since the boundary is behind the eye) - target lock: while a feature has a bind and the key is held, the acquired target is kept while it is alive and has a visible selected hitbox point; it only re-acquires when the target dies/leaves visibility or the key is released. With bind = None both features keep selecting the nearest target. --- src/esp.cpp | 204 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 153 insertions(+), 51 deletions(-) (limited to 'src/esp.cpp') diff --git a/src/esp.cpp b/src/esp.cpp index 7583f26..945b234 100644 --- a/src/esp.cpp +++ b/src/esp.cpp @@ -274,6 +274,45 @@ static void surf_line(int x0, int y0, int x1, int y1) { vfunc(g_surface, SURF_DrawLine)(g_surface, x0, y0, x1, y1); } +// Screen projection of the aimbot FOV cone boundary, using the engine's own +// world->screen transform so it follows the actual aspect/fov. +static void draw_fov_circle() { + if (!aimbot_fov_circle()) + return; + float fov = (float)aimbot_fov(); + if (fov < 1.0f || fov >= 89.0f) // beyond this the "circle" is behind the eye + return; + float alpha = fov * PI_F / 180.0f; + float yaw = g_cam_view.y * PI_F / 180.0f; + float pitch = g_cam_view.x * PI_F / 180.0f; + Vector fwd{cosf(pitch) * cosf(yaw), cosf(pitch) * sinf(yaw), -sinf(pitch)}; + Vector right{sinf(yaw), -cosf(yaw), 0.0f}; + Vector up{right.y * fwd.z - right.z * fwd.y, + right.z * fwd.x - right.x * fwd.z, + right.x * fwd.y - right.y * fwd.x}; + constexpr int N = 48; + float xs[N], ys[N]; + bool ok[N]; + float ca = cosf(alpha), sa = sinf(alpha); + for (int i = 0; i < N; i++) { + float phi = (2.0f * PI_F * i) / N; + float cp = cosf(phi), sp = sinf(phi); + Vector d{fwd.x * ca + (right.x * cp + up.x * sp) * sa, + fwd.y * ca + (right.y * cp + up.y * sp) * sa, + fwd.z * ca + (right.z * cp + up.z * sp) * sa}; + Vector p{g_cam_eye.x + d.x * 1024.0f, g_cam_eye.y + d.y * 1024.0f, + g_cam_eye.z + d.z * 1024.0f}; + ok[i] = world_to_screen(p, xs[i], ys[i]) && std::isfinite(xs[i]) && + std::isfinite(ys[i]); + } + surf_color(255, 255, 255, 160); + for (int i = 0; i < N; i++) { + int j = (i + 1) % N; + if (ok[i] && ok[j]) + surf_line((int)xs[i], (int)ys[i], (int)xs[j], (int)ys[j]); + } +} + // Draw the parent->child bone links. Bone snapshots are world-space matrices // from SetupBones; project each bone once and reuse for both endpoints. static void draw_skeleton(const EspTarget &t) { @@ -332,11 +371,20 @@ static QAngle angle_to(const Vector &from, const Vector &to) { return a; } -static constexpr float AIM_MAX_FOV = 60.0f; +static int g_aim_lock = -1; +static int g_silent_lock = -1; +void aimbot_reset_lock() { g_aim_lock = -1; } +void silentaim_reset_lock() { g_silent_lock = -1; } + +// max_fov is the angular radius around the crosshair. If lock_idx is non-null +// and valid, that target is kept while it is alive and visible (the "do not +// switch while the bind is held" rule); a fresh acquisition is ranked by angle +// and the nearest visible selected hitbox point. static bool select_aim_target(const QAngle &view, unsigned bone_mask, - bool vischeck, const char *tag, int &out_idx, - Vector &out_point, float &out_fov) { + bool vischeck, float max_fov, const char *tag, + int *lock_idx, int &out_idx, Vector &out_point, + float &out_fov) { out_idx = -1; out_point = {}; out_fov = 0.0f; @@ -352,6 +400,71 @@ static bool select_aim_target(const QAngle &view, unsigned bone_mask, *(int *)((uintptr_t)local_ent + g_net.health) <= 0) return false; + auto try_target = [&](int idx, bool enforce_fov, Vector &pt, + float &fov) -> bool { + if (idx <= 0 || idx == local) + return false; + void *ent = entitylist_get(idx); + if (!ent) + return false; + void *net = entity_networkable(idx); + if (!net) + return false; + const char *cls = entity_class_name(net, nullptr); + if (!cls || !is_npc_class(cls)) + return false; + uintptr_t e = (uintptr_t)ent; + int life = g_net.lifestate >= 0 + ? (int)*(unsigned char *)(e + g_net.lifestate) + : -1; + if (life != LIFE_ALIVE) + return false; + const char *model = entity_model_name(ent); + if (model_is_friendly(model) || model_is_neutral(model)) + return false; + if (!bones_update(idx, ent)) + return false; + Vector pts[32]; + int npoints = aim_points(idx, bone_mask, pts, 32); + float best = 1e9f; + Vector best_pt{}; + for (int i = 0; i < npoints; i++) { + float f = getfov(view, angle_to(g_cam_eye, pts[i])); + if (enforce_fov && f > max_fov) + continue; + if (f >= best) + continue; + if (vischeck && !is_visible(g_cam_eye, pts[i])) + continue; + best = f; + best_pt = pts[i]; + } + if (best > 1e8f) + return false; + pt = best_pt; + fov = best; + return true; + }; + + // Keep the locked target while it is alive and has a visible selected point. + // No FOV limit on a locked target; only acquisition is FOV-limited. + if (lock_idx && *lock_idx >= 0) { + Vector pt; + float f; + if (try_target(*lock_idx, false, pt, f)) { + out_idx = *lock_idx; + out_point = pt; + out_fov = f; + static int lock_logs = 0; + if (lock_logs < 5) { + lock_logs++; + logf("%s: lock idx=%d fov=%.2f", tag, out_idx, f); + } + return true; + } + *lock_idx = -1; + } + using Fn = int (*)(void *); int hi = vfunc(g_iface.entitylist, 6)(g_iface.entitylist); if (hi < 0 || hi > 4096) @@ -397,7 +510,7 @@ static bool select_aim_target(const QAngle &view, unsigned bone_mask, Vector approx{origin.x, origin.y, origin.z + maxz * ((bone_mask & (1u << 1)) ? 0.9f : 0.55f)}; float fov = getfov(view, angle_to(g_cam_eye, approx)); - if (fov >= AIM_MAX_FOV) + if (fov > max_fov) continue; int pos = ncands; @@ -416,57 +529,37 @@ static bool select_aim_target(const QAngle &view, unsigned bone_mask, double now = esp_now(); if (now - last_none >= 2.0) { last_none = now; - logf("%s: no hostile target within %.0f deg", tag, AIM_MAX_FOV); + logf("%s: no hostile target within %.0f deg", tag, max_fov); } return false; } - int best_idx = -1; - Vector best_point{}; - float best_fov = 0.0f; - for (int ci = 0; ci < ncands && best_idx < 0; ci++) { - int idx = cands[ci].idx; - void *ent = entitylist_get(idx); - if (!ent || !bones_update(idx, ent)) + for (int ci = 0; ci < ncands; ci++) { + Vector pt; + float f; + if (!try_target(cands[ci].idx, true, pt, f)) continue; - Vector pts[32]; - int npoints = aim_points(idx, bone_mask, pts, 32); - float aim_fov = 1e9f; - Vector aim_pt{}; - for (int i = 0; i < npoints; i++) { - float f = getfov(view, angle_to(g_cam_eye, pts[i])); - if (f >= aim_fov) - continue; - if (vischeck && !is_visible(g_cam_eye, pts[i])) - continue; - aim_fov = f; - aim_pt = pts[i]; - } - if (aim_fov <= AIM_MAX_FOV && aim_fov < 1e8f) { - best_idx = idx; - best_point = aim_pt; - best_fov = aim_fov; - static int sel_logs = 0; - if (sel_logs < 5) { - sel_logs++; - logf("%s: target idx=%d points=%d fov=%.2f vischeck=%d", tag, idx, - npoints, aim_fov, (int)vischeck); - } + out_idx = cands[ci].idx; + out_point = pt; + out_fov = f; + if (lock_idx) + *lock_idx = out_idx; + static int sel_logs = 0; + if (sel_logs < 5) { + sel_logs++; + logf("%s: target idx=%d fov=%.2f vischeck=%d", tag, out_idx, f, + (int)vischeck); } + return true; } - if (best_idx < 0) { - static double last_vis = 0.0; - double now = esp_now(); - if (now - last_vis >= 2.0) { - last_vis = now; - logf("%s: no visible aim point (vischeck=%d)", tag, (int)vischeck); - } - return false; + + static double last_vis = 0.0; + double now = esp_now(); + if (now - last_vis >= 2.0) { + last_vis = now; + logf("%s: no visible aim point (vischeck=%d)", tag, (int)vischeck); } - out_idx = best_idx; - out_point = best_point; - out_fov = best_fov; - return true; + return false; } bool aimbot_apply(CUserCmd *cmd) { @@ -477,8 +570,12 @@ bool aimbot_apply(CUserCmd *cmd) { int target = -1; Vector point{}; float fov = 0.0f; - if (!select_aim_target(view, bone_mask, aimbot_vischeck_enabled(), "aimbot", - target, point, fov)) + float max_fov = (float)aimbot_fov(); + if (max_fov < 1.0f) max_fov = 1.0f; + if (max_fov > 180.0f) max_fov = 180.0f; + int *lock = feature_has_bind(FEAT_AIMBOT) ? &g_aim_lock : nullptr; + if (!select_aim_target(view, bone_mask, aimbot_vischeck_enabled(), max_fov, + "aimbot", lock, target, point, fov)) return false; QAngle desired = angle_to(g_cam_eye, point); static int want_logs = 0; @@ -548,8 +645,12 @@ bool silent_aim_apply(CUserCmd *cmd) { int target = -1; Vector point{}; float fov = 0.0f; - if (!select_aim_target(view, bone_mask, true, "silentaim", target, point, - fov)) + float max_fov = (float)silentaim_fov(); + if (max_fov < 1.0f) max_fov = 1.0f; + if (max_fov > 180.0f) max_fov = 180.0f; + int *lock = feature_has_bind(FEAT_SILENTAIM) ? &g_silent_lock : nullptr; + if (!select_aim_target(view, bone_mask, true, max_fov, "silentaim", lock, + target, point, fov)) return false; QAngle desired = angle_to(g_cam_eye, point); float np = desired.x; @@ -643,6 +744,7 @@ void esp_draw() { logf("ESP: screen %dx%d", g_scr_w, g_scr_h); if (!g_scr_w) return; } + draw_fov_circle(); esp_collect(engine_get_local_player()); for (int i = 0; i < g_ntargets; i++) { const EspTarget &t = g_targets[i]; -- cgit v1.2.3