Launch the game through the guarded lab

This commit is contained in:
N0VAN0M4LY committed 2026-11-29 15:02:39 +08:00
1 parent 462b49b5c4
commit 6c09525834
25 files changed
+920 -23

No files matched your search

@@ -0,0 +1,19 @@
import type { AppErrorCode } from '@shared/errors.ts';
export interface BuildRequest {
readonly kind: 'build';
readonly stockPath: string;
readonly copyPath: string;
readonly dataPath: string;
readonly port: number;
readonly patches: string;
readonly networkHookLibrary: string;
readonly acceptedUnavailable: readonly string[];
}
export type BuildCommand = BuildRequest | { readonly kind: 'write' };
export type BuildReply =
| { readonly kind: 'prepared'; readonly total: number }
| { readonly kind: 'progress'; readonly written: number; readonly total: number; readonly file: string }
| { readonly kind: 'written' }
| { readonly kind: 'failed'; readonly error: AppErrorCode };
@@ -0,0 +1,53 @@
import { readFileSync } from 'node:fs';
import type { MessageEvent } from 'electron';
import { assertWritableCopy, buildGameCopy, readStockGameFiles, writeGameCopy, type GameCopyFile } from '@wto/patcher';
import { multiVehiclePackIds } from '@wto/server';
import type { BuildCommand, BuildReply, BuildRequest } from './build-protocol.ts';
let prepared: { readonly copyPath: string; readonly files: readonly GameCopyFile[] } | null = null;
function send(reply: BuildReply): void {
process.parentPort.postMessage(reply);
}
function build(request: BuildRequest): void {
assertWritableCopy(request.stockPath, request.copyPath);
const result = buildGameCopy({
stock: readStockGameFiles(request.stockPath),
patches: request.patches,
networkHookLibrary: readFileSync(request.networkHookLibrary),
port: request.port,
multiVehiclePackIds: multiVehiclePackIds(request.dataPath, console.info),
placeholderDecals: true,
});
const unavailable = [...result.exePatches.failures, ...result.guiPatches.failures, ...result.nativeModules.failures];
const accepted = new Set(request.acceptedUnavailable);
if (result.blocking.length > 0 || unavailable.some((failure) => !accepted.has(failure.patchId))) {
console.error('[build] the copy has unaccepted or essential failures:', unavailable);
send({ kind: 'failed', error: 'launch_build_unavailable' });
return;
}
prepared = { copyPath: request.copyPath, files: result.files };
send({ kind: 'prepared', total: prepared.files.length });
}
process.parentPort.on('message', (event: MessageEvent) => {
const command = event.data as BuildCommand;
try {
if (command.kind === 'build') {
build(command);
return;
}
if (!prepared) throw new Error('No build is ready to write.');
const { copyPath, files } = prepared;
prepared = null;
for (const [index, file] of files.entries()) {
writeGameCopy(copyPath, [file]);
send({ kind: 'progress', written: index + 1, total: files.length, file: file.path });
}
send({ kind: 'written' });
} catch (error) {
console.error('[build] preparing the game copy failed:', error);
send({ kind: 'failed', error: 'launch_build_failed' });
}
});