diff --git a/apps/launcher/src/main/services/copies/relocate-copy.ts b/apps/launcher/src/main/services/copies/relocate-copy.ts index 3a58b2c..c34ee2d 100644 --- a/apps/launcher/src/main/services/copies/relocate-copy.ts +++ b/apps/launcher/src/main/services/copies/relocate-copy.ts @@ -2,7 +2,7 @@ import { AppError } from '@shared/errors.ts'; import type { Copies } from '@shared/schemas/install.ts'; import { inspectGameFolder } from '../game-folder/inspect-game-folder.ts'; import { hydrateCopiesStatus, relocateCopyRecord } from '../install/install-record.ts'; -import { backUpStockFiles } from '../install/stock-backup.ts'; +import { backUpStockFiles, installStockSource, refreshStockBackup } from '../install/stock-backup.ts'; /** * Re-point an existing registered client to its moved folder while keeping its id, name, saves, @@ -12,7 +12,10 @@ export async function relocateCopy(id: string, newPath: string): Promise const game = await inspectGameFolder(newPath); if (game.missingFiles.length) throw new AppError('not_a_game_folder', { path: newPath }); if (game.needsStockSource) throw new AppError('stock_source_invalid'); - const stockBackupPath = await backUpStockFiles(game.resolvedPath); + const stock = await installStockSource(game.resolvedPath, game.version); + const stockBackupPath = stock.refresh + ? await refreshStockBackup(game.resolvedPath) + : await backUpStockFiles(game.resolvedPath); const updated = await relocateCopyRecord(id, { copyPath: newPath, stockBackupPath, diff --git a/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts b/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts index 92001b0..d1aa5dd 100644 --- a/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts +++ b/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts @@ -23,28 +23,43 @@ export async function inspectGameFolder(path: string): Promise exists(join(exeDir, file))), - )).some(Boolean); - needsStockSource = hasMarkerFile || (executableBytes !== null && executableBytes.includes(PATCHED_EXE_MARKER)); + if (hasStockFiles && backupVersion !== null && liveVersion !== null && backupVersion !== liveVersion) { + // A stale stock backup only needs an external stock source if the live executable is already + // patched; an unpatched live executable can refresh wtoffline/stock directly during install. + needsStockSource = liveExePatched; + } else { + const exeDir = join(resolved, dirname(GAME_FILES.executable)); + const hasMarkerFile = (await Promise.all( + PATCH_MARKER_FILES.map((file) => exists(join(exeDir, file))), + )).some(Boolean); + needsStockSource = hasMarkerFile || liveExePatched; + } } return { path, diff --git a/apps/launcher/src/main/services/install/install-game.ts b/apps/launcher/src/main/services/install/install-game.ts index acb3f3f..402469f 100644 --- a/apps/launcher/src/main/services/install/install-game.ts +++ b/apps/launcher/src/main/services/install/install-game.ts @@ -12,7 +12,7 @@ import { discardDecalCache, importDecalCache } from './decals.ts'; import { hardlinkResource, hasHardlinkEvidence, verifyHardlinkResource } from './hardlink-files.ts'; import { canonicalCopyPath, copyPathContains, requireAvailableCopy, writeInstallRecord } from './install-record.ts'; import { checkPatches } from './patch-check.ts'; -import { backUpStockFiles, backUpStockFilesFrom, installStockSource, refreshStockBackup, requireStockBackupLocation, stockBackupPath } from './stock-backup.ts'; +import { backUpStockFiles, installStockSource, refreshStockBackup, refreshStockBackupFrom, requireStockBackupLocation, stockBackupPath } from './stock-backup.ts'; /** * Install the offline version: check the patches against the player's game, @@ -95,7 +95,7 @@ async function install(request: InstallRequest, signal: AbortSignal, report: (pr report({ phase: 'backing-up', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 }); const stockBackup = externalStockPath - ? await backUpStockFilesFrom(copyPath, externalStockPath) + ? await refreshStockBackupFrom(copyPath, externalStockPath) : (request.method === 'in-place' || request.method === 'existing') && stock.refresh ? await refreshStockBackup(copyPath) : await backUpStockFiles(copyPath); diff --git a/apps/launcher/src/main/services/install/stock-backup.ts b/apps/launcher/src/main/services/install/stock-backup.ts index 9130682..b1db289 100644 --- a/apps/launcher/src/main/services/install/stock-backup.ts +++ b/apps/launcher/src/main/services/install/stock-backup.ts @@ -50,22 +50,36 @@ export async function backUpStockFilesFrom(copyFolder: string, sourceFolder: str return backup; } -/** A new game version must pass the patch checks before replacing an existing stock backup. */ +/** A new game version or damaged backup must pass the patch checks before replacing wtoffline/stock. */ export async function installStockSource(copyFolder: string, version: string | null) { const backup = await requireStockBackupLocation(copyFolder); - if (!await exists(join(backup, GAME_FILES.executable))) return { path: copyFolder, refresh: await exists(backup) }; - const backedUpVersion = executableVersion(await readFile(join(backup, GAME_FILES.executable))); - return version !== null && backedUpVersion !== version ? { path: copyFolder, refresh: true } : { path: backup, refresh: false }; + const backupExe = join(backup, GAME_FILES.executable); + if (!await exists(backupExe)) return { path: copyFolder, refresh: await exists(backup) }; + let backedUpVersion: string | null = null; + try { + backedUpVersion = executableVersion(await readFile(backupExe)); + } catch (error) { + console.warn('[stock-backup] unreadable backed-up executable, will refresh:', backupExe, error); + return { path: copyFolder, refresh: true }; + } + return backedUpVersion === null || (version !== null && backedUpVersion !== version) + ? { path: copyFolder, refresh: true } + : { path: backup, refresh: false }; } export async function refreshStockBackup(copyFolder: string): Promise { + return refreshStockBackupFrom(copyFolder, copyFolder); +} + +/** Replace wtoffline/stock atomically with the four stock files from `sourceFolder`. */ +export async function refreshStockBackupFrom(copyFolder: string, sourceFolder: string): Promise { const backup = await requireStockBackupLocation(copyFolder); return await changeCopyFiles(copyFolder, async (incoming) => { const replace = Object.values(GAME_FILES).map((file) => join(STOCK_BACKUP_FOLDER, file)); for (const file of Object.values(GAME_FILES)) { const target = join(incoming, STOCK_BACKUP_FOLDER, file); await mkdir(dirname(target), { recursive: true }); - await copyFile(join(copyFolder, file), target); + await copyFile(join(sourceFolder, file), target); } return { replace, remove: [] }; }, async () => backup); diff --git a/apps/launcher/src/main/services/launch/launch-controller.ts b/apps/launcher/src/main/services/launch/launch-controller.ts index 3073341..a3c5a7b 100644 --- a/apps/launcher/src/main/services/launch/launch-controller.ts +++ b/apps/launcher/src/main/services/launch/launch-controller.ts @@ -144,6 +144,10 @@ async function planLaunch(job: LaunchJob, record: InstallRecord, settings: Setti } const currentVersion = await readVersion(record.copyPath, signal); if (!currentVersion || currentVersion !== record.gameVersion) { + console.warn( + `[launch] client version changed: recorded=${record.gameVersion ?? 'unknown'}, ` + + `actual=${currentVersion ?? 'missing'} (${record.copyPath})`, + ); update(job, { phase: 'version-changed', actualVersion: currentVersion }); return null; } @@ -171,6 +175,11 @@ async function planLaunch(job: LaunchJob, record: InstallRecord, settings: Setti ]); signal.throwIfAborted(); if (!copyVersion || copyVersion !== stockVersion) { + console.warn( + `[launch] copy/stock version mismatch: copy=${copyVersion ?? 'missing'} (${copyPath}), ` + + `stock=${stockVersion ?? 'missing'} (${stockPath})`, + ); + if (!lab && !stockVersion) throw new AppError('launch_stock_missing'); throw new AppError(lab ? 'launch_lab_version' : 'launch_stock_version'); } if (games) throw new AppError('launch_game_running'); diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index f91cecc..d20b31a 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -706,6 +706,7 @@ "launch_steam_confirmation_required": "Confirm the Steam locations in Client Maintenance before launching.", "launch_location": "The client, stock backup, or data folder location is invalid.", "launch_stock_version": "The stock backup and client versions do not match.", + "launch_stock_missing": "The original file backup (wtoffline\\stock) is missing or unreadable. Check your security software, or remove this client entry and add it again.", "launch_build_failed": "The game files could not be generated.", "launch_build_unavailable": "The build found unavailable patches that require review.", "launch_port_busy": "The local server port is already in use.", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index 91d68a5..4e17004 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -706,6 +706,7 @@ "launch_steam_confirmation_required": "请在客户端维护中确认 Steam 目录后再启动。", "launch_location": "客户端、原版文件备份或数据目录的位置无效。", "launch_stock_version": "原版文件备份的版本与客户端不一致。", + "launch_stock_missing": "缺少或无法读取原版文件备份(wtoffline\\stock)。请检查安全软件拦截记录,或移除此客户端登记后重新添加。", "launch_build_failed": "无法生成游戏文件。", "launch_build_unavailable": "生成游戏文件时发现需要重新确认的不可用补丁。", "launch_port_busy": "本地服务器端口已被占用。", diff --git a/apps/launcher/src/shared/errors.ts b/apps/launcher/src/shared/errors.ts index 22484fc..dfdd5ac 100644 --- a/apps/launcher/src/shared/errors.ts +++ b/apps/launcher/src/shared/errors.ts @@ -59,6 +59,8 @@ export const APP_ERROR_CODES = [ 'launch_steam_confirmation_required', 'launch_location', 'launch_stock_version', + /** The wtoffline/stock backup executable is missing or unreadable before launch. */ + 'launch_stock_missing', 'launch_build_failed', 'launch_build_unavailable', 'launch_port_busy',