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.
This commit is contained in:
N0VAN0M4LY committed 2026-12-01 11:10:05 +08:00
1 parent 7c2e2250c3
commit 6c55c64222
19 files changed
+203

No files matched your search

@@ -0,0 +1 @@
function copyToClipboard() {
@@ -0,0 +1 @@
this.curPage = page
@@ -0,0 +1,4 @@
function fillLog(logObj) {
let rowName =$"row{logObj.idx}"
let rowObj = this.listObj.findObject(rowName)
let rowData = getUserlogViewData(logObj, this.ugcAllowed)
@@ -0,0 +1 @@
curPage = null
@@ -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"
}
]
}
]
}
@@ -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() {
@@ -0,0 +1,2 @@
this.curPage = page
this.localBattleReplays = null
@@ -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)
@@ -0,0 +1,2 @@
curPage = null
localBattleReplays = null
@@ -0,0 +1,2 @@
return {
guiStartReplayBattle
@@ -0,0 +1 @@
function getReplayUrlBySessionId(sessionId) {
@@ -0,0 +1,4 @@
setBackFromReplaysFn(backToReplays, true)
reqUnlockByClient("view_replay")
currentReplay.path = this.replays[index].path
on_view_replay(currentReplay.path)
@@ -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"
}
]
}
]
}
@@ -0,0 +1,4 @@
return {
getLocalBattleReplays
viewLocalBattleReplay
guiStartReplayBattle
@@ -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) {
@@ -0,0 +1 @@
playLocalReplay(this.replays[index].path, backToReplays, true)
@@ -0,0 +1 @@
blk.uiScriptsData.playersInfo = datablockConverter.dataToBlk(getSessionLobbyPlayersInfo())
@@ -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"
}
]
}
]
}
@@ -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