From 28aa6ec9717c4c0783b9e501d2c65139a14a73a8 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:01:15 +0800 Subject: [PATCH] Record the LocalMP battle outcome when the mission ends The settlement report read get_mission_status() when the debriefing opened. By then the mission scene has been unloaded and the status reads as running, so every battle that ended on its own (tickets or nuclear strike) was settled as not won. The end time was lost the same way and the last life was never closed: onQuitToDebriefing is only raised when the battle is left from the menu, not by the automatic FadeToDebriefing. AcesMission::endFinally (2.61.0.37 0x11203f0) raises the HUD event MissionResult with the local team's result while the mission still exists. Record the outcome, the end time and the closing life there; leaving from the menu still records the end time without an outcome. Checked with check-gui; not yet verified in game. --- .../record-local-battle-awards/patch.jsonc | 6 ++-- .../record-local-battle-awards/replace.nut | 34 +++++++++++++++---- .../replace.nut | 7 ++-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/gui-patches/battle/record-local-battle-awards/patch.jsonc b/gui-patches/battle/record-local-battle-awards/patch.jsonc index 463c669..e12001f 100644 --- a/gui-patches/battle/record-local-battle-awards/patch.jsonc +++ b/gui-patches/battle/record-local-battle-awards/patch.jsonc @@ -1,6 +1,6 @@ -// Record the local player's lives, combat events and the battle's kill log in a LocalMP battle, -// show the reward banner, and pass each fact to the local service live to show the battle awards -// (streaks) it completes. +// Record the local player's lives, combat events, the battle's kill log and how the battle ended +// in a LocalMP battle, show the reward banner, and pass each fact to the local service live to +// show the battle awards (streaks) it completes. // Why the client: online the battle server prices each event, judges the awards and sends both // banners (packet 0xb03d, streak messages); a LocalMP host has no battle server, so the native // bridge reports the facts as the HUD event "wtoLocalMpExpEvent" and only the client sees spawns, diff --git a/gui-patches/battle/record-local-battle-awards/replace.nut b/gui-patches/battle/record-local-battle-awards/replace.nut index 31e86ca..d6b5dfe 100644 --- a/gui-patches/battle/record-local-battle-awards/replace.nut +++ b/gui-patches/battle/record-local-battle-awards/replace.nut @@ -151,22 +151,42 @@ function wtoOnHudMessage(msg) { wtoSendLiveFact("kill", kill) } +// The battle ends for the local player: close the open life and keep the end time, which the +// settlement report needs after the mission has been left (the mission is unloaded before the +// debriefing, so its time and status are gone by then). The first end counts. +function wtoEndBattleRecord() { + let { ndbExists, ndbWrite } = require("nestdb") + if (!ndbExists(["wto", "activeBattle"]) || ndbExists(["wto", "battleLog", "sessionEnd"])) + return false + wtoCloseBattleLife(false) + ndbWrite(["wto", "battleLog", "sessionEnd"], require("mission").get_mission_time()) + return true +} + +// AcesMission::endFinally raises this HUD event with the result for the local player's team on +// every end of the battle (tickets, nuclear strike, empty team), while the mission still exists. +// The end that follows on its own (FadeToDebriefing) raises no script event. +function wtoOnMissionResult(ev) { + let { GO_WIN, GO_FAIL } = require("guiMission") + let result = ev?.resultNum + if (result != GO_WIN && result != GO_FAIL) + return + if (wtoEndBattleRecord()) + require("nestdb").ndbWrite(["wto", "battleLog", "outcome"], result == GO_WIN ? "win" : "lose") +} + function wtoSubscribeBattleAwards() { let { g_hud_event_manager } = require("%scripts/hud/hudEventManager.nut") g_hud_event_manager.subscribe("wtoLocalMpExpEvent", wtoOnLocalMpExpEvent) g_hud_event_manager.subscribe("LocalPlayerAlive", wtoOnLocalPlayerAlive) g_hud_event_manager.subscribe("LocalPlayerDead", wtoOnLocalPlayerDead) g_hud_event_manager.subscribe("HudMessage", wtoOnHudMessage) + g_hud_event_manager.subscribe("MissionResult", wtoOnMissionResult) } -// The battle ends for the local player here: close the open life and keep the end time, which the -// settlement report needs after the mission has been left. +// Leaving the battle from the menu before it has ended. function wtoOnQuitToDebriefing(_p) { - let { ndbExists, ndbWrite } = require("nestdb") - if (!ndbExists(["wto", "activeBattle"])) - return - wtoCloseBattleLife(false) - ndbWrite(["wto", "battleLog", "sessionEnd"], require("mission").get_mission_time()) + wtoEndBattleRecord() } wtoSubscribeBattleAwards() diff --git a/gui-patches/battle/report-local-battle-settlement/replace.nut b/gui-patches/battle/report-local-battle-settlement/replace.nut index d82d8eb..38cce17 100644 --- a/gui-patches/battle/report-local-battle-settlement/replace.nut +++ b/gui-patches/battle/report-local-battle-settlement/replace.nut @@ -4,14 +4,11 @@ // no rewards itself. function buildWtoBattleReport(wtoBattle, res) { let { ndbTryRead } = require("nestdb") - let guiMis = require("guiMission") let battleLog = ndbTryRead(["wto", "battleLog"]) ?? {} - let mStatus = guiMis.get_mission_status() let blk = DataBlock() blk.sessionId = wtoBattle.sessionId - blk.outcome = mStatus == guiMis.MISSION_STATUS_SUCCESS ? "win" - : mStatus == guiMis.MISSION_STATUS_FAIL ? "lose" - : "running" + // Recorded when the battle ended (record-local-battle-awards); none when it was left before. + blk.outcome = battleLog?.outcome ?? "running" blk.localTeam = (res?.localTeam ?? 1).tointeger() blk.teamAScore = (res?.mpTblTeams?[0]?.score ?? 0).tointeger() blk.teamBScore = (res?.mpTblTeams?[1]?.score ?? 0).tointeger()