Register bundle GUIDs at build time and return local store item URLs. Route marketplace item links to the requested coupon. Update vehicle and cosmetic prices from the marketplace snapshot and support selling coupons back to the system at the configured fee. Type checking, an isolated build, and local service checks passed. In-game acceptance is pending.
102 lines
5.4 KiB
TypeScript
102 lines
5.4 KiB
TypeScript
/**
|
|
* Development entry point of the build: read the stock files of a game folder, write the
|
|
* files of the game copy.
|
|
*
|
|
* node packages/build/src/cli.ts --game <stock game folder> --out <game copy folder> --port <n>
|
|
* [--patches exe-patches] [--gui-patches gui-patches]
|
|
* [--native build/native] [--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.
|
|
* The launcher will run the same steps 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 { parseArgs } from 'node:util';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { rebuildCharPack } from './char-pack.ts';
|
|
import { patchExecutable } from './executable.ts';
|
|
import { assertWritableCopy, GAME_FILES } from './game-copy.ts';
|
|
import { rebuildGuiPack } from './gui-pack.ts';
|
|
import { rebuildMainPack } from './main-pack.ts';
|
|
import { localEndpoint } from './network/local-endpoint.ts';
|
|
import { NETWORK_HOOK_LIBRARY, networkHookSettings } from './network/network-hook.ts';
|
|
import { offlinePackBundleGuids } from './store/offline-bundles.ts';
|
|
|
|
/** The local service's default store tuning; its multi-vehicle pack ids get bundle GUIDs too. */
|
|
const STORE_TUNING_PATH = fileURLToPath(new URL('../../local-service/tuning/store.jsonc', import.meta.url));
|
|
|
|
function main(): number {
|
|
const { values } = parseArgs({
|
|
options: {
|
|
game: { type: 'string' },
|
|
out: { type: 'string' },
|
|
port: { type: 'string' },
|
|
patches: { type: 'string', default: 'exe-patches' },
|
|
'gui-patches': { type: 'string' },
|
|
native: { type: 'string', default: join('build', 'native') },
|
|
verbose: { type: 'boolean', default: false },
|
|
},
|
|
});
|
|
if (!values.game || !values.out || !values.port) {
|
|
console.error('usage: cli.ts --game <stock game folder> --out <game copy folder> --port <n> [--patches exe-patches] [--gui-patches gui-patches] [--native build/native] [--verbose]');
|
|
return 2;
|
|
}
|
|
assertWritableCopy(values.game, values.out);
|
|
const endpoint = localEndpoint(Number(values.port));
|
|
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 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');
|
|
return 1;
|
|
}
|
|
|
|
const stockCharPack = readFileSync(join(values.game, GAME_FILES.charPack));
|
|
const charPack = rebuildCharPack(stockCharPack, endpoint);
|
|
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`);
|
|
|
|
const packBundles = offlinePackBundleGuids(stockCharPack, STORE_TUNING_PATH);
|
|
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);
|
|
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}`);
|
|
}
|
|
|
|
process.exitCode = main();
|