feat(native): route client traffic to the loopback service

Build the socket library and client-local port configuration for redirecting
traffic to the offline service. Accept HTTPS and the existing matching and
HTTP protocols on the same port. Route requests by the original host.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 05:02:34 +08:00
1 parent ddfc067874
commit 2428b34497
35 files changed
+3897 -23

No files matched your search

+17 -5
View File
@@ -3,13 +3,14 @@
* 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]
* [--patches exe-patches] [--native build/native] [--verbose]
*
* Writes <out>/char.vromfs.bin, <out>/aces.vromfs.bin and <out>/win64/aces.exe. The stock
* folder is only read.
* Writes <out>/char.vromfs.bin, <out>/aces.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 { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { parseArgs } from 'node:util';
import { rebuildCharPack } from './char-pack.ts';
@@ -17,6 +18,7 @@ import { patchExecutable } from './executable.ts';
import { assertWritableCopy, GAME_FILES } from './game-copy.ts';
import { rebuildMainPack } from './main-pack.ts';
import { localEndpoint } from './network/local-endpoint.ts';
import { NETWORK_HOOK_LIBRARY, networkHookSettings } from './network/network-hook.ts';
function main(): number {
const { values } = parseArgs({
@@ -25,15 +27,21 @@ function main(): number {
out: { type: 'string' },
port: { type: 'string' },
patches: { type: 'string', default: 'exe-patches' },
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] [--verbose]');
console.error('usage: cli.ts --game <stock game folder> --out <game copy folder> --port <n> [--patches exe-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);
@@ -58,6 +66,10 @@ function main(): number {
writeOutput(values.out, GAME_FILES.charPack, charPack.pack);
writeOutput(values.out, GAME_FILES.mainPack, mainPack.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;
}
@@ -0,0 +1,14 @@
/**
* The network hook library in the game copy: the exe patch
* online/network-hook-library makes aces.exe load win64/wto_ws.dll, which reads the local
* service port from win64/wto_ws.cfg. Both files are written next to the executable; the DLL is
* built from native/wto-net (build.ps1).
*/
import type { LocalEndpoint } from './local-endpoint.ts';
export const NETWORK_HOOK_LIBRARY = 'wto_ws.dll';
const SETTINGS = 'wto_ws.cfg';
export function networkHookSettings(endpoint: LocalEndpoint): { name: string; content: Uint8Array } {
return { name: SETTINGS, content: new TextEncoder().encode(`port=${endpoint.port}\n`) };
}