diff --git a/native/wto-net/src/local_mp_damage_notifications.c b/native/wto-net/src/local_mp_damage_notifications.c index 03c9386..1f3dab6 100644 --- a/native/wto-net/src/local_mp_damage_notifications.c +++ b/native/wto-net/src/local_mp_damage_notifications.c @@ -19,6 +19,7 @@ typedef void (__fastcall *AvionicsDamageFn)(const uint8_t *component, uint32_t k typedef uint64_t (__fastcall *ExitOpticViewFn)(void *camera, int32_t arg2, uint8_t arg3); typedef uint64_t (__fastcall *UnitOnEventFn)(void *unit, const uint8_t *event, void *arg3, void *arg4); typedef void (__fastcall *HitPartsFeedbackFn)(void *hud, const uint8_t *victim, const void *info); +typedef void (__fastcall *LocalMpiDispatchFn)(void *proxy, const uint8_t *msg, uint32_t recipient_pid); typedef const uint8_t *(__fastcall *ControlledUnitFn)(const uint8_t *mplayer); /* HUD message types, registered in the stock hudMessages module. */ @@ -49,10 +50,12 @@ static UnitOnEventFn original_unit_on_event; static HitPartsFeedbackFn original_enqueue_enemy_parts; static HitPartsFeedbackFn original_hit_cam_important; static HitPartsFeedbackFn original_naval_hit_state; +static LocalMpiDispatchFn original_local_mpi_dispatch; static int suppressed_avionics_logged; static int suppressed_optic_logged; static int suppressed_parts_logged; +static int suppressed_enemy_mpi_logged; /* The unit the local player's MPlayer controls, falling back to g_hero when MPlayer is absent. */ static const uint8_t *local_controlled_unit(void) @@ -232,6 +235,22 @@ static void __fastcall hook_hit_cam_important(void *hud, const uint8_t *victim, original_hit_cam_important(hud, victim, info); } +static int is_local_or_watched_mplayer(const uint8_t *mp) +{ + const uint8_t *watched; + const uint8_t *watched_mp; + + if (mp == NULL) + return 0; + if (local_mp_is_local_mplayer(mp)) + return 1; + watched = g_lmp.watched_hero != NULL ? *(const uint8_t *const *)g_lmp.watched_hero : NULL; + if (watched == NULL) + return 0; + watched_mp = *(const uint8_t *const *)(watched + LMP_UNIT_OFF_MPLAYER); + return watched_mp != NULL && mp == watched_mp; +} + static void __fastcall hook_naval_hit_state(void *hud, const uint8_t *victim, const void *info) { if (should_drop_hit_parts_feedback()) @@ -239,6 +258,31 @@ static void __fastcall hook_naval_hit_state(void *hud, const uint8_t *victim, co original_naval_hit_state(hud, victim, info); } +/* + * AcesApp's local MPI proxy ignores recipient_pid and delivers every local message to + * AcesApp::onEvent, leaking AI-vs-AI aircraft part damage (0xf104 / 0xf118) into the local + * player's bottom-right kill feed. + */ +static void __fastcall hook_local_mpi_dispatch(void *proxy, const uint8_t *msg, uint32_t recipient_pid) +{ + if (msg != NULL && local_mp_is_host()) { + uint16_t msg_id = *(const uint16_t *)(msg + g_lmp.mpi_msg_id_off); + if (msg_id == (uint16_t)g_lmp.enemy_part_dmg_mpi_id || msg_id == (uint16_t)g_lmp.enemy_part_hit_mpi_id) { + uint8_t pid = (uint8_t)(recipient_pid & 0xffu); + const uint8_t *recipient_mp = local_mp_find_mplayer(-1, pid); + if (!is_local_or_watched_mplayer(recipient_mp)) { + if (suppressed_enemy_mpi_logged < SUPPRESSED_LOG_LIMIT) { + ++suppressed_enemy_mpi_logged; + log_line("local_mp: dropped enemy part damage MPI 0x%04x for non-local pid %u", + (unsigned)msg_id, (unsigned)pid); + } + return; + } + } + } + original_local_mpi_dispatch(proxy, msg, recipient_pid); +} + int install_local_mp_damage_notification_hooks(void) { const LocalMpHookSpec hooks[] = { @@ -252,6 +296,7 @@ int install_local_mp_damage_notification_hooks(void) { "enqueue_enemy_parts", g_lmp.enqueue_enemy_parts, (void *)&hook_enqueue_enemy_parts, (void **)&original_enqueue_enemy_parts }, { "hit_cam_important", g_lmp.hit_cam_important, (void *)&hook_hit_cam_important, (void **)&original_hit_cam_important }, { "naval_hit_state", g_lmp.naval_hit_state, (void *)&hook_naval_hit_state, (void **)&original_naval_hit_state }, + { "local_mpi_dispatch", g_lmp.local_mpi_dispatch, (void *)&hook_local_mpi_dispatch, (void **)&original_local_mpi_dispatch }, }; if (g_lmp.barrel_notice_deliver != g_lmp.breech_notice_deliver) { diff --git a/native/wto-net/src/local_mp_events.c b/native/wto-net/src/local_mp_events.c index ffb9545..dc793ec 100644 --- a/native/wto-net/src/local_mp_events.c +++ b/native/wto-net/src/local_mp_events.c @@ -28,7 +28,7 @@ typedef struct AssistDedupRecord { typedef void (__fastcall *IGroundAwardAssistsFn)(uint8_t *victim); typedef void (__fastcall *DispatchAssistFn)(int64_t uid, uint8_t *victim, uint8_t *offender, float share, int32_t extra); typedef void (__fastcall *DispatchCaptureZoneFn)(int64_t uid, uint8_t *capturer_unit); -typedef void (__fastcall *DispatchHitCritFn)(int64_t uid, uint8_t *victim, uint8_t *offender, float dmg, uint8_t is_kill, uint8_t is_crit, uint8_t extra); +typedef void (__fastcall *DispatchHitCritFn)(int64_t uid, uint8_t *victim, uint8_t *offender, float dmg, uint8_t is_repeat_flush, uint8_t is_crit, uint8_t extra); typedef void (__fastcall *DispatchSevereDamageFn)(int64_t uid, uint8_t *victim, uint8_t *offender); typedef void (__fastcall *DispatchNavalDamageFn)(int64_t uid, uint8_t *victim, uint8_t *offender, float award_dmg); @@ -152,12 +152,22 @@ static void __fastcall hook_dispatch_capture_zone(int64_t uid, uint8_t *capturer orig_dispatch_capture_zone(uid, capturer_unit); } +/* + * The 5th parameter is `r8b & (fabsf(offender->lastHitAwardTime) >= FLT_EPSILON)` from + * Unit::flushOffenderHitAward (2.61.0.58 0xffcf70), not a kill flag. Ground, naval and helicopter + * hits flush via 0xffcd20 with r8b=0, whereas fixed-wing aircraft skip 0xffcd20 (0x13d7cd8) and + * only flush via 0xffdf10 with r8b=1; gating on it dropped every hit/crit after the first flush + * on an aircraft. The native single-player reward path (0xffd345) ignores it as well. + */ static void __fastcall hook_dispatch_hit_crit( - int64_t uid, uint8_t *victim, uint8_t *offender, float dmg, uint8_t is_kill, uint8_t is_crit, uint8_t extra + int64_t uid, uint8_t *victim, uint8_t *offender, float dmg, uint8_t is_repeat_flush, uint8_t is_crit, uint8_t extra ) { - if (local_mp_is_host() && !is_kill && victim != NULL) { - uint8_t *mp = local_mp_find_mplayer(uid, offender ? offender[LMP_OFFENDER_OFF_PID] : 0xffu); + if (local_mp_is_host() && victim != NULL) { + uint8_t victim_army = victim[LMP_UNIT_OFF_ARMY]; + int same_team = offender != NULL && victim_army != 0 + && *(int32_t *)(offender + LMP_OFFENDER_OFF_ARMY) == (int32_t)victim_army; + uint8_t *mp = !same_team ? local_mp_find_mplayer(uid, offender ? offender[LMP_OFFENDER_OFF_PID] : 0xffu) : NULL; if (mp != NULL && mp != *(uint8_t **)(victim + LMP_UNIT_OFF_MPLAYER)) { float pts = local_mp_event_score(is_crit ? "criticalHit" : "hit", victim, *(uint8_t **)(victim + LMP_UNIT_OFF_MPLAYER) != NULL); @@ -172,7 +182,7 @@ static void __fastcall hook_dispatch_hit_crit( } } } - orig_dispatch_hit_crit(uid, victim, offender, dmg, is_kill, is_crit, extra); + orig_dispatch_hit_crit(uid, victim, offender, dmg, is_repeat_flush, is_crit, extra); } static void __fastcall hook_dispatch_severe_damage(int64_t uid, uint8_t *victim, uint8_t *offender) diff --git a/native/wto-net/src/local_mp_values.c b/native/wto-net/src/local_mp_values.c index 42641da..c065def 100644 --- a/native/wto-net/src/local_mp_values.c +++ b/native/wto-net/src/local_mp_values.c @@ -158,6 +158,10 @@ static const LmpValueSpec SPECS[] = { A(DAMAGE_NOTICES, "hit_parts_feedback.enqueue_enemy_parts", enqueue_enemy_parts), A(DAMAGE_NOTICES, "hit_parts_feedback.hit_cam_important", hit_cam_important), A(DAMAGE_NOTICES, "hit_parts_feedback.naval_hit_state", naval_hit_state), + A(DAMAGE_NOTICES, "local_mpi_dispatch", local_mpi_dispatch), + O(DAMAGE_NOTICES, "mpi_msg_id.id_offset", mpi_msg_id_off), + O(DAMAGE_NOTICES, "enemy_part_damage_mpi.msg_id", enemy_part_dmg_mpi_id), + O(DAMAGE_NOTICES, "enemy_part_hit_mpi.msg_id", enemy_part_hit_mpi_id), O(AIR_EVENTS, "mission_mode_name.mode_name", mis_mode_name), A(AIR_EVENTS, "prepare_local_mission", prepare_local_mission), diff --git a/native/wto-net/src/local_mp_values.h b/native/wto-net/src/local_mp_values.h index 8ddf51e..c620cd4 100644 --- a/native/wto-net/src/local_mp_values.h +++ b/native/wto-net/src/local_mp_values.h @@ -77,8 +77,9 @@ typedef struct LmpValues { /* local_mp_damage_notifications */ uint8_t *barrel_damage, *breech_fire_update, *barrel_notice_deliver, *breech_notice_deliver, *mplayer_controlled_unit; uint8_t *hud_damage_deliver, *avionics_damage, *avionics_exit_optic; - uint8_t *watched_hero, *enqueue_enemy_parts, *hit_cam_important, *naval_hit_state; + uint8_t *watched_hero, *enqueue_enemy_parts, *hit_cam_important, *naval_hit_state, *local_mpi_dispatch; size_t barrel_unit_ref, breech_unit, barrel_notice_id, breech_notice_id, avionics_unit, hit_event_offender; + size_t mpi_msg_id_off, enemy_part_dmg_mpi_id, enemy_part_hit_mpi_id; /* local_mp_air_events */ uint8_t *prepare_local_mission, *use_kill_streaks, *gameplay, *kill_streak_name_map, *add_kill_streak_points; diff --git a/patches/native/local_mp_damage_notifications.jsonc b/patches/native/local_mp_damage_notifications.jsonc index 7fb119a..191324a 100644 --- a/patches/native/local_mp_damage_notifications.jsonc +++ b/patches/native/local_mp_damage_notifications.jsonc @@ -194,6 +194,69 @@ } } ] + }, + // AcesApp local MPI proxy dispatch(proxy, msg, recipient_pid): forwards every local message to + // AcesApp::onEvent without checking recipient_pid, so enemy-part-damage MPI messages addressed + // to AI bots reach the local HUD kill feed on a LocalMP host. + // 2.61.0.37: 0xc9d930; 2.61.0.58: 0xca1770. + "local_mpi_dispatch": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 48 83 ec 20 48 89 d6 48 8b 02 48 89 d1 ff 50 40 84 c0 74 ?? 48 8b 4e 08 48 8b 01 48 8b 40 10 48 89 f2 48 83 c4 20 5e 48 ff e0" + } + } + ] + }, + // Offset of the uint16 MPI message ID inside mpi::Message, read by mpi::send_to's error branch. + // 2.61.0.37: 0x3091846 (id_offset=0x20); 2.61.0.58: 0x30a0726 (id_offset=0x20). + "mpi_msg_id": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "0f b7 46 ?? 48 8d 0d ?? ?? ?? ?? 48 89 4c 24 28 c7 44 24 20 01 00 00 00 48 89 74 24 38 c7 44 24 30 06 00 00 00 48 89 44 24 48 c7 44 24 40 03 00 00 00", + "captures": { + "id_offset": { "offset": 3, "type": "u8" } + } + } + } + ] + }, + // Aircraft enemy-part-damage MPI constructor (HUD_MSG_ENEMY_DAMAGE/CRITICAL/FATAL). + // 2.61.0.37: 0xe19abb (msg_id=0xf104); 2.61.0.58: 0xe1dbfb (msg_id=0xf104). + "enemy_part_damage_mpi": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "4c 89 7c 24 40 c7 44 24 48 ff ff ff ff 48 89 4c 24 50 66 c7 44 24 58 ?? ?? 48 c7 44 24 60 00 00 00 00 c7 44 24 68 00 00 00 00", + "captures": { + "msg_id": { "offset": 23, "type": "u16" } + } + } + } + ] + }, + // Aircraft minor enemy-part-hit MPI constructor (HUD_MSG_ENEMY_DAMAGE). + // 2.61.0.37: 0xe6971f (msg_id=0xf118); 2.61.0.58: 0xe6d6ef (msg_id=0xf118). + "enemy_part_hit_mpi": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "48 89 7c 24 30 c7 44 24 38 ff ff ff ff 48 89 54 24 40 66 c7 44 24 48 ?? ?? 48 c7 44 24 50 00 00 00 00 c7 44 24 58 00 00 00 00", + "captures": { + "msg_id": { "offset": 23, "type": "u16" } + } + } + } + ] } } }