summaryrefslogtreecommitdiffstats
path: root/src/server.cpp
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-27 14:52:00 +0100
committersalmonik <salmonik@tuta.io>2026-10-27 14:52:24 +0100
commit293eda2bdce9d732fad168b5b6838bd89ce59fe8 (patch)
tree9f345d4a19d1957ccfd7764012221d62eb2df328 /src/server.cpp
parentMenu: latch the Insert key and expand the root on open (diff)
downloadhl2h-293eda2bdce9d732fad168b5b6838bd89ce59fe8.tar.gz
hl2h-293eda2bdce9d732fad168b5b6838bd89ce59fe8.zip
Melee killbot: 360-degree crowbar silent aim
- New feature (default on): while the local player's active weapon is the crowbar, pick the nearest visible hostile NPC within the 75-unit crowbar range, sorted by distance to its collision AABB, and attack it through the normal silent-aim path (usercmd view + IN_ATTACK, movement preserved, rendered view restored at FRAME_RENDER_START). - Prefer the nearest visible hitbox center; fall back to the AABB center / closest point when bones are unavailable. Reuses the existing friendly / neutral and life-state filters and the world-only vischeck. - Detect the active weapon from the client m_hActiveWeapon handle, with the authoritative server m_hActiveWeapon handle as a fallback (client entity index from the low 16 bits). - While the crowbar is active and this feature is on, skip the gun aimbot, triggerbot and silent aim so they do not fight over the usercmd view. - Menu: Melee killbot -> Active; config [melee] active=...
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/server.cpp b/src/server.cpp
index 3766906..896ce3e 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -33,6 +33,7 @@ int g_srv_lifestate = -1;
33int g_srv_modelindex = -1; 33int g_srv_modelindex = -1;
34int g_srv_absvelocity = -1; 34int g_srv_absvelocity = -1;
35int g_srv_velocity = -1; 35int g_srv_velocity = -1;
36int g_srv_activeweapon = -1;
36static bool g_srv_ready = false; 37static bool g_srv_ready = false;
37static bool g_srv_checked = false; 38static bool g_srv_checked = false;
38 39
@@ -109,12 +110,14 @@ bool resolve_server_netvars() {
109 g_srv_modelindex = datamap_offset("m_nModelIndex", 7); // FIELD_SHORT 110 g_srv_modelindex = datamap_offset("m_nModelIndex", 7); // FIELD_SHORT
110 g_srv_absvelocity = datamap_offset("m_vecAbsVelocity", 3); // FIELD_VECTOR 111 g_srv_absvelocity = datamap_offset("m_vecAbsVelocity", 3); // FIELD_VECTOR
111 g_srv_velocity = datamap_offset("m_vecVelocity", 3); // FIELD_VECTOR 112 g_srv_velocity = datamap_offset("m_vecVelocity", 3); // FIELD_VECTOR
113 g_srv_activeweapon = datamap_offset("m_hActiveWeapon", 13); // FIELD_EHANDLE
112 g_srv_ready = g_srv_health > 0; 114 g_srv_ready = g_srv_health > 0;
113 if (g_srv_ready) { 115 if (g_srv_ready) {
114 logf("server datamap (%s): health=%d maxhealth=%d lifeste=%d " 116 logf("server datamap (%s): health=%d maxhealth=%d lifeste=%d "
115 "modelindex=%d absvel=%d vel=%d", 117 "modelindex=%d absvel=%d vel=%d activeweapon=%d",
116 g_server.path.c_str(), g_srv_health, g_srv_maxhealth, g_srv_lifestate, 118 g_server.path.c_str(), g_srv_health, g_srv_maxhealth, g_srv_lifestate,
117 g_srv_modelindex, g_srv_absvelocity, g_srv_velocity); 119 g_srv_modelindex, g_srv_absvelocity, g_srv_velocity,
120 g_srv_activeweapon);
118 fail_logged = false; 121 fail_logged = false;
119 } else if (!fail_logged) { 122 } else if (!fail_logged) {
120 fail_logged = true; 123 fail_logged = true;
@@ -194,3 +197,18 @@ bool server_set_velocity_z(int idx, float vz) {
194 *(float *)((uintptr_t)base + g_srv_absvelocity + 8) = vz; 197 *(float *)((uintptr_t)base + g_srv_absvelocity + 8) = vz;
195 return true; 198 return true;
196} 199}
200
201// Entity index of the player's active weapon from the authoritative server
202// entity. Used as a fallback if the client m_hActiveWeapon netvar is missing.
203int server_active_weapon(int idx) {
204 if (!g_srv_ready || !g_iface.engineserver || g_srv_activeweapon <= 0)
205 return -1;
206 void *base = nullptr;
207 if (server_entity_health(idx, nullptr, nullptr, &base) < 0 || !base)
208 return -1;
209 uint32_t h = *(uint32_t *)((uintptr_t)base + g_srv_activeweapon);
210 if (h == 0xFFFFFFFFu)
211 return -1;
212 int wi = (int)(h & 0xFFFF);
213 return (wi > 0 && wi <= 4096) ? wi : -1;
214}