The LocalMP modules of wto_ws.dll scanned for 42 functions at start-up and used about a hundred structure offsets compiled in as constants, so a game update could move a field without anything noticing. Their needs are now definitions under patches/native/<module>.jsonc, resolved by the patcher when it builds the game copy, the same way exe patches are located: - Locate methods: "string_ref" finds code by the string it loads (optionally with a pattern around the lea, to read the field a scoreboard row stores under that name), and "within" searches a short pattern inside the function of a site located before it (function ranges from the exception directory). - Each module lists its sites (functions, globals, call targets and the instructions whose captures give structure offsets), its features and the modules it requires. A module whose sites are not all found is reported like an unavailable patch, with the modules depending on it. - The resolved values go into wto_ws.cfg as native.<site>[.<capture>] lines, with the executable's PE time stamp and image size so the library can refuse values resolved for another build. - Version records include the native module variants and values. - Patch-set folders: the patcher, the scripts and the launcher take the root of a patch set (exe, gui, native, versions) instead of separate folders. - New feature tags K-Chat and radio and K-Nuclear bomb in both language packs. The library still scans by itself; reading these values is the next change. Checked: root and launcher type checks; all 10 modules resolve on 2.61.0.37, where the 239 values equal what the drafting tool read with a disassembler, and on 2.61.0.43, where every structure offset is unchanged except the GameSaveData HUD event queue (0xae8 -> 0xb18); build-game-copy from 2.61.0.37 into a temporary folder writes the values into wto_ws.cfg.
135 lines
7.0 KiB
TypeScript
135 lines
7.0 KiB
TypeScript
/**
|
|
* Development script: build the game copy from the stock files of a game folder.
|
|
*
|
|
* node scripts/build-game-copy.ts --game <stock game folder> --out <game copy folder> --port <n>
|
|
* --data <local server data folder>
|
|
* [--patches <patch set>]
|
|
* [--native <folder with wto_ws.dll>] [--decal-cache <folder>]
|
|
* [--skip-unavailable] [--verbose]
|
|
*
|
|
* Writes <out>/char.vromfs.bin, <out>/aces.vromfs.bin, <out>/gui.vromfs.bin, <out>/win64/aces.exe
|
|
* and the network hook library the patched executable loads (<out>/win64/wto_ws.dll from --native,
|
|
* built by native/wto-net/build.ps1, and its settings wto_ws.cfg). The stock folder is only read.
|
|
* --data is the folder the local server will run with: the store packs it sells there (its tuning
|
|
* 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 <out>/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 set (exe, GUI and native definitions) and the hook library default to this
|
|
* repository's patches/ and build/native. The launcher runs the same build at every launch, with the port the player chose.
|
|
*/
|
|
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,
|
|
NETWORK_HOOK_LIBRARY,
|
|
playerDecalCacheProblem,
|
|
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 <stock game folder> --out <game copy folder> --port <n> --data <local server data folder> '
|
|
+ '[--patches <patch set>] [--native <folder with wto_ws.dll>] [--decal-cache <folder>] '
|
|
+ '[--skip-unavailable] [--verbose]';
|
|
|
|
function main(): number {
|
|
const { values } = parseArgs({
|
|
options: {
|
|
game: { type: 'string' },
|
|
out: { type: 'string' },
|
|
port: { type: 'string' },
|
|
data: { type: 'string' },
|
|
patches: { type: 'string', default: join(REPOSITORY, 'patches') },
|
|
native: { type: 'string', default: join(REPOSITORY, 'build', 'native') },
|
|
'decal-cache': { type: 'string' },
|
|
'skip-unavailable': { type: 'boolean', default: false },
|
|
verbose: { type: 'boolean', default: false },
|
|
},
|
|
});
|
|
if (!values.game || !values.out || !values.port || !values.data) {
|
|
console.error(USAGE);
|
|
return 2;
|
|
}
|
|
assertWritableCopy(values.game, values.out);
|
|
const decalCache = values['decal-cache'];
|
|
const decalCacheProblem = decalCache === undefined ? undefined : playerDecalCacheProblem(decalCache);
|
|
if (decalCacheProblem) {
|
|
console.error(`--decal-cache: ${decalCacheProblem}; nothing was written`);
|
|
return 1;
|
|
}
|
|
const hookLibraryPath = join(values.native, NETWORK_HOOK_LIBRARY);
|
|
if (!existsSync(hookLibraryPath)) {
|
|
console.error(`${hookLibraryPath} not found (build it with native/wto-net/build.ps1); nothing was written`);
|
|
return 1;
|
|
}
|
|
|
|
const build = buildGameCopy({
|
|
stock: readStockGameFiles(values.game),
|
|
port: Number(values.port),
|
|
patches: values.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, ...build.nativeModules.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;
|
|
}
|
|
|
|
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(', ')})`);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
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);
|
|
console.log(`wto_ws.cfg: ${build.nativeModules.available.length} native module(s) ready, ${build.nativeModules.failures.length} unavailable`);
|
|
if (verbose) for (const module of build.nativeModules.available) console.log(` ready ${module}`);
|
|
reportFailures(build.nativeModules.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();
|