fix(hud): show damage notices for the controlled vehicle

Keep the affected unit on the native barrel and breech notification paths. Filter only the local-host notices, using the stock current-control lookup.
This commit is contained in:
N0VAN0M4LY committed 2026-12-01 13:50:05 +08:00
1 parent 70c4ee4880
commit b4af034756
9 files changed
+219

No files matched your search

@@ -648,6 +648,7 @@
"K-Spawn score and respawns": "Spawn points and respawning",
"K-Scouting": "Scouting and drones",
"K-Kill, assist and capture scoring": "Kill, assist and capture scoring",
"K-Player damage notices": "Player damage notices",
"K-Additional vehicles": "Additional vehicles",
"K-Scoreboard": "Scoreboard",
"K-Chat and radio": "Chat and radio",
@@ -648,6 +648,7 @@
"K-Spawn score and respawns": "出生点数与重生",
"K-Scouting": "侦察与无人机",
"K-Kill, assist and capture scoring": "击杀、助攻与占点计分",
"K-Player damage notices": "玩家载具受损提示",
"K-Additional vehicles": "补充载具",
"K-Scoreboard": "计分板",
"K-Chat and radio": "聊天与无线电",
+1
View File
@@ -23,6 +23,7 @@ New-Item -ItemType Directory -Force $obj | Out-Null
$sources = @(
"$src\dll_main.c", "$src\hook_config.c", "$src\redirect_rules.c", "$src\resolver_hooks.c", "$src\connection_hooks.c",
"$src\local_mp_core.c", "$src\local_mp_values.c", "$src\local_mp_players.c", "$src\local_mp_loadout.c", "$src\local_mp_actions.c", "$src\local_mp_awards.c", "$src\local_mp_kills.c", "$src\local_mp_events.c", "$src\local_mp_scores.c", "$src\local_mp_nuke.c", "$src\local_mp_support.c",
"$src\local_mp_damage_notifications.c",
"$mh\src\hook.c", "$mh\src\buffer.c", "$mh\src\trampoline.c", "$mh\src\hde\hde64.c"
) | ForEach-Object { '"' + (Resolve-Path $_) + '"' }
+1
View File
@@ -140,6 +140,7 @@ static const LocalMpModule MODULES[] = {
{ "local_mp_events", install_local_mp_event_hooks },
{ "local_mp_nuke", install_local_mp_nuke_hooks },
{ "local_mp_support", install_local_mp_support_hooks },
{ "local_mp_damage_notifications", install_local_mp_damage_notification_hooks },
};
static void use_core_values(void)
@@ -0,0 +1,109 @@
/*
* Bind the stock barrel and breech HUD notices to the damaged unit on a LocalMP host.
* The native damage and firing handlers retain their normal effects.
*/
#include "local_mp_internal.h"
#include "local_mp_values.h"
#include "MinHook.h"
typedef uint8_t (__fastcall *BarrelDamageFn)(void *damage, const uint8_t *impact);
typedef void (__fastcall *FireUpdateFn)(
const uint8_t *weapon, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6,
float arg7, uint8_t arg8, float arg9, void *arg10, uint8_t arg11, float arg12);
typedef void (__fastcall *DeliverHudFn)(
int32_t type, int32_t id, int32_t arg3, int32_t arg4, int32_t arg5,
float arg6, float arg7, uint8_t arg8);
typedef const uint8_t *(__fastcall *ControlledUnitFn)(const uint8_t *mplayer);
/* HUD_MSG_EVENT is registered in the stock hudMessages module. */
enum { HUD_MSG_EVENT = 9 };
typedef struct DamageNotice {
const uint8_t *context;
size_t unit_offset;
uintptr_t unit_tag;
int32_t id;
} DamageNotice;
/* Both producers deliver synchronously. Keep nested events and simulation threads independent. */
static __declspec(thread) const DamageNotice *active_notice;
static BarrelDamageFn original_barrel_damage;
static FireUpdateFn original_fire_update;
static DeliverHudFn original_deliver_hud;
static uint8_t __fastcall hook_barrel_damage(void *damage, const uint8_t *impact)
{
/* The stock handler resolves the reference before it emits the notice and tags it in bit 0. */
const DamageNotice notice = { impact, g_lmp.barrel_unit_ref, 1, (int32_t)g_lmp.barrel_notice_id };
const DamageNotice *previous = active_notice;
uint8_t result;
if (local_mp_is_host())
active_notice = &notice;
result = original_barrel_damage(damage, impact);
active_notice = previous;
return result;
}
static void __fastcall hook_fire_update(
const uint8_t *weapon, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6,
float arg7, uint8_t arg8, float arg9, void *arg10, uint8_t arg11, float arg12)
{
const DamageNotice notice = { weapon, g_lmp.breech_unit, 0, (int32_t)g_lmp.breech_notice_id };
const DamageNotice *previous = active_notice;
if (local_mp_is_host())
active_notice = &notice;
original_fire_update(weapon, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
active_notice = previous;
}
static int is_controlled_damage(const DamageNotice *notice)
{
const uint8_t *mplayer = g_local_mp_mplayer ? *g_local_mp_mplayer : NULL;
uintptr_t unit;
if (mplayer == NULL || notice->context == NULL)
return 0;
unit = *(const uintptr_t *)(notice->context + notice->unit_offset) & ~notice->unit_tag;
return unit != 0 && (const uint8_t *)unit == ((ControlledUnitFn)g_lmp.mplayer_controlled_unit)(mplayer);
}
static void __fastcall hook_deliver_hud(
int32_t type, int32_t id, int32_t arg3, int32_t arg4, int32_t arg5,
float arg6, float arg7, uint8_t arg8)
{
const DamageNotice *notice = active_notice;
if (notice != NULL && type == HUD_MSG_EVENT && id == notice->id && local_mp_is_host()
&& !is_controlled_damage(notice))
return;
original_deliver_hud(type, id, arg3, arg4, arg5, arg6, arg7, arg8);
}
int install_local_mp_damage_notification_hooks(void)
{
const struct { void *target, *detour, **original; } hooks[] = {
{ g_lmp.barrel_notice_deliver, (void *)&hook_deliver_hud, (void **)&original_deliver_hud },
{ g_lmp.barrel_damage, (void *)&hook_barrel_damage, (void **)&original_barrel_damage },
{ g_lmp.breech_fire_update, (void *)&hook_fire_update, (void **)&original_fire_update },
};
size_t created = 0;
if (g_lmp.barrel_notice_deliver != g_lmp.breech_notice_deliver)
return 0;
while (created < sizeof(hooks) / sizeof(hooks[0])) {
if (MH_CreateHook(hooks[created].target, hooks[created].detour, hooks[created].original) != MH_OK)
goto failed;
++created;
if (MH_QueueEnableHook(hooks[created - 1].target) != MH_OK)
goto failed;
}
if (MH_ApplyQueued() == MH_OK)
return 1;
failed:
while (created != 0)
MH_RemoveHook(hooks[--created].target);
return 0;
}
+1
View File
@@ -92,3 +92,4 @@ int install_local_mp_event_hooks(void);
int install_local_mp_score_reader(void);
int install_local_mp_nuke_hooks(void);
int install_local_mp_support_hooks(void);
int install_local_mp_damage_notification_hooks(void);
+9
View File
@@ -39,6 +39,7 @@ typedef struct LmpValueSpec {
#define EVENTS "local_mp_events"
#define NUKE "local_mp_nuke"
#define SUPPORT "local_mp_support"
#define DAMAGE_NOTICES "local_mp_damage_notifications"
static const LmpValueSpec SPECS[] = {
A(CORE, "do_respawn_player", do_respawn_player), O(CORE, "do_respawn_player.app_score_rules", app_score_rules),
@@ -141,6 +142,14 @@ static const LmpValueSpec SPECS[] = {
A(SUPPORT, "set_controlled_unit", set_controlled_unit), O(SUPPORT, "mplayer_support_unit.eid", mp_support_unit_eid),
O(SUPPORT, "mplayer_support_unit.unit", mp_support_unit_ptr),
A(DAMAGE_NOTICES, "barrel_damage", barrel_damage), O(DAMAGE_NOTICES, "barrel_damage.unit", barrel_unit_ref),
A(DAMAGE_NOTICES, "barrel_damage_notice.deliver", barrel_notice_deliver),
O(DAMAGE_NOTICES, "barrel_damage_notice.id", barrel_notice_id),
A(DAMAGE_NOTICES, "breech_fire_update", breech_fire_update), O(DAMAGE_NOTICES, "breech_fire_update.unit", breech_unit),
A(DAMAGE_NOTICES, "breech_damage_notice.deliver", breech_notice_deliver),
O(DAMAGE_NOTICES, "breech_damage_notice.id", breech_notice_id),
A(DAMAGE_NOTICES, "mplayer_controlled_unit", mplayer_controlled_unit),
};
static void store(const LmpValueSpec *spec, int64_t value, uint8_t *base)
+4
View File
@@ -74,6 +74,10 @@ typedef struct LmpValues {
/* local_mp_support */
uint8_t *set_controlled_unit;
size_t mp_support_unit_eid, mp_support_unit_ptr;
/* local_mp_damage_notifications */
uint8_t *barrel_damage, *breech_fire_update, *barrel_notice_deliver, *breech_notice_deliver, *mplayer_controlled_unit;
size_t barrel_unit_ref, breech_unit, barrel_notice_id, breech_notice_id;
} LmpValues;
extern LmpValues g_lmp;
@@ -0,0 +1,92 @@
// Send barrel explosion and breech misfire notices only for the locally controlled unit.
// The native producers know the affected unit. The HUD receives only the type, text and ID.
{
"module": "local_mp_damage_notifications",
"features": [
"K-Player damage notices"
],
"requires": [
"local_mp_core"
],
"sites": {
// Damage handler prologue reads the impact's tagged unit reference.
// 2.61.0.37: 0x398780; 2.61.0.43: 0x398700.
"barrel_damage": {
"variants": [
{
"written_for": "2.61.0.37",
"locate": {
"method": "signature",
"pattern": "41 56 56 57 53 48 83 ec 58 48 8b 72 ?? 89 f0 83 e0 01 0b 05 ?? ?? ?? ?? 3b 42 ?? 0f 85",
"captures": {
"unit": { "offset": 12, "type": "u8" }
}
}
}
]
},
// The barrel handler sends HUD_MSG_EVENT with hud_gun_barrel_exploded.
"barrel_damage_notice": {
"variants": [
{
"written_for": "2.61.0.37",
"locate": {
"method": "within",
"in": "barrel_damage",
"pattern": "b9 09 00 00 00 ba e2 01 00 00 45 31 c0 45 31 c9 e8 ?? ?? ?? ??",
"captures": {
"id": { "offset": 6, "type": "u32" },
"deliver": { "offset": 17, "type": "rel32" }
}
}
}
]
},
// Fire update prologue through the argument saves and the weapon owner's unit load.
// 2.61.0.37: 0x13e03a0; 2.61.0.43: 0x13e4a40.
"breech_fire_update": {
"variants": [
{
"written_for": "2.61.0.37",
"locate": {
"method": "signature",
"pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec f8 01 00 00 44 0f 29 bc 24 e0 01 00 00 44 0f 29 b4 24 d0 01 00 00 44 0f 29 ac 24 c0 01 00 00 44 0f 29 a4 24 b0 01 00 00 44 0f 29 9c 24 a0 01 00 00 44 0f 29 94 24 90 01 00 00 44 0f 29 8c 24 80 01 00 00 44 0f 29 84 24 70 01 00 00 0f 29 bc 24 60 01 00 00 0f 29 b4 24 50 01 00 00 4c 89 8c 24 18 01 00 00 4c 89 84 24 d8 00 00 00 48 89 94 24 10 01 00 00 48 89 ce f3 44 0f 10 94 24 80 02 00 00 48 8b 49 ??",
"captures": {
"unit": { "offset": 147, "type": "u8" }
}
}
}
]
},
// The fire update sends HUD_MSG_EVENT with hud_gun_breech_malfunction_misfire.
"breech_damage_notice": {
"variants": [
{
"written_for": "2.61.0.37",
"locate": {
"method": "within",
"in": "breech_fire_update",
"pattern": "b9 09 00 00 00 ba e4 01 00 00 45 31 c0 45 31 c9 e8 ?? ?? ?? ??",
"captures": {
"id": { "offset": 6, "type": "u32" },
"deliver": { "offset": 17, "type": "rel32" }
}
}
}
]
},
// Resolve the currently controlled unit, preferring the active override over the original unit.
// 2.61.0.37: 0x598bc0; 2.61.0.43: 0x5994c0.
"mplayer_controlled_unit": {
"variants": [
{
"written_for": "2.61.0.37",
"locate": {
"method": "signature",
"pattern": "48 83 ec 38 48 8d 81 78 08 00 00 48 8d 91 84 08 00 00 44 8b 81 80 08 00 00 4c 8d 89 54 08 00 00 45 85 c0 4c 0f 45 ca 48 8d 91 48 08 00 00"
}
}
]
}
}
}