fix(battle): register nuclear wins when the projectile explodes

create_nuke_destr_area_es does not run on the LocalMP host. The projectile
explosion handler 0xbe7c00 gets the launch record's instant-win flag as its
8th argument (0x2fd778 / 0x2fd7c3) and is what plays the nuclear explosion,
so the winner is now taken there.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 18:10:39 +08:00
1 parent a2ade264ce
commit 5edc7adac8
2 files changed
+19 -14

No files matched your search

+15 -11
View File
@@ -11,8 +11,10 @@
* (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. Nuclear explosion: the ECS system create_nuke_destr_area_es (0x63caf0, registered at
* 0x641d7c) runs for the nuclear explosion entity. The remembered team becomes the winner.
* 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.
* 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:
@@ -28,11 +30,12 @@
#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 *EcsSystemFn)(void *a1, void *query, void *a3, void *a4);
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 EcsSystemFn orig_nuke_destr_area;
static ShellExplodeFn orig_shell_explode;
static LogicActionFn orig_cta_logic;
/* Team of the last launched instant-win bomb, and the team that won with it (0 = none). */
@@ -69,10 +72,11 @@ static void __fastcall hook_shell_launch(void **launch, void *a2, uint8_t *owner
g_bomb_team = team;
}
static void __fastcall hook_nuke_destr_area(void *a1, void *query, void *a3, void *a4)
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_nuke_destr_area(a1, query, a3, a4);
if (!local_mp_is_host() || g_bomb_team == 0 || g_winner_team != 0)
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;
@@ -119,16 +123,16 @@ static uint64_t __fastcall hook_cta_logic(uint8_t *ctx, void *a2, void *a3, void
int install_local_mp_nuke_hooks(const uint8_t *text, size_t text_size)
{
uint8_t *p_launch = local_mp_scan_unique(text, text_size, "shell launch (instant-win flag)", LMP_SIG_SHELL_LAUNCH);
uint8_t *p_destr = local_mp_scan_unique(text, text_size, "create_nuke_destr_area_es", LMP_SIG_NUKE_DESTR_AREA_ES);
uint8_t *p_explode = local_mp_scan_unique(text, text_size, "shell explosion", LMP_SIG_SHELL_EXPLODE);
uint8_t *p_cta = local_mp_scan_unique(text, text_size, "cta_logic_action", LMP_SIG_CTA_LOGIC_ACTION);
if (!p_launch || !p_destr || !p_cta)
if (!p_launch || !p_explode || !p_cta)
return 0;
if (MH_CreateHook(p_launch, (void *)&hook_shell_launch, (void **)&orig_shell_launch) != MH_OK ||
MH_CreateHook(p_destr, (void *)&hook_nuke_destr_area, (void **)&orig_nuke_destr_area) != 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_destr) != 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;
+4 -3
View File
@@ -271,12 +271,13 @@
* Nuclear instant win (local_mp_nuke.c, 2.61.0.37):
* bomb launch 0x1431c10: launch[3] is the launch record, record+0x70 its instant-win flag
* (set at 0x143330d / 0x143337d from the bomb property isInstantWinOnExplode);
* create_nuke_destr_area_es 0x63caf0 (registered at 0x641d7c);
* shell explosion 0xbe7c00: 8th argument = the launch record's instant-win flag (passed from
* record+0x70 at 0x2fd778 / 0x2fd7c3);
* cta_logic_action 0x11bc400: its context holds the mission variables at +0x40 (data) and
* +0x50 (count), 0x20 bytes each, name pointer at +0 and int value at +8 (0x11bd150).
*
* @anchor "isInstantWinOnExplode"
* @anchor "create_nuke_destr_area_es"
* @anchor "onBombMiss"
* @anchor "cta_logic_action"
* @anchor "mpTi1"
*/
@@ -288,6 +289,6 @@
#define LMP_MISSION_VAR_OFF_NAME 0x0000u
#define LMP_MISSION_VAR_OFF_VALUE 0x0008u
#define LMP_SIG_SHELL_LAUNCH "41 57 41 56 41 54 56 57 55 53 48 81 ec 30 02 00 00 44 0f 29 bc 24 20 02 00 00"
#define LMP_SIG_NUKE_DESTR_AREA_ES "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 88 01 00 00 44 0f 29 94 24 70 01 00 00 44 0f 29 8c 24 60 01 00 00 44 0f 29 84 24 50 01 00 00 0f 29 bc 24 40 01 00 00 0f 29 b4 24 30 01 00 00 0f b7 6a 02"
#define LMP_SIG_SHELL_EXPLODE "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 02 00 00 44 0f 29 bc 24 90 02 00 00 44 0f 29 b4 24 80 02 00 00 44 0f 29 ac 24 70 02 00 00 44 0f 29 a4 24 60 02 00 00 44 0f 29 9c 24 50 02 00 00 44 0f 29 94 24 40 02 00 00 44 0f 29 8c 24 30 02 00 00 44 0f 29 84 24 20 02 00 00 0f 29 bc 24 10 02 00 00 0f 29 b4 24 00 02 00 00 41 89 d3"
#define LMP_SIG_CTA_LOGIC_ACTION "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 02 00 00 44 0f 29 bc 24 90 02 00 00 44 0f 29 b4 24 80 02 00 00 44 0f 29 ac 24 70 02 00 00 44 0f 29 a4 24 60 02 00 00 44 0f 29 9c 24 50 02 00 00 44 0f 29 94 24 40 02 00 00 44 0f 29 8c 24 30 02 00 00 44 0f 29 84 24 20 02 00 00 0f 29 bc 24 10 02 00 00 0f 29 b4 24 00 02 00 00 48 89 cf"
#define LMP_SIG_IS_SLOT_READY_AT_HOST "41 56 56 57 55 53 48 81 ec a0 00 00 00 0f 29 b4 24 90 00 00 00 44 89 c3 48 89 d6 48 83 3d"