From 6c55c642222a435b5ea68b8308cae00229b2a283 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Tue, 1 Dec 2026 11:10:05 +0800 Subject: [PATCH] feat(replays): open local replays from battle reports Store the offline session ID in native replay metadata. Match the battle report to its recording and reuse the native player, queue check, and return flow. Verified TypeScript, GUI and executable patch checks on 2.61.0.37 and 2.61.0.43, and a temporary 2.61.0.43 build. In-game verification is pending. --- .../find-click.nut | 1 + .../find-refresh.nut | 1 + .../find-row-link.nut | 4 ++ .../find-state.nut | 1 + .../open-replay-from-battle-log/patch.jsonc | 34 +++++++++++++++++ .../replace-click.nut | 30 +++++++++++++++ .../replace-refresh.nut | 2 + .../replace-row-link.nut | 22 +++++++++++ .../replace-state.nut | 2 + .../play-local-battle-replay/find-exports.nut | 2 + .../play-local-battle-replay/find-lookup.nut | 1 + .../find-playback.nut | 4 ++ .../play-local-battle-replay/patch.jsonc | 30 +++++++++++++++ .../replace-exports.nut | 4 ++ .../replace-lookup.nut | 37 +++++++++++++++++++ .../replace-playback.nut | 1 + .../tag-local-battle-replay/find-metadata.nut | 1 + .../tag-local-battle-replay/patch.jsonc | 22 +++++++++++ .../replace-metadata.nut | 4 ++ 19 files changed, 203 insertions(+) create mode 100644 patches/gui/battle/open-replay-from-battle-log/find-click.nut create mode 100644 patches/gui/battle/open-replay-from-battle-log/find-refresh.nut create mode 100644 patches/gui/battle/open-replay-from-battle-log/find-row-link.nut create mode 100644 patches/gui/battle/open-replay-from-battle-log/find-state.nut create mode 100644 patches/gui/battle/open-replay-from-battle-log/patch.jsonc create mode 100644 patches/gui/battle/open-replay-from-battle-log/replace-click.nut create mode 100644 patches/gui/battle/open-replay-from-battle-log/replace-refresh.nut create mode 100644 patches/gui/battle/open-replay-from-battle-log/replace-row-link.nut create mode 100644 patches/gui/battle/open-replay-from-battle-log/replace-state.nut create mode 100644 patches/gui/battle/play-local-battle-replay/find-exports.nut create mode 100644 patches/gui/battle/play-local-battle-replay/find-lookup.nut create mode 100644 patches/gui/battle/play-local-battle-replay/find-playback.nut create mode 100644 patches/gui/battle/play-local-battle-replay/patch.jsonc create mode 100644 patches/gui/battle/play-local-battle-replay/replace-exports.nut create mode 100644 patches/gui/battle/play-local-battle-replay/replace-lookup.nut create mode 100644 patches/gui/battle/play-local-battle-replay/replace-playback.nut create mode 100644 patches/gui/battle/tag-local-battle-replay/find-metadata.nut create mode 100644 patches/gui/battle/tag-local-battle-replay/patch.jsonc create mode 100644 patches/gui/battle/tag-local-battle-replay/replace-metadata.nut diff --git a/patches/gui/battle/open-replay-from-battle-log/find-click.nut b/patches/gui/battle/open-replay-from-battle-log/find-click.nut new file mode 100644 index 0000000..958d407 --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/find-click.nut @@ -0,0 +1 @@ + function copyToClipboard() { diff --git a/patches/gui/battle/open-replay-from-battle-log/find-refresh.nut b/patches/gui/battle/open-replay-from-battle-log/find-refresh.nut new file mode 100644 index 0000000..4ed38f0 --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/find-refresh.nut @@ -0,0 +1 @@ + this.curPage = page diff --git a/patches/gui/battle/open-replay-from-battle-log/find-row-link.nut b/patches/gui/battle/open-replay-from-battle-log/find-row-link.nut new file mode 100644 index 0000000..2a66fad --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/find-row-link.nut @@ -0,0 +1,4 @@ + function fillLog(logObj) { + let rowName =$"row{logObj.idx}" + let rowObj = this.listObj.findObject(rowName) + let rowData = getUserlogViewData(logObj, this.ugcAllowed) diff --git a/patches/gui/battle/open-replay-from-battle-log/find-state.nut b/patches/gui/battle/open-replay-from-battle-log/find-state.nut new file mode 100644 index 0000000..871c4ad --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/find-state.nut @@ -0,0 +1 @@ + curPage = null diff --git a/patches/gui/battle/open-replay-from-battle-log/patch.jsonc b/patches/gui/battle/open-replay-from-battle-log/patch.jsonc new file mode 100644 index 0000000..751fca7 --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/patch.jsonc @@ -0,0 +1,34 @@ +// Add a local replay link to a battle log entry when its recording is available. +// The stock battle log only links to the official server replay page. +// Without this link, players must find the recording in the separate Replay list. +{ + "id": "battle/open-replay-from-battle-log", + "title": "Open the local recording from its battle log entry", + "features": [ + "M-Replays" + ], + "variants": [ + { + "written_for": "2.61.0.37", + "file": "scripts/userlog/userlog.nut", + "edits": [ + { + "find": "find-state.nut", + "replace": "replace-state.nut" + }, + { + "find": "find-refresh.nut", + "replace": "replace-refresh.nut" + }, + { + "find": "find-row-link.nut", + "replace": "replace-row-link.nut" + }, + { + "find": "find-click.nut", + "replace": "replace-click.nut" + } + ] + } + ] +} diff --git a/patches/gui/battle/open-replay-from-battle-log/replace-click.nut b/patches/gui/battle/open-replay-from-battle-log/replace-click.nut new file mode 100644 index 0000000..74eaeba --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/replace-click.nut @@ -0,0 +1,30 @@ + function onViewLocalBattleReplay(obj) { + let logIdx = to_integer_safe(obj?.logIdx, -1) + let startReplay = function() { + if (!isInMenu.get() || !checkObj(this.scene)) + return + + let logObj = this.logs?.findvalue(@(entry) entry.idx == logIdx) + if (logObj?.type != EULT_SESSION_RESULT || logObj?.wtoSessionId == null) + return + + let replayScreen = require("%scripts/replays/replayScreen.nut") + // The recording may have been renamed or deleted since the log was opened. + this.localBattleReplays = replayScreen?.getLocalBattleReplays?() ?? {} + let replay = this.localBattleReplays?[logObj.wtoSessionId] + if (replay == null) { + this.initPage(this.curPage) + return + } + + replayScreen?.viewLocalBattleReplay?(replay, function() { + require("%scripts/mainmenu/guiStartMainmenu.nut").gui_start_mainmenu() + let { loadHandler } = require("%scripts/baseGuiHandlerManagerWT.nut") + let { get_gui_handler } = require("%scripts/sqDagui/framework/gui_handlers.nut") + loadHandler(get_gui_handler("UserLogHandler")) + }) + }.bindenv(this) + this.checkedNewFlight(@() defer(startReplay)) + } + + function copyToClipboard() { diff --git a/patches/gui/battle/open-replay-from-battle-log/replace-refresh.nut b/patches/gui/battle/open-replay-from-battle-log/replace-refresh.nut new file mode 100644 index 0000000..37580ba --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/replace-refresh.nut @@ -0,0 +1,2 @@ + this.curPage = page + this.localBattleReplays = null diff --git a/patches/gui/battle/open-replay-from-battle-log/replace-row-link.nut b/patches/gui/battle/open-replay-from-battle-log/replace-row-link.nut new file mode 100644 index 0000000..be61a31 --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/replace-row-link.nut @@ -0,0 +1,22 @@ + function addLocalReplayLink(logObj, rowData) { + let sessionId = logObj?.wtoSessionId + if (logObj.type != EULT_SESSION_RESULT || sessionId == null) + return + + if (this.localBattleReplays == null) { + let replayScreen = require("%scripts/replays/replayScreen.nut") + this.localBattleReplays = replayScreen?.getLocalBattleReplays?() ?? {} + } + if (!(sessionId in this.localBattleReplays)) + return + + let link = format("button { talign:t='left'; text:t='#mainmenu/btnViewReplay'; logIdx:t='%d'; " + + "on_click:t='onViewLocalBattleReplay'; underline{} }", logObj.idx) + rowData.descriptionBlk <- link + (rowData?.descriptionBlk ?? "") + } + + function fillLog(logObj) { + let rowName =$"row{logObj.idx}" + let rowObj = this.listObj.findObject(rowName) + let rowData = getUserlogViewData(logObj, this.ugcAllowed) + this.addLocalReplayLink(logObj, rowData) diff --git a/patches/gui/battle/open-replay-from-battle-log/replace-state.nut b/patches/gui/battle/open-replay-from-battle-log/replace-state.nut new file mode 100644 index 0000000..13a3737 --- /dev/null +++ b/patches/gui/battle/open-replay-from-battle-log/replace-state.nut @@ -0,0 +1,2 @@ + curPage = null + localBattleReplays = null diff --git a/patches/gui/battle/play-local-battle-replay/find-exports.nut b/patches/gui/battle/play-local-battle-replay/find-exports.nut new file mode 100644 index 0000000..8aa1866 --- /dev/null +++ b/patches/gui/battle/play-local-battle-replay/find-exports.nut @@ -0,0 +1,2 @@ +return { + guiStartReplayBattle diff --git a/patches/gui/battle/play-local-battle-replay/find-lookup.nut b/patches/gui/battle/play-local-battle-replay/find-lookup.nut new file mode 100644 index 0000000..de7b59a --- /dev/null +++ b/patches/gui/battle/play-local-battle-replay/find-lookup.nut @@ -0,0 +1 @@ +function getReplayUrlBySessionId(sessionId) { diff --git a/patches/gui/battle/play-local-battle-replay/find-playback.nut b/patches/gui/battle/play-local-battle-replay/find-playback.nut new file mode 100644 index 0000000..54982d1 --- /dev/null +++ b/patches/gui/battle/play-local-battle-replay/find-playback.nut @@ -0,0 +1,4 @@ + setBackFromReplaysFn(backToReplays, true) + reqUnlockByClient("view_replay") + currentReplay.path = this.replays[index].path + on_view_replay(currentReplay.path) diff --git a/patches/gui/battle/play-local-battle-replay/patch.jsonc b/patches/gui/battle/play-local-battle-replay/patch.jsonc new file mode 100644 index 0000000..15c50fb --- /dev/null +++ b/patches/gui/battle/play-local-battle-replay/patch.jsonc @@ -0,0 +1,30 @@ +// Find playable local replays by the battle ID stored in their metadata. +// The battle log needs the client's replay catalog and local playback entry point. +// Without this lookup, the local battle record cannot open a validated replay. +{ + "id": "battle/play-local-battle-replay", + "title": "Find recorded local battles and use the native replay player", + "features": [ + "M-Replays" + ], + "variants": [ + { + "written_for": "2.61.0.37", + "file": "scripts/replays/replayscreen.nut", + "edits": [ + { + "find": "find-lookup.nut", + "replace": "replace-lookup.nut" + }, + { + "find": "find-playback.nut", + "replace": "replace-playback.nut" + }, + { + "find": "find-exports.nut", + "replace": "replace-exports.nut" + } + ] + } + ] +} diff --git a/patches/gui/battle/play-local-battle-replay/replace-exports.nut b/patches/gui/battle/play-local-battle-replay/replace-exports.nut new file mode 100644 index 0000000..55e887c --- /dev/null +++ b/patches/gui/battle/play-local-battle-replay/replace-exports.nut @@ -0,0 +1,4 @@ +return { + getLocalBattleReplays + viewLocalBattleReplay + guiStartReplayBattle diff --git a/patches/gui/battle/play-local-battle-replay/replace-lookup.nut b/patches/gui/battle/play-local-battle-replay/replace-lookup.nut new file mode 100644 index 0000000..d02aac5 --- /dev/null +++ b/patches/gui/battle/play-local-battle-replay/replace-lookup.nut @@ -0,0 +1,37 @@ +function playLocalReplay(path, onReturn, isBackToReplayList) { + setBackFromReplaysFn(onReturn, isBackToReplayList) + reqUnlockByClient("view_replay") + currentReplay.path = path + on_view_replay(currentReplay.path) +} + +function getLocalBattleReplays() { + let replaysBySession = {} + if (!hasFeature("ClientReplay") || !is_replay_turned_on()) + return replaysBySession + + foreach (replay in get_replays_list()) { + if (!canPlayReplay(replay)) + continue + let replayInfo = get_replay_info(replay.path) + if (replayInfo == null || isCorruptedReplay(replayInfo)) + continue + let sessionId = replayInfo?.comments?.uiScriptsData?.wtoSessionId + if (typeof sessionId == "string" && !(sessionId in replaysBySession)) + replaysBySession[sessionId] <- replay + } + return replaysBySession +} + +function viewLocalBattleReplay(replay, onReturn) { + if (!canPlayReplay(replay) || !canJoinFlightMsgBox()) + return + + set_presence_to_player("replay") + playLocalReplay(replay.path, function() { + resetSessionLobbyPlayersInfo() + onReturn() + }, false) +} + +function getReplayUrlBySessionId(sessionId) { diff --git a/patches/gui/battle/play-local-battle-replay/replace-playback.nut b/patches/gui/battle/play-local-battle-replay/replace-playback.nut new file mode 100644 index 0000000..76a4405 --- /dev/null +++ b/patches/gui/battle/play-local-battle-replay/replace-playback.nut @@ -0,0 +1 @@ + playLocalReplay(this.replays[index].path, backToReplays, true) diff --git a/patches/gui/battle/tag-local-battle-replay/find-metadata.nut b/patches/gui/battle/tag-local-battle-replay/find-metadata.nut new file mode 100644 index 0000000..579313b --- /dev/null +++ b/patches/gui/battle/tag-local-battle-replay/find-metadata.nut @@ -0,0 +1 @@ + blk.uiScriptsData.playersInfo = datablockConverter.dataToBlk(getSessionLobbyPlayersInfo()) diff --git a/patches/gui/battle/tag-local-battle-replay/patch.jsonc b/patches/gui/battle/tag-local-battle-replay/patch.jsonc new file mode 100644 index 0000000..c041983 --- /dev/null +++ b/patches/gui/battle/tag-local-battle-replay/patch.jsonc @@ -0,0 +1,22 @@ +// Store the local battle ID in the replay's script metadata when the game writes it. +// The local service knows the battle ID; only the game writes the native replay file. +// Without the ID, the battle log cannot identify its recording after a rename or restart. +{ + "id": "battle/tag-local-battle-replay", + "title": "Store the local battle ID in the native replay", + "features": [ + "M-Replays" + ], + "variants": [ + { + "written_for": "2.61.0.37", + "file": "scripts/replays/replaymetadata.nut", + "edits": [ + { + "find": "find-metadata.nut", + "replace": "replace-metadata.nut" + } + ] + } + ] +} diff --git a/patches/gui/battle/tag-local-battle-replay/replace-metadata.nut b/patches/gui/battle/tag-local-battle-replay/replace-metadata.nut new file mode 100644 index 0000000..a7f5b0c --- /dev/null +++ b/patches/gui/battle/tag-local-battle-replay/replace-metadata.nut @@ -0,0 +1,4 @@ + blk.uiScriptsData.playersInfo = datablockConverter.dataToBlk(getSessionLobbyPlayersInfo()) + let sessionId = require("nestdb").ndbTryRead(["wto", "activeBattle"])?.sessionId + if (sessionId != null && !is_replay_playing()) + blk.uiScriptsData.wtoSessionId = sessionId