From 2065514d16a76913a15325527b245c21803bd4ea Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sun, 29 Nov 2026 02:37:19 +0800 Subject: [PATCH] Free a destroyed mission support unit on the LocalMP host After the first nuclear carrier was shot down, the next launch respawned it in the air where it died and the player could not fly it. The host gives a player a support unit only while missionSupportUnitRef (MPlayer +0xb50 / +0xb58) is empty (2.61.0.37 0x59d9c8), and the client clears the reference only when the player is re-initialised, never during a battle. The second launch reused the dead unit: control was refused ("changed controlled unit to already dead unit"), and without an owner the respawn (0xe4fdf0) placed it at its old position instead of an airfield. Clear a player's reference when the unit it names dies (in the existing onUnitDeadOnce hook, host only), so the stock update creates a new support unit the next time the spawn score threshold is reached. Checked with the native build and check-offsets; not yet verified in game. --- native/wto-net/build.ps1 | 2 +- native/wto-net/src/local_mp_internal.h | 3 ++ native/wto-net/src/local_mp_kills.c | 1 + native/wto-net/src/local_mp_offsets.h | 3 ++ native/wto-net/src/local_mp_support.c | 45 ++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 native/wto-net/src/local_mp_support.c diff --git a/native/wto-net/build.ps1 b/native/wto-net/build.ps1 index 2c7c683..039a3ad 100644 --- a/native/wto-net/build.ps1 +++ b/native/wto-net/build.ps1 @@ -22,7 +22,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_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_core.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", "$mh\src\hook.c", "$mh\src\buffer.c", "$mh\src\trampoline.c", "$mh\src\hde\hde64.c" ) | ForEach-Object { '"' + (Resolve-Path $_) + '"' } diff --git a/native/wto-net/src/local_mp_internal.h b/native/wto-net/src/local_mp_internal.h index 2a04f30..d8be63d 100644 --- a/native/wto-net/src/local_mp_internal.h +++ b/native/wto-net/src/local_mp_internal.h @@ -65,6 +65,9 @@ void local_mp_players_queue_spawn(int32_t slot_id, int32_t spare_type, int is_si /* Combat event reporting to the GUI scripts (local_mp_awards.c). */ void local_mp_report_award_event(const LocalMpAwardEvent *ev); void local_mp_report_nuclear_strike(void); + +/* A destroyed unit that is some player's mission support unit frees the reference (local_mp_support.c). */ +void local_mp_support_unit_dead(const uint8_t *victim); const char *local_mp_unit_exp_class(const uint8_t *unit); /* Mission scores of combat events from the mission settings (local_mp_scores.c). */ diff --git a/native/wto-net/src/local_mp_kills.c b/native/wto-net/src/local_mp_kills.c index 37d20e5..dd5625d 100644 --- a/native/wto-net/src/local_mp_kills.c +++ b/native/wto-net/src/local_mp_kills.c @@ -180,6 +180,7 @@ static void __fastcall hook_iground_on_became_dead(uint8_t *victim, int32_t p2) static void __fastcall hook_on_unit_dead_once(uint8_t *victim) { + local_mp_support_unit_dead(victim); if (local_mp_is_host() && victim != NULL && victim[LMP_UNIT_OFF_SKIP_KILL] == 0) { int32_t killer_army = 0; uint8_t *killer_mp = resolve_offender_killer(victim, &killer_army); diff --git a/native/wto-net/src/local_mp_offsets.h b/native/wto-net/src/local_mp_offsets.h index eeecb3d..aea2118 100644 --- a/native/wto-net/src/local_mp_offsets.h +++ b/native/wto-net/src/local_mp_offsets.h @@ -112,6 +112,9 @@ #define LMP_MP_OFF_SHIP_SEVERE_DMG 0x0a08u #define LMP_MP_OFF_STAT_DIRTY 0x0a10u #define LMP_MP_OFF_STAT_PAYLOAD 0x0a30u +/* missionSupportUnitRef: cached unit pointer and entity id (set 0x59da3c..0x59da47, ctor 0x5ad57b). */ +#define LMP_MP_OFF_SUPPORT_UNIT_PTR 0x0b50u +#define LMP_MP_OFF_SUPPORT_UNIT_EID 0x0b58u #define LMP_MP_OFF_RESP_BASE_ID 0x0bd8u #define LMP_MP_OFF_SPAWN_DELAY_A 0x0bf4u #define LMP_MP_OFF_SPAWN_DELAY_B 0x0bf8u diff --git a/native/wto-net/src/local_mp_support.c b/native/wto-net/src/local_mp_support.c new file mode 100644 index 0000000..b0b3b03 --- /dev/null +++ b/native/wto-net/src/local_mp_support.c @@ -0,0 +1,45 @@ +/* + * Mission support unit (the nuclear carrier) after it is destroyed, on the LocalMP host. + * + * The host gives a player a support unit when the player's spawn score reaches the threshold and + * the player has none: MPlayer per-frame update 0x59d270 at 0x59d9c8..0x59da47 (2.61.0.37) checks + * missionSupportUnitRef (MPlayer +0xb50 cached pointer, +0xb58 entity id) == 0, creates the unit + * with async_create_support_unit (0xcb55d0) and stores its entity id there. The action bar button + * launches the unit the reference names; the host then hands it control (setControlledUnit, via + * 0xfd7160) and respawns it (0xe4fdf0, which picks an airfield only for a unit with an owner). + * + * The client never clears the reference while a battle runs (only MPlayer::initMPlayer / + * clearBeforeLobby reset it, 0x595a30 / 0x599680), so after the first support unit was destroyed + * the next launch reused the dead unit: control was refused ("changed controlled unit to already + * dead unit"), the unit respawned in the air where it died and nobody flew it. Online the battle + * server presumably drops the reference (not observed). Here the host does it when the unit dies, + * so the stock update creates a new support unit the next time the threshold is reached. + */ +#include "hooks.h" +#include "hook_config.h" +#include "local_mp_internal.h" +#include "local_mp_offsets.h" + +void local_mp_support_unit_dead(const uint8_t *victim) +{ + uint8_t **table = g_local_mp_player_table ? *g_local_mp_player_table : NULL; + uint32_t count = g_local_mp_player_count ? *g_local_mp_player_count : 0; + uint32_t i; + + if (victim == NULL || table == NULL || g_lmp_get_unit_by_eid == NULL || !local_mp_is_host()) + return; + for (i = 0; i < count; i++) { + uint8_t *mp = table[i]; + uint32_t eid; + + if (mp == NULL) + continue; + eid = *(uint32_t *)(mp + LMP_MP_OFF_SUPPORT_UNIT_EID); + if (eid == 0 || (const uint8_t *)g_lmp_get_unit_by_eid(eid) != victim) + continue; + log_line("local_mp: support unit eid %08x of pid %u destroyed, reference cleared", + (unsigned)eid, (unsigned)mp[LMP_MP_OFF_PID]); + *(uint64_t *)(mp + LMP_MP_OFF_SUPPORT_UNIT_PTR) = 0; + *(uint32_t *)(mp + LMP_MP_OFF_SUPPORT_UNIT_EID) = 0; + } +}