diff options
Diffstat (limited to '')
| -rw-r--r-- | src/server.cpp | 22 |
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; | |||
| 33 | int g_srv_modelindex = -1; | 33 | int g_srv_modelindex = -1; |
| 34 | int g_srv_absvelocity = -1; | 34 | int g_srv_absvelocity = -1; |
| 35 | int g_srv_velocity = -1; | 35 | int g_srv_velocity = -1; |
| 36 | int g_srv_activeweapon = -1; | ||
| 36 | static bool g_srv_ready = false; | 37 | static bool g_srv_ready = false; |
| 37 | static bool g_srv_checked = false; | 38 | static 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. | ||
| 203 | int 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 | } | ||
