diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-28 13:02:26 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-28 13:02:26 +0100 |
| commit | b212e8e13835cfdc4849a61c1b57146bd0312a29 (patch) | |
| tree | 128a64c8c20411749ee8ea4a78ef4a51a9604515 /src/esp.cpp | |
| parent | Combat: fix silent-aim spread seed and lead projectiles (diff) | |
| download | hl2h-b212e8e13835cfdc4849a61c1b57146bd0312a29.tar.gz hl2h-b212e8e13835cfdc4849a61c1b57146bd0312a29.zip | |
Melee: surface weapon state across maps; reset stale caches
- Map transitions often leave a non-crowbar weapon active, so the killbot
silently does nothing. Log every active-weapon change as a normal
`melee: active ... crowbar=0/1` line and toast once suggesting the crowbar.
- Recover the crowbar model from the server entity when the client weapon
model index is missing/0 after a map change.
- Clear the bone cache and aim/silent locks when the local player entity
changes (map load/respawn) so stale entity/model data cannot poison melee
target selection.
Diffstat (limited to 'src/esp.cpp')
| -rw-r--r-- | src/esp.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/esp.cpp b/src/esp.cpp index 06bafaf..a0d84dd 100644 --- a/src/esp.cpp +++ b/src/esp.cpp | |||
| @@ -873,6 +873,8 @@ bool melee_weapon_active(void *local_ent) { | |||
| 873 | if (!local_ent) | 873 | if (!local_ent) |
| 874 | return false; | 874 | return false; |
| 875 | int local = engine_get_local_player(); | 875 | int local = engine_get_local_player(); |
| 876 | if (g_iface.engineserver) | ||
| 877 | resolve_server_netvars(); | ||
| 876 | 878 | ||
| 877 | auto check = [&](int idx, const char **cls_out, | 879 | auto check = [&](int idx, const char **cls_out, |
| 878 | const char **model_out) -> bool { | 880 | const char **model_out) -> bool { |
| @@ -882,6 +884,14 @@ bool melee_weapon_active(void *local_ent) { | |||
| 882 | void *net = entity_networkable(idx); | 884 | void *net = entity_networkable(idx); |
| 883 | const char *cls = net ? entity_class_name(net, nullptr) : nullptr; | 885 | const char *cls = net ? entity_class_name(net, nullptr) : nullptr; |
| 884 | const char *model = wep ? entity_model_name(wep) : nullptr; | 886 | const char *model = wep ? entity_model_name(wep) : nullptr; |
| 887 | // Client weapon models can be missing/0 after a map change; recover the | ||
| 888 | // server model index so the crowbar is still recognized. | ||
| 889 | if ((!model || !*model) && g_iface.engineserver) { | ||
| 890 | void *sbase = nullptr; | ||
| 891 | server_entity_health(idx, nullptr, nullptr, &sbase); | ||
| 892 | if (sbase) | ||
| 893 | model = model_name_from_index(server_model_index(sbase)); | ||
| 894 | } | ||
| 885 | *cls_out = cls; | 895 | *cls_out = cls; |
| 886 | *model_out = model; | 896 | *model_out = model; |
| 887 | return (cls && strstr(cls, "Crowbar")) || | 897 | return (cls && strstr(cls, "Crowbar")) || |
| @@ -916,8 +926,15 @@ bool melee_weapon_active(void *local_ent) { | |||
| 916 | if (idx != last_idx || crowbar != last_crowbar) { | 926 | if (idx != last_idx || crowbar != last_crowbar) { |
| 917 | last_idx = idx; | 927 | last_idx = idx; |
| 918 | last_crowbar = crowbar; | 928 | last_crowbar = crowbar; |
| 919 | logd("melee: active idx=%d cls=%s model=%s crowbar=%d", idx, | 929 | logf("melee: active idx=%d cls=%s model=%s crowbar=%d", idx, |
| 920 | cls ? cls : "?", model ? model : "?", (int)crowbar); | 930 | cls ? cls : "?", model ? model : "?", (int)crowbar); |
| 931 | if (!crowbar) { | ||
| 932 | static bool warned = false; | ||
| 933 | if (!warned) { | ||
| 934 | warned = true; | ||
| 935 | toastf(TOAST_WARN, "Melee killbot: equip the crowbar"); | ||
| 936 | } | ||
| 937 | } | ||
| 921 | } | 938 | } |
| 922 | return crowbar; | 939 | return crowbar; |
| 923 | } | 940 | } |
