Files
WT-Offline/native/wto-net/src/local_mp_nuke.c
T
N0VAN0M4LY fdac56a036 refactor(native)!: load LocalMP values from the build configuration
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.

BREAKING CHANGE: Rebuild game copies to generate the new native values in wto_ws.cfg. Use record-game-version.ts or the launcher patch check in place of wtotools check-offsets.
2026-11-29 12:26:11 +08:00

146 lines
6.3 KiB
C

/*
* Instant win of the nuclear bomb in a LocalMP battle.
*
* Online the battle server ends the battle when a bomb with isInstantWinOnExplode explodes
* (gamedata/weapons/bombguns/us_b61.blk and the other killstreak nuclear bombs); the 2.61.0.37
* client only marks the bomb and plays the explosion. The LocalMP host has no battle server, so
* the battle went on after the explosion. Here the host takes the same decision with the stock
* end of battle:
*
* 1. Bomb launch 0x1431c10: at its end the client sets the launch record's instant-win flag
* (record +0x70, written at 0x143330d / 0x143337d) from the bomb property
* isInstantWinOnExplode (+0x6a6, read at 0x13cb5a5). After it returns, a flagged record of a
* unit with an MPlayer remembers that player's team.
* 2. Projectile explosion 0xbe7c00: the host's shell update passes the launch record's flag as
* its 8th argument (movzx eax, byte [r15+0x70] at 0x2fd778, call at 0x2fd7c3); with the flag
* set it plays the nuclear explosion (flag 0x7bf4958+0x2be2, camera type 0x17 at 0xbe97e6) and
* nothing else. The remembered team becomes the winner; a bomb of the local player is also
* reported to the scripts (LMP_NUCLEAR_STRIKE_EVENT_NAME), the fact of the award
* killStreak_bomber_nuclear_success that online the battle server gives.
* 3. Domination logic cta_logic_action (0x11bc400, the mp_update_trig action registered at
* 0x11ba558): before it runs, the loser's mission variable mpTi1 / mpTi2 (tickets of team 1 / 2,
* looked up at 0x11bd1c7) is set to 0. The stock logic then ends the battle as on tickets:
* mp_game_over with the result for the local player's team (0x11bf661 / 0x11bf9c1).
*/
#include "hooks.h"
#include "hook_config.h"
#include "local_mp_internal.h"
#include "local_mp_offsets.h"
#include "MinHook.h"
#include <string.h>
typedef void (__fastcall *ShellLaunchFn)(void **launch, void *a2, uint8_t *owner, void *a4, uint64_t a5, uint64_t a6);
typedef void (__fastcall *ShellExplodeFn)(void *a1, uint64_t a2, void *a3, void *a4, void *a5, void *a6,
uint64_t a7, uint64_t instant_win, void *a9);
typedef uint64_t (__fastcall *LogicActionFn)(uint8_t *ctx, void *a2, void *a3, void *a4);
static ShellLaunchFn orig_shell_launch;
static ShellExplodeFn orig_shell_explode;
static LogicActionFn orig_cta_logic;
/* Team of the last launched instant-win bomb and whether the local player launched it, and the
* team that won with it (0 = none). */
static volatile uint8_t g_bomb_team;
static volatile uint8_t g_bomb_is_local;
static volatile uint8_t g_winner_team;
static uint8_t *g_logic_ctx;
static const uint8_t *owner_mplayer(const uint8_t *unit)
{
return unit != NULL ? *(const uint8_t *const *)(unit + LMP_UNIT_OFF_MPLAYER) : NULL;
}
static void __fastcall hook_shell_launch(void **launch, void *a2, uint8_t *owner, void *a4, uint64_t a5, uint64_t a6)
{
const uint8_t *record;
const uint8_t *mp;
uint8_t team;
orig_shell_launch(launch, a2, owner, a4, a5, a6);
if (launch == NULL || !local_mp_is_host())
return;
record = *(const uint8_t *const *)((const uint8_t *)launch + LMP_SHELL_LAUNCH_OFF_RECORD);
if (record == NULL || record[LMP_SHELL_REC_OFF_INSTANT_WIN] != 1)
return;
mp = owner_mplayer(owner);
team = mp != NULL ? mp[LMP_MP_OFF_TEAM] : 0;
if (team != 1 && team != 2)
return;
if (g_bomb_team != team)
log_line("local_mp: instant-win bomb launched by team %u", (unsigned)team);
g_bomb_team = team;
g_bomb_is_local = local_mp_is_local_mplayer(mp) ? 1 : 0;
}
static void __fastcall hook_shell_explode(void *a1, uint64_t a2, void *a3, void *a4, void *a5, void *a6,
uint64_t a7, uint64_t instant_win, void *a9)
{
orig_shell_explode(a1, a2, a3, a4, a5, a6, a7, instant_win, a9);
if ((instant_win & 1u) == 0 || !local_mp_is_host() || g_bomb_team == 0 || g_winner_team != 0)
return;
g_winner_team = g_bomb_team;
g_bomb_team = 0;
log_line("local_mp: nuclear explosion, team %u wins%s", (unsigned)g_winner_team,
g_bomb_is_local ? " (local player's bomb)" : "");
if (g_bomb_is_local)
local_mp_report_nuclear_strike();
g_bomb_is_local = 0;
}
static int *mission_int_var(uint8_t *ctx, const char *name)
{
uint8_t *vars = *(uint8_t **)(ctx + LMP_MISSION_VARS_OFF_DATA);
uint32_t count = *(uint32_t *)(ctx + LMP_MISSION_VARS_OFF_COUNT);
uint32_t i;
if (vars == NULL)
return NULL;
for (i = 0; i < count; i++) {
uint8_t *var = vars + (size_t)i * LMP_MISSION_VAR_STRIDE;
const char *var_name = *(const char **)(var + LMP_MISSION_VAR_OFF_NAME);
if (var_name != NULL && strcmp(var_name, name) == 0)
return (int *)(var + LMP_MISSION_VAR_OFF_VALUE);
}
return NULL;
}
static uint64_t __fastcall hook_cta_logic(uint8_t *ctx, void *a2, void *a3, void *a4)
{
if (ctx != g_logic_ctx) {
/* A new mission: nothing launched or won in the previous one carries over. */
g_logic_ctx = ctx;
g_bomb_team = 0;
g_bomb_is_local = 0;
g_winner_team = 0;
}
if (ctx != NULL && g_winner_team != 0 && local_mp_is_host()) {
int *loser_tickets = mission_int_var(ctx, g_winner_team == 1 ? "mpTi2" : "mpTi1");
if (loser_tickets != NULL && *loser_tickets > 0) {
log_line("local_mp: nuclear win, tickets of team %u set to 0 (were %d)",
(unsigned)(3u - g_winner_team), *loser_tickets);
*loser_tickets = 0;
}
g_winner_team = 0;
}
return orig_cta_logic(ctx, a2, a3, a4);
}
int install_local_mp_nuke_hooks(void)
{
uint8_t *p_launch = g_lmp.shell_launch;
uint8_t *p_explode = g_lmp.shell_explode;
uint8_t *p_cta = g_lmp.cta_logic_action;
if (MH_CreateHook(p_launch, (void *)&hook_shell_launch, (void **)&orig_shell_launch) != MH_OK ||
MH_CreateHook(p_explode, (void *)&hook_shell_explode, (void **)&orig_shell_explode) != MH_OK ||
MH_CreateHook(p_cta, (void *)&hook_cta_logic, (void **)&orig_cta_logic) != MH_OK ||
MH_EnableHook(p_launch) != MH_OK ||
MH_EnableHook(p_explode) != MH_OK ||
MH_EnableHook(p_cta) != MH_OK) {
log_line("local_mp: failed to install the nuclear instant-win hooks");
return 0;
}
return 1;
}