diff --git a/packages/patcher/src/build-game-copy.ts b/packages/patcher/src/build-game-copy.ts new file mode 100644 index 0000000..06c25ad --- /dev/null +++ b/packages/patcher/src/build-game-copy.ts @@ -0,0 +1,108 @@ +/** + * Build the files of the game copy in memory: the three rebuilt data packs, + * the patched executable, the network hook library and its settings. Nothing is written here + * (write-game-copy.ts does that), so a caller can show the report first and let the player decide. + * + * Everything the build needs from outside comes in as an input: the stock files, the patch + * folders, the hook library, and the multi-vehicle pack ids the local server will sell from its + * data folder. + */ +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import type { PatchFailure } from '@wto/exepatch'; +import { rebuildCharPack, type CharPackResult } from './char-pack.ts'; +import { blockingFailures } from './essential-features.ts'; +import { patchExecutable } from './executable.ts'; +import { GAME_FILES } from './game-copy.ts'; +import { rebuildGuiPack } from './gui-pack.ts'; +import { rebuildMainPack } from './main-pack.ts'; +import type { AddressChange } from './network/address-rewrite.ts'; +import { localEndpoint, type LocalEndpoint } from './network/local-endpoint.ts'; +import { NETWORK_HOOK_LIBRARY, networkHookSettings } from './network/network-hook.ts'; +import { offlinePackBundleGuids } from './store/offline-bundles.ts'; + +/** The stock files the build changes. */ +export interface StockGameFiles { + readonly charPack: Uint8Array; + readonly mainPack: Uint8Array; + readonly guiPack: Uint8Array; + readonly executable: Uint8Array; +} + +export interface GameCopyInputs { + readonly stock: StockGameFiles; + /** The local server's port, written into the data packs and the hook settings. */ + readonly port: number; + /** Folder of the exe patch definitions. */ + readonly exePatches: string; + /** Folder of the GUI script patch definitions. */ + readonly guiPatches: string; + /** wto_ws.dll, built from native/wto-net. */ + readonly networkHookLibrary: Uint8Array; + /** Ids of the multi-vehicle packs the local server sells (@wto/server multiVehiclePackIds). */ + readonly multiVehiclePackIds: readonly string[]; + /** Store the placeholder decal index; false when the player's own web cache is copied. */ + readonly placeholderDecals: boolean; +} + +/** One file of the game copy, by its path relative to the copy folder. */ +export interface GameCopyFile { + readonly path: string; + readonly content: Uint8Array; +} + +export interface GameCopyBuild { + /** Every file to write, with unavailable patches left out. */ + readonly files: readonly GameCopyFile[]; + readonly endpoint: LocalEndpoint; + readonly exePatches: { readonly applied: readonly { readonly patchId: string; readonly rva: number }[]; readonly failures: readonly PatchFailure[] }; + readonly guiPatches: { readonly applied: readonly string[]; readonly failures: readonly PatchFailure[] }; + /** Unavailable patches that must stop an installation (essential-features.ts). */ + readonly blocking: readonly PatchFailure[]; + readonly charPack: Omit; + /** Addresses in aces.vromfs.bin config/settings.blk now pointing at the local server. */ + readonly engineAddresses: readonly AddressChange[]; + /** Store bundle GUIDs registered in config/gui.blk. */ + readonly bundleGuids: number; +} + +export function readStockGameFiles(folder: string): StockGameFiles { + return { + charPack: readFileSync(join(folder, GAME_FILES.charPack)), + mainPack: readFileSync(join(folder, GAME_FILES.mainPack)), + guiPack: readFileSync(join(folder, GAME_FILES.guiPack)), + executable: readFileSync(join(folder, GAME_FILES.executable)), + }; +} + +export function buildGameCopy(inputs: GameCopyInputs): GameCopyBuild { + const endpoint = localEndpoint(inputs.port); + const executable = patchExecutable(inputs.stock.executable, inputs.exePatches); + const { pack: charPack, ...charReport } = rebuildCharPack(inputs.stock.charPack, endpoint, { placeholderDecals: inputs.placeholderDecals }); + const bundles = offlinePackBundleGuids(inputs.stock.charPack, inputs.multiVehiclePackIds); + const mainPack = rebuildMainPack(inputs.stock.mainPack, endpoint, bundles); + const guiPack = rebuildGuiPack(inputs.stock.guiPack, endpoint, inputs.guiPatches); + + const executableFolder = dirname(GAME_FILES.executable); + const hookSettings = networkHookSettings(endpoint); + const files: GameCopyFile[] = [ + { path: GAME_FILES.charPack, content: charPack }, + { path: GAME_FILES.mainPack, content: mainPack.pack }, + { path: GAME_FILES.guiPack, content: guiPack.pack }, + { path: GAME_FILES.executable, content: executable.executable }, + { path: join(executableFolder, NETWORK_HOOK_LIBRARY), content: inputs.networkHookLibrary }, + { path: join(executableFolder, hookSettings.name), content: hookSettings.content }, + ]; + + const failures = [...executable.plan.failures, ...guiPack.failures]; + return { + files, + endpoint, + exePatches: { applied: executable.plan.writes.map((write) => ({ patchId: write.patchId, rva: write.rva })), failures: executable.plan.failures }, + guiPatches: { applied: guiPack.applied.map((patch) => patch.id), failures: guiPack.failures }, + blocking: blockingFailures(failures), + charPack: charReport, + engineAddresses: mainPack.addresses, + bundleGuids: bundles.length, + }; +} diff --git a/packages/patcher/src/essential-features.ts b/packages/patcher/src/essential-features.ts new file mode 100644 index 0000000..230fe6e --- /dev/null +++ b/packages/patcher/src/essential-features.ts @@ -0,0 +1,24 @@ +/** + * Which unavailable patches stop an installation. + * + * Any other missing patch only costs the features it lists, and the player may go on without + * them. A patch tagged with one of these features keeps the copy from running at all, or keeps + * it apart from the online game: without it the copy would read or write the online game's data, + * load the anti-cheat, or connect to Gaijin (working rules 18). The tags are the feature + * inventory's section A rows the patch definitions name in `features`. + */ +import type { PatchFailure } from '@wto/exepatch'; + +export const ESSENTIAL_FEATURES: ReadonlySet = new Set([ + /** The game starts offline at all (e.g. the data pack signature check). */ + 'A-离线启动', + /** Nothing of the online game's data or identity is touched. */ + 'A-与正版隔离', + /** Nothing connects to Gaijin. */ + 'A-不连 Gaijin', +]); + +/** The failures that must stop an installation. */ +export function blockingFailures(failures: readonly PatchFailure[]): PatchFailure[] { + return failures.filter((failure) => failure.features.some((feature) => ESSENTIAL_FEATURES.has(feature))); +} diff --git a/packages/patcher/src/executable.ts b/packages/patcher/src/executable.ts index 03a35ad..1ae1fa8 100644 --- a/packages/patcher/src/executable.ts +++ b/packages/patcher/src/executable.ts @@ -1,19 +1,19 @@ /** - * Patch a copy of aces.exe with every definition under patches/exe/. When any patch cannot be - * applied, no executable is produced; the result lists the unavailable patches and the - * features they cover. + * Patch a copy of aces.exe with every definition under the exe patch folder. A patch that cannot + * be applied (site missing or ambiguous, original bytes differ, or a patch it requires failed) is + * left out and listed with the features it covers; whether a copy with + * patches missing may be installed is the caller's decision (essential-features.ts). */ import { applyWrites, describePlan, loadPatches, PeImage, planPatches, type PatchPlan } from '@wto/exepatch'; export interface ExecutableResult { - /** The patched executable, or null when some patch was unavailable. */ - readonly executable: Uint8Array | null; + /** The executable with every available patch written. */ + readonly executable: Uint8Array; readonly plan: PatchPlan; readonly description: string; } export function patchExecutable(stockExecutable: Uint8Array, patchesRoot: string): ExecutableResult { const plan = planPatches(new PeImage(stockExecutable), loadPatches(patchesRoot)); - const executable = plan.failures.length ? null : applyWrites(stockExecutable, plan.writes); - return { executable, plan, description: describePlan(plan) }; + return { executable: applyWrites(stockExecutable, plan.writes), plan, description: describePlan(plan) }; } diff --git a/packages/patcher/src/game-copy.ts b/packages/patcher/src/game-copy.ts index 127a0a5..0e6d5a3 100644 --- a/packages/patcher/src/game-copy.ts +++ b/packages/patcher/src/game-copy.ts @@ -1,7 +1,7 @@ /** * Files the build reads from a stock game folder and writes into the game copy, and the - * checks that keep it from writing where it must not (working-rules 9: never the Steam - * installation, never the folder it reads from). + * checks that keep it from writing where it must not: never the folder it reads from, and a + * Steam library only when the player has confirmed it. */ import { realpathSync } from 'node:fs'; import { join, resolve, sep } from 'node:path'; @@ -13,15 +13,29 @@ export const GAME_FILES = { executable: join('win64', 'aces.exe'), } as const; -export function assertWritableCopy(stockFolder: string, copyFolder: string): void { +export interface WritableCopyOptions { + /** + * The player was told that installing into a Steam library changes the online client, can be + * undone by Steam's file check or an update, and risks a ban when started online, and chose to + * go on. Development tools never set it. + */ + readonly steamLibraryConfirmed?: boolean; +} + +export function assertWritableCopy(stockFolder: string, copyFolder: string, options: WritableCopyOptions = {}): void { const stock = canonical(stockFolder); const copy = canonical(copyFolder); if (copy === stock) throw new Error('the output folder is the folder the stock files are read from'); - if (copy.toLowerCase().split(sep).includes('steamapps')) { - throw new Error(`refusing to write into a Steam library: ${copy}`); + if (isInSteamLibrary(copy) && !options.steamLibraryConfirmed) { + throw new Error(`refusing to write into a Steam library without the player's confirmation: ${copy}`); } } +/** Whether a folder lies inside a Steam library (a `steamapps` folder on its path). */ +export function isInSteamLibrary(folder: string): boolean { + return canonical(folder).toLowerCase().split(sep).includes('steamapps'); +} + function canonical(folder: string): string { try { return realpathSync(folder); diff --git a/packages/patcher/src/gui-pack.ts b/packages/patcher/src/gui-pack.ts index 7746f72..5c47b11 100644 --- a/packages/patcher/src/gui-pack.ts +++ b/packages/patcher/src/gui-pack.ts @@ -1,21 +1,28 @@ /** - * Rebuild gui.vromfs.bin by applying the script patch definitions in `patches/gui/` + * Rebuild gui.vromfs.bin by applying the script patch definitions in the GUI patch folder * (implementation notes, format in gui-patch-definition.ts). * - * Every edit must find its stock text exactly once in the current script; anything else - * refuses the whole build rather than writing a half-patched archive. + * Every edit must find its stock text exactly once in the current script. A patch with an edit + * that does not is left out whole, never half applied, and listed with the features it covers + *, the same way an unavailable exe patch is; the other patches are applied. */ -import { getFile, putFile, readArchive, writeArchive } from '@wto/vromfs'; +import type { PatchFailure } from '@wto/exepatch'; +import { getFile, putFile, readArchive, writeArchive, type Archive } from '@wto/vromfs'; import { loadGuiPatches, type GuiScriptPatch } from './gui-patch-definition.ts'; import type { LocalEndpoint } from './network/local-endpoint.ts'; const ENDPOINT_PLACEHOLDER = '{{LOCAL_ENDPOINT}}'; export interface GuiPackResult { + /** The data pack with every applicable patch written. */ readonly pack: Uint8Array; readonly applied: readonly GuiScriptPatch[]; + readonly failures: readonly PatchFailure[]; } +/** The stock text of an edit was not found exactly once, or the target script is missing. */ +class GuiPatchMismatch extends Error {} + export function rebuildGuiPack( stockPack: Uint8Array, endpoint: LocalEndpoint, @@ -24,21 +31,32 @@ export function rebuildGuiPack( const patches = loadGuiPatches(patchesFolder); const archive = readArchive(stockPack); const hostPortText = `${endpoint.host}:${endpoint.port}`; + const applied: GuiScriptPatch[] = []; + const failures: PatchFailure[] = []; for (const patch of patches) { - let current = Buffer.from(getFile(archive, patch.file)).toString('utf8'); - const newline = current.includes('\r\n') ? '\r\n' : '\n'; - for (const [index, edit] of patch.edits.entries()) { - const replace = edit.replace.replaceAll('\n', newline).replaceAll(ENDPOINT_PLACEHOLDER, hostPortText); - current = replaceUnique(current, edit.find, replace, `GUI patch ${patch.id} edit ${index + 1} in ${patch.file}`); + try { + putFile(archive, patch.file, Buffer.from(patchedScript(archive, patch, hostPortText), 'utf8')); + applied.push(patch); + } catch (error) { + if (!(error instanceof GuiPatchMismatch)) throw error; + failures.push({ patchId: patch.id, features: patch.features, reason: error.message }); } - putFile(archive, patch.file, Buffer.from(current, 'utf8')); } - return { - pack: writeArchive(archive), - applied: patches, - }; + return { pack: writeArchive(archive), applied, failures }; +} + +/** The target script with every edit of `patch` made; throws GuiPatchMismatch before any change. */ +function patchedScript(archive: Archive, patch: GuiScriptPatch, hostPortText: string): string { + if (!archive.files.has(patch.file)) throw new GuiPatchMismatch(`the data pack has no script ${patch.file}`); + let current = Buffer.from(getFile(archive, patch.file)).toString('utf8'); + const newline = current.includes('\r\n') ? '\r\n' : '\n'; + for (const [index, edit] of patch.edits.entries()) { + const replace = edit.replace.replaceAll('\n', newline).replaceAll(ENDPOINT_PLACEHOLDER, hostPortText); + current = replaceUnique(current, edit.find, replace, `edit ${index + 1} in ${patch.file}`); + } + return current; } /** @@ -49,8 +67,8 @@ export function rebuildGuiPack( function replaceUnique(text: string, find: string, replace: string, label: string): string { const { normalized, original } = withoutCarriageReturns(text); const first = normalized.indexOf(find); - if (first === -1) throw new Error(`${label}: stock text not found; refusing to write`); - if (normalized.indexOf(find, first + find.length) !== -1) throw new Error(`${label}: stock text appears more than once; refusing to write`); + if (first === -1) throw new GuiPatchMismatch(`${label}: stock text not found`); + if (normalized.indexOf(find, first + find.length) !== -1) throw new GuiPatchMismatch(`${label}: stock text appears more than once`); return text.slice(0, original[first]!) + replace + text.slice(original[first + find.length]!); } diff --git a/packages/patcher/src/index.ts b/packages/patcher/src/index.ts index 20b7a32..1adad48 100644 --- a/packages/patcher/src/index.ts +++ b/packages/patcher/src/index.ts @@ -1,12 +1,22 @@ /** * The patcher: builds the game copy by pointing the client at the local server * and patching the executable. Used by the development script scripts/build-game-copy.ts and by - * the launcher. The patch definitions and the network hook library are given by the caller. + * the launcher. The patch definitions, the network hook library and the store pack ids are given + * by the caller. */ +export { + buildGameCopy, + readStockGameFiles, + type GameCopyBuild, + type GameCopyFile, + type GameCopyInputs, + type StockGameFiles, +} from './build-game-copy.ts'; export { NETWORK_CONFIG_PATH, rebuildCharPack, type CharPackResult } from './char-pack.ts'; export { copyPlayerDecalCache, playerDecalCacheProblem } from './decals/player-decal-cache.ts'; +export { blockingFailures, ESSENTIAL_FEATURES } from './essential-features.ts'; export { patchExecutable, type ExecutableResult } from './executable.ts'; -export { assertWritableCopy, GAME_FILES } from './game-copy.ts'; +export { assertWritableCopy, GAME_FILES, isInSteamLibrary, type WritableCopyOptions } from './game-copy.ts'; export { rebuildGuiPack, type GuiPackResult } from './gui-pack.ts'; export { loadGuiPatches, type GuiScriptEdit, type GuiScriptPatch } from './gui-patch-definition.ts'; export { ENGINE_SETTINGS_PATH, EXTRA_STORE_BUNDLE_GUID_MAP, EXTRA_STORE_BUNDLE_GUIDS, rebuildMainPack, type MainPackResult } from './main-pack.ts'; @@ -15,3 +25,4 @@ export { hostPort, localEndpoint, localUrl, type LocalEndpoint } from './network export { NETWORK_HOOK_LIBRARY, networkHookSettings } from './network/network-hook.ts'; export { redirectNetworkConfig, type NetworkRedirectReport } from './network/redirect-network-config.ts'; export { offlinePackBundleGuids } from './store/offline-bundles.ts'; +export { writeGameCopy } from './write-game-copy.ts'; diff --git a/packages/patcher/src/write-game-copy.ts b/packages/patcher/src/write-game-copy.ts new file mode 100644 index 0000000..98233f6 --- /dev/null +++ b/packages/patcher/src/write-game-copy.ts @@ -0,0 +1,20 @@ +/** + * Write the built files into the game copy folder. + */ +import { mkdirSync, rmSync, writeFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import type { GameCopyFile } from './build-game-copy.ts'; + +/** Writes every file and returns the full paths written, in order. */ +export function writeGameCopy(copyFolder: string, files: readonly GameCopyFile[]): string[] { + return files.map((file) => { + const path = join(copyFolder, file.path); + mkdirSync(dirname(path), { recursive: true }); + // Remove before writing: a read-only file is replaced instead of failing with EPERM, and a + // file hard-linked to the stock folder gets a new file of its own instead of changing the + // stock one through the link. + rmSync(path, { force: true }); + writeFileSync(path, file.content); + return path; + }); +} diff --git a/scripts/build-game-copy.ts b/scripts/build-game-copy.ts index 339cae3..68305ce 100644 --- a/scripts/build-game-copy.ts +++ b/scripts/build-game-copy.ts @@ -4,7 +4,8 @@ * node scripts/build-game-copy.ts --game --out --port * --data * [--patches ] [--gui-patches ] - * [--native ] [--decal-cache ] [--verbose] + * [--native ] [--decal-cache ] + * [--skip-unavailable] [--verbose] * * Writes /char.vromfs.bin, /aces.vromfs.bin, /gui.vromfs.bin, /win64/aces.exe * and the network hook library the patched executable loads (/win64/wto_ws.dll from --native, @@ -13,32 +14,32 @@ * with that folder's overrides) get bundle GUIDs in gui.blk. --decal-cache names the cache/content * folder of the player's online installation; it is copied to /cache/content, otherwise * char.vromfs.bin gets the placeholder decal index. + * When a patch is unavailable nothing is written, unless --skip-unavailable is given and none of + * the unavailable patches is essential (the patcher's essential-features.ts). * The patch folders and the hook library default to this repository's patches/exe, patches/gui - * and build/native. The launcher runs the same steps at every launch, with the port the player chose. + * and build/native. The launcher runs the same build at every launch, with the port the player chose. */ -import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; -import { dirname, join } from 'node:path'; +import { existsSync, readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { parseArgs } from 'node:util'; +import type { PatchFailure } from '@wto/exepatch'; import { assertWritableCopy, + buildGameCopy, copyPlayerDecalCache, - GAME_FILES, - localEndpoint, NETWORK_HOOK_LIBRARY, - networkHookSettings, - offlinePackBundleGuids, - patchExecutable, playerDecalCacheProblem, - rebuildCharPack, - rebuildGuiPack, - rebuildMainPack, + readStockGameFiles, + writeGameCopy, + type GameCopyBuild, } from '@wto/patcher'; import { multiVehiclePackIds } from '@wto/server'; const REPOSITORY = fileURLToPath(new URL('..', import.meta.url)); const USAGE = 'usage: build-game-copy.ts --game --out --port --data ' - + '[--patches ] [--gui-patches ] [--native ] [--decal-cache ] [--verbose]'; + + '[--patches ] [--gui-patches ] [--native ] [--decal-cache ] ' + + '[--skip-unavailable] [--verbose]'; function main(): number { const { values } = parseArgs({ @@ -51,6 +52,7 @@ function main(): number { 'gui-patches': { type: 'string', default: join(REPOSITORY, 'patches', 'gui') }, native: { type: 'string', default: join(REPOSITORY, 'build', 'native') }, 'decal-cache': { type: 'string' }, + 'skip-unavailable': { type: 'boolean', default: false }, verbose: { type: 'boolean', default: false }, }, }); @@ -59,7 +61,6 @@ function main(): number { return 2; } assertWritableCopy(values.game, values.out); - const endpoint = localEndpoint(Number(values.port)); const decalCache = values['decal-cache']; const decalCacheProblem = decalCache === undefined ? undefined : playerDecalCacheProblem(decalCache); if (decalCacheProblem) { @@ -72,41 +73,28 @@ function main(): number { return 1; } - const executable = patchExecutable(readFileSync(join(values.game, GAME_FILES.executable)), values.patches); - console.log(executable.description); - if (!executable.executable) { - console.error('some patches are unavailable; nothing was written'); + const build = buildGameCopy({ + stock: readStockGameFiles(values.game), + port: Number(values.port), + exePatches: values.patches, + guiPatches: values['gui-patches'], + networkHookLibrary: readFileSync(hookLibraryPath), + multiVehiclePackIds: multiVehiclePackIds(values.data, (line) => console.log(line)), + placeholderDecals: decalCache === undefined, + }); + report(build, values.verbose); + + const failures = [...build.exePatches.failures, ...build.guiPatches.failures]; + if (build.blocking.length) { + console.error(`essential patch(es) unavailable: ${build.blocking.map((failure) => failure.patchId).join(', ')}; nothing was written`); + return 1; + } + if (failures.length && !values['skip-unavailable']) { + console.error('some patches are unavailable; nothing was written (--skip-unavailable writes the copy without them)'); return 1; } - const stockCharPack = readFileSync(join(values.game, GAME_FILES.charPack)); - const charPack = rebuildCharPack(stockCharPack, endpoint, { placeholderDecals: decalCache === undefined }); - console.log(`network.blk: ${charPack.network.addresses.length} address(es) now point to ${endpoint.host}:${endpoint.port}; ` + - `environments configured: ${charPack.network.environments.join(', ')}`); - if (values.verbose) { - for (const change of charPack.network.addresses) console.log(` ${change.path}: ${change.before} -> ${change.after}`); - } - console.log(`game_settings.blk: features on for every player: ${charPack.features.join(', ') || '(already on)'}`); - console.log(`shop.blk: ${charPack.revealedVehicles} hidden vehicles shown in the tech tree`); - if (charPack.placeholderDecals !== undefined) console.log(`dldata: placeholder textures for ${charPack.placeholderDecals} decals`); - - const packBundles = offlinePackBundleGuids(stockCharPack, multiVehiclePackIds(values.data, (line) => console.log(line))); - const mainPack = rebuildMainPack(readFileSync(join(values.game, GAME_FILES.mainPack)), endpoint, packBundles); - console.log(`gui.blk: ${packBundles.length} offline vehicle pack bundle GUID(s) registered`); - console.log(`settings.blk: ${mainPack.addresses.length} address(es) now point to ${endpoint.host}:${endpoint.port}`); - for (const change of mainPack.addresses) console.log(` ${change.path}: ${change.before} -> ${change.after}`); - - const guiPack = rebuildGuiPack(readFileSync(join(values.game, GAME_FILES.guiPack)), endpoint, values['gui-patches']); - console.log(`gui.vromfs.bin: ${guiPack.applied.length} GUI patch(es) applied (${guiPack.applied.map((p) => p.id).join(', ')})`); - - writeOutput(values.out, GAME_FILES.charPack, charPack.pack); - writeOutput(values.out, GAME_FILES.mainPack, mainPack.pack); - writeOutput(values.out, GAME_FILES.guiPack, guiPack.pack); - writeOutput(values.out, GAME_FILES.executable, executable.executable); - const executableFolder = dirname(GAME_FILES.executable); - writeOutput(values.out, join(executableFolder, NETWORK_HOOK_LIBRARY), readFileSync(hookLibraryPath)); - const settings = networkHookSettings(endpoint); - writeOutput(values.out, join(executableFolder, settings.name), settings.content); + for (const path of writeGameCopy(values.out, build.files)) console.log(`wrote ${path}`); if (decalCache !== undefined) { const copied = copyPlayerDecalCache(decalCache, values.out); console.log(`copied the player's web cache to ${copied.copiedTo} (decal indexes: ${copied.decalIndexes.join(', ')})`); @@ -114,14 +102,32 @@ function main(): number { return 0; } -function writeOutput(folder: string, relativePath: string, content: Uint8Array): void { - const path = join(folder, relativePath); - mkdirSync(dirname(path), { recursive: true }); - // Unlink before writing so a read-only target file or a hardlink to the stock folder is - // replaced with a fresh file instead of failing with EPERM or mutating the link target. - rmSync(path, { force: true }); - writeFileSync(path, content); - console.log(`wrote ${path}`); +function report(build: GameCopyBuild, verbose: boolean): void { + const { endpoint, charPack } = build; + const target = `${endpoint.host}:${endpoint.port}`; + console.log(`exe: ${build.exePatches.applied.length} patch(es) ready, ${build.exePatches.failures.length} unavailable`); + for (const write of build.exePatches.applied) console.log(` ready ${write.patchId} at 0x${write.rva.toString(16)}`); + reportFailures(build.exePatches.failures); + console.log(`network.blk: ${charPack.network.addresses.length} address(es) now point to ${target}; ` + + `environments configured: ${charPack.network.environments.join(', ')}`); + if (verbose) { + for (const change of charPack.network.addresses) console.log(` ${change.path}: ${change.before} -> ${change.after}`); + } + console.log(`game_settings.blk: features on for every player: ${charPack.features.join(', ') || '(already on)'}`); + console.log(`shop.blk: ${charPack.revealedVehicles} hidden vehicles shown in the tech tree`); + if (charPack.placeholderDecals !== undefined) console.log(`dldata: placeholder textures for ${charPack.placeholderDecals} decals`); + console.log(`gui.blk: ${build.bundleGuids} offline vehicle pack bundle GUID(s) registered`); + console.log(`settings.blk: ${build.engineAddresses.length} address(es) now point to ${target}`); + for (const change of build.engineAddresses) console.log(` ${change.path}: ${change.before} -> ${change.after}`); + console.log(`gui.vromfs.bin: ${build.guiPatches.applied.length} GUI patch(es) ready, ${build.guiPatches.failures.length} unavailable`); + if (verbose) for (const id of build.guiPatches.applied) console.log(` ready ${id}`); + reportFailures(build.guiPatches.failures); +} + +function reportFailures(failures: readonly PatchFailure[]): void { + for (const failure of failures) console.log(` FAILED ${failure.patchId}: ${failure.reason}`); + const features = [...new Set(failures.flatMap((failure) => failure.features))].sort(); + if (failures.length) console.log(` features affected: ${features.join(', ') || 'none recorded'}`); } process.exitCode = main();