From 57b53d579f32f094c1cdefad62a6224baf270e0d Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 5 Nov 2026 20:32:59 +0100 Subject: Items: server ammo counts and frag-grenade type - local_ammo now prefers the authoritative server m_iAmmo array (header skip) and only falls back to the client netvar array. The client offset can be off by an element, which made "full" checks flicker as other ammo was spent. - Frag grenade pickups were falling through to a generic "Ammo" label with ammo_type=-1, so the usable filter never ran. w_grenade/w_frag/ items/grenade/frag_grenade are now "Frag grenade" and map to m_iAmmo[11] (sk_max_grenade, stock 5); AR2/SMG1 grenade variants map to m_iAmmo[8]. --- src/esp.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/esp.cpp') diff --git a/src/esp.cpp b/src/esp.cpp index 3785107..7ddc86b 100644 --- a/src/esp.cpp +++ b/src/esp.cpp @@ -2419,10 +2419,15 @@ static int item_ammo_type(const char *model) { item_icontains(model, "w_rocket_launcher")) return 7; if (item_icontains(model, "ar2_grenade") || - item_icontains(model, "ammocrate_smg2")) + item_icontains(model, "ammocrate_smg2") || + item_icontains(model, "smg1_grenade") || + item_icontains(model, "smg_grenade")) return 8; if (item_icontains(model, "ammocrate_grenade") || - item_icontains(model, "w_grenade") || item_icontains(model, "w_frag")) + item_icontains(model, "w_grenade") || + item_icontains(model, "w_frag") || + item_icontains(model, "frag_grenade") || + item_icontains(model, "items/grenade")) return 11; if (item_icontains(model, "w_smg1") || item_icontains(model, "w_smg2")) return 3; @@ -2479,12 +2484,19 @@ static int ammo_max(int type) { static int local_ammo(void *local_ent, int type) { if (type < 0 || type >= 32) return -1; + // Prefer the authoritative server array; the client m_iAmmo netvar offset + // can be off by an element, which made "full" counts flicker as other ammo + // was spent. server_player_ammo already skips the CNetworkArray header. + int local = engine_get_local_player(); + if (local > 0 && g_iface.engineserver) { + resolve_server_netvars(); + int s = server_player_ammo(local, type); + if (s >= 0) + return s; + } if (local_ent && g_net.ammo >= 0) return *(int *)((uintptr_t)local_ent + g_net.ammo + type * 4); - // Client array offset may not resolve; the listen-server player has the - // same array in its datamap. - int local = engine_get_local_player(); - return local > 0 ? server_player_ammo(local, type) : -1; + return -1; } static int classify_item(const char *model, const char *cls, char *label, @@ -2610,6 +2622,13 @@ static int classify_item(const char *model, const char *cls, char *label, snprintf(label, outn, "AR2 grenade"); return IK_AMMO; } + if (item_icontains(model, "w_grenade") || + item_icontains(model, "w_frag") || + item_icontains(model, "frag_grenade") || + item_icontains(model, "items/grenade")) { + snprintf(label, outn, "Frag grenade"); + return IK_AMMO; + } if (item_icontains(model, "models/items/")) { snprintf(label, outn, "Ammo"); return IK_AMMO; -- cgit v1.2.3