fix(battle): release destroyed mission support units on the 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.
This commit is contained in:
1 parent
37efa804bb
commit
c1a9fe8d26
5 files changed
+53
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user