feat(patcher): build a loopback client copy with TypeScript
Add the shared BLK, VROMFS, executable patch, and build packages. Preserve typed fields and shared name tables when reading BLK data. Rewrite the service endpoints in place so the original environment names remain available to the client, then build the client copy.
This commit is contained in:
1 parent
89aa5198c3
commit
c3914ec0d6
44 files changed
+1986
-1
No files matched your search
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 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] [--verbose]
|
||||
*
|
||||
* Writes <out>/char.vromfs.bin and <out>/win64/aces.exe. The stock folder is only read.
|
||||
* The launcher will run the same steps at every launch, with the port the player chose.
|
||||
*/
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { parseArgs } from 'node:util';
|
||||
import { rebuildCharPack } from './char-pack.ts';
|
||||
import { patchExecutable } from './executable.ts';
|
||||
import { assertWritableCopy, GAME_FILES } from './game-copy.ts';
|
||||
import { localEndpoint } from './network/local-endpoint.ts';
|
||||
|
||||
function main(): number {
|
||||
const { values } = parseArgs({
|
||||
options: {
|
||||
game: { type: 'string' },
|
||||
out: { type: 'string' },
|
||||
port: { type: 'string' },
|
||||
patches: { type: 'string', default: 'exe-patches' },
|
||||
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] [--verbose]');
|
||||
return 2;
|
||||
}
|
||||
assertWritableCopy(values.game, values.out);
|
||||
const endpoint = localEndpoint(Number(values.port));
|
||||
|
||||
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 charPack = rebuildCharPack(readFileSync(join(values.game, GAME_FILES.charPack)), 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}`);
|
||||
}
|
||||
|
||||
writeOutput(values.out, GAME_FILES.charPack, charPack.pack);
|
||||
writeOutput(values.out, GAME_FILES.executable, executable.executable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
function writeOutput(folder: string, relativePath: string, content: Uint8Array): void {
|
||||
const path = join(folder, relativePath);
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
writeFileSync(path, content);
|
||||
console.log(`wrote ${path}`);
|
||||
}
|
||||
|
||||
process.exitCode = main();
|
||||
Reference in new issue
Block a user