wto_ws.dll no longer scans aces.exe or carries structure offsets of a game build. It reads the values the patcher resolved (wto_ws.cfg native.* lines) into g_lmp through one table that names, per module, which value fills which field (local_mp_values.c), and installs each module whose values are all present, in dependency order, instead of giving up on the whole bridge when one subsystem is missing. When the settings were resolved for another executable (PE time stamp and image size differ), the bridge stays off. local_mp_offsets.h keeps the existing names so the module code reads as before; only Dagor library layouts (dag::Vector, DataBlock), protocol enums, the reflection buffer size and the two change request members with no reader in the client remain constants. A few fields are derived where the client has no instruction of its own for them (local_mp_values.c derive_values). The signatures moved to patches/native, and the header-based check-offsets command is gone: record-game-version and the launcher's patch check resolve the native modules now. Shared sites moved to local_mp_core (mission customBots, the player's unit eid) so modules do not depend on each other for them. Checked: DLL build (no warnings outside MinHook); root and launcher type checks; check-patches on 2.61.0.37; version records for 2.61.0.37 and 2.61.0.43 (10 native modules each); a lab run of the 2.61.0.37 copy logs 239 native values and "9 of 9 LocalMP modules installed". Battles were not played in this run.
111 lines
4.4 KiB
C
111 lines
4.4 KiB
C
/*
|
|
* 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
|
|
* 0x598a70, via 0xfd7160) and respawns it (0xe4fdf0, which picks an airfield only for a unit with
|
|
* an owner). When the support unit is gone, the unit update (0xfd1450 at 0xfd2f01 / 0xfd25a7)
|
|
* recognises it by that reference (unit +0x88 == MPlayer +0xb58) and gives the player back the
|
|
* vehicle (setControlledUnit with eid 0).
|
|
*
|
|
* 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 once the player has
|
|
* been given back control after the unit died (clearing it at the death itself kept the player
|
|
* from getting the vehicle back), 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"
|
|
|
|
#include "MinHook.h"
|
|
|
|
typedef void (__fastcall *SetControlledUnitFn)(uint8_t *mp, uint32_t eid);
|
|
|
|
static SetControlledUnitFn orig_set_controlled_unit;
|
|
|
|
/* Players whose support unit died, with that unit's entity id; cleared after control moves on. */
|
|
#define LMP_SUPPORT_PENDING_MAX 32
|
|
static struct {
|
|
uint8_t *mp;
|
|
uint32_t eid;
|
|
} g_pending[LMP_SUPPORT_PENDING_MAX];
|
|
|
|
static void remember_dead_support_unit(uint8_t *mp, uint32_t eid)
|
|
{
|
|
size_t i, free_slot = LMP_SUPPORT_PENDING_MAX;
|
|
|
|
for (i = 0; i < LMP_SUPPORT_PENDING_MAX; i++) {
|
|
if (g_pending[i].mp == mp) {
|
|
g_pending[i].eid = eid;
|
|
return;
|
|
}
|
|
if (g_pending[i].mp == NULL && free_slot == LMP_SUPPORT_PENDING_MAX)
|
|
free_slot = i;
|
|
}
|
|
if (free_slot < LMP_SUPPORT_PENDING_MAX) {
|
|
g_pending[free_slot].mp = mp;
|
|
g_pending[free_slot].eid = eid;
|
|
}
|
|
}
|
|
|
|
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", (unsigned)eid, (unsigned)mp[LMP_MP_OFF_PID]);
|
|
remember_dead_support_unit(mp, eid);
|
|
}
|
|
}
|
|
|
|
static void __fastcall hook_set_controlled_unit(uint8_t *mp, uint32_t eid)
|
|
{
|
|
size_t i;
|
|
|
|
orig_set_controlled_unit(mp, eid);
|
|
if (mp == NULL || !local_mp_is_host())
|
|
return;
|
|
for (i = 0; i < LMP_SUPPORT_PENDING_MAX; i++) {
|
|
if (g_pending[i].mp != mp)
|
|
continue;
|
|
if (*(uint32_t *)(mp + LMP_MP_OFF_SUPPORT_UNIT_EID) == g_pending[i].eid) {
|
|
log_line("local_mp: support unit reference of pid %u cleared", (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;
|
|
}
|
|
g_pending[i].mp = NULL;
|
|
g_pending[i].eid = 0;
|
|
}
|
|
}
|
|
|
|
int install_local_mp_support_hooks(void)
|
|
{
|
|
uint8_t *p_set = g_lmp.set_controlled_unit;
|
|
if (MH_CreateHook(p_set, (void *)&hook_set_controlled_unit, (void **)&orig_set_controlled_unit) != MH_OK ||
|
|
MH_EnableHook(p_set) != MH_OK) {
|
|
log_line("local_mp: failed to install the support unit hook");
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|