feat(accounts): implement local login

Route login and character requests by their original host names on one
loopback port. Add local accounts, saves, and credential redaction.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 05:01:26 +08:00
1 parent c3914ec0d6
commit 7f482ae530
55 files changed
+1559 -58

No files matched your search

+4 -23
View File
@@ -1,13 +1,7 @@
/**
* Rebuild char.vromfs.bin with config/network.blk pointed at the local service. Every other
* file of the pack is kept byte for byte. The rewritten network.blk is stored self-contained
* (it no longer depends on the pack's shared name map), which the game accepts in every
* loading mode.
*/
import { decodeBlk, encodeBlk, parseSharedNameMap } from '@wto/blk';
import { getFile, NAME_MAP_PATH, putFile, readArchive, writeArchive, type Archive } from '@wto/vromfs';
/** Rebuild char.vromfs.bin with config/network.blk pointed at the local service. */
import type { LocalEndpoint } from './network/local-endpoint.ts';
import { redirectNetworkConfig, type NetworkRedirectReport } from './network/redirect-network-config.ts';
import { editPackBlk } from './pack-edit.ts';
export const NETWORK_CONFIG_PATH = 'config/network.blk';
@@ -17,19 +11,6 @@ export interface CharPackResult {
}
export function rebuildCharPack(stockPack: Uint8Array, endpoint: LocalEndpoint): CharPackResult {
const archive = readArchive(stockPack);
const dictionary = findDictionary(archive);
const shared = parseSharedNameMap(getFile(archive, NAME_MAP_PATH), dictionary);
const networkConfig = decodeBlk(getFile(archive, NETWORK_CONFIG_PATH), { names: shared.names, dictionary });
const network = redirectNetworkConfig(networkConfig, endpoint);
putFile(archive, NETWORK_CONFIG_PATH, encodeBlk(networkConfig));
return { pack: writeArchive(archive), network };
}
/** The pack's zstd dictionary, if it has one (char.vromfs.bin in 2.61.0.37 has none). */
function findDictionary(archive: Archive): Uint8Array | undefined {
const dictionaries = [...archive.files.keys()].filter((path) => path.endsWith('.dict'));
if (dictionaries.length > 1) throw new Error(`the data pack has several zstd dictionaries: ${dictionaries.join(', ')}`);
return dictionaries.length ? archive.files.get(dictionaries[0]!) : undefined;
const { pack, report } = editPackBlk(stockPack, NETWORK_CONFIG_PATH, (root) => redirectNetworkConfig(root, endpoint));
return { pack, network: report };
}
+8 -1
View File
@@ -5,7 +5,8 @@
* 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.
* Writes <out>/char.vromfs.bin, <out>/aces.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';
@@ -14,6 +15,7 @@ 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 { rebuildMainPack } from './main-pack.ts';
import { localEndpoint } from './network/local-endpoint.ts';
function main(): number {
@@ -47,7 +49,12 @@ function main(): number {
for (const change of charPack.network.addresses) console.log(` ${change.path}: ${change.before} -> ${change.after}`);
}
const mainPack = rebuildMainPack(readFileSync(join(values.game, GAME_FILES.mainPack)), endpoint);
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}`);
writeOutput(values.out, GAME_FILES.charPack, charPack.pack);
writeOutput(values.out, GAME_FILES.mainPack, mainPack.pack);
writeOutput(values.out, GAME_FILES.executable, executable.executable);
return 0;
}
+1
View File
@@ -8,6 +8,7 @@ import { join, resolve, sep } from 'node:path';
export const GAME_FILES = {
charPack: 'char.vromfs.bin',
mainPack: 'aces.vromfs.bin',
executable: join('win64', 'aces.exe'),
} as const;
+3 -1
View File
@@ -6,5 +6,7 @@
export { NETWORK_CONFIG_PATH, rebuildCharPack, type CharPackResult } from './char-pack.ts';
export { patchExecutable, type ExecutableResult } from './executable.ts';
export { assertWritableCopy, GAME_FILES } from './game-copy.ts';
export { ENGINE_SETTINGS_PATH, rebuildMainPack, type MainPackResult } from './main-pack.ts';
export { redirectAddresses, type AddressChange } from './network/address-rewrite.ts';
export { hostPort, localEndpoint, localUrl, type LocalEndpoint } from './network/local-endpoint.ts';
export { redirectNetworkConfig, type AddressChange, type NetworkRedirectReport } from './network/redirect-network-config.ts';
export { redirectNetworkConfig, type NetworkRedirectReport } from './network/redirect-network-config.ts';
+35
View File
@@ -0,0 +1,35 @@
/**
* Rebuild aces.vromfs.bin with the engine settings' server addresses pointed at the local
* service.
*
* config/settings.blk, block `network`: publicConfigsUrl and publicConfigsUrls are where the
* engine's public-configs module downloads files at startup, including a signed network.blk
* that would replace the one in char.vromfs.bin (DagorEngine prog/gameLibs/publicConfigs/
* publicConfigs.cpp, init). On a machine with internet access the download would succeed and
* point the game back at Gaijin's servers. Redirected, the request reaches the local service;
* it has no such file, so the game keeps the network.blk of char.vromfs.bin.
*
* Only the `network` block is touched: the rest of settings.blk is engine configuration, not
* server addresses.
*/
import { findBlock } from '@wto/blk';
import { redirectAddresses, type AddressChange } from './network/address-rewrite.ts';
import type { LocalEndpoint } from './network/local-endpoint.ts';
import { editPackBlk } from './pack-edit.ts';
export const ENGINE_SETTINGS_PATH = 'config/settings.blk';
const NETWORK_BLOCK = 'network';
export interface MainPackResult {
readonly pack: Uint8Array;
readonly addresses: readonly AddressChange[];
}
export function rebuildMainPack(stockPack: Uint8Array, endpoint: LocalEndpoint): MainPackResult {
const { pack, report } = editPackBlk(stockPack, ENGINE_SETTINGS_PATH, (root) => {
const network = findBlock(root, NETWORK_BLOCK);
if (!network) throw new Error(`${ENGINE_SETTINGS_PATH} has no "${NETWORK_BLOCK}" block; this game build differs from the verified ones`);
return redirectAddresses(network, endpoint, [NETWORK_BLOCK]);
});
return { pack, addresses: report };
}
@@ -10,8 +10,28 @@
* Everything else (file patterns, placeholders such as "https://not.used", DNS server IPs)
* is left as it is.
*/
import { visitParams, type BlkBlock } from '@wto/blk';
import { hostPort, localUrl, LOOPBACK, type LocalEndpoint } from './local-endpoint.ts';
export interface AddressChange {
readonly path: string;
readonly before: string;
readonly after: string;
}
/** Rewrite every server address among the string parameters of `root`, in place. */
export function redirectAddresses(root: BlkBlock, endpoint: LocalEndpoint, pathPrefix: readonly string[] = []): AddressChange[] {
const changes: AddressChange[] = [];
visitParams(root, (param, path) => {
if (param.value.type !== 'string') return;
const rewritten = rewriteAddress(param.value.value, endpoint);
if (rewritten === null || rewritten === param.value.value) return;
changes.push({ path: [...pathPrefix, ...path, param.name].join('/'), before: param.value.value, after: rewritten });
param.value = { type: 'string', value: rewritten };
});
return changes;
}
/** gaijin.ops is Gaijin's internal domain, used by the internal test environments. */
const GAIJIN_DOMAINS = ['gaijin.net', 'gaijinent.com', 'warthunder.com', 'gaijin.ops'];
const URL_PATTERN = /^(https?|wss?):\/\/([^/:?#]+)(?::\d+)?([/?#].*)?$/i;
@@ -7,10 +7,12 @@
* certain (https://auth.gaijinent.com/login.php); the others are matched by name to the
* addresses in the executable's string table.
*
* The host keys replace the host of every other login-related address, so those requests
* stay on this machine as well.
* The host keys replace only the host name of every login-related address and keep the
* address's port (yuplay2 YuSession::updateApiHost sets the host part). They therefore get
* the bare loopback address: "127.0.0.1:<port>" would turn the local login URL into
* http://127.0.0.1:<port>:<port>/..., which the game rejects as malformed.
*/
import { hostPort, localUrl, LOOPBACK, type LocalEndpoint } from './local-endpoint.ts';
import { localUrl, LOOPBACK, type LocalEndpoint } from './local-endpoint.ts';
const URL_DEFAULTS: ReadonlyArray<readonly [key: string, host: string, path: string]> = [
['loginURL', 'auth.gaijinent.com', '/login.php'],
@@ -26,7 +28,7 @@ const HOST_KEYS = ['authHost', 'ssoHost', 'storeApiHost', 'authFallbackHost'];
export function loginOverrides(endpoint: LocalEndpoint): ReadonlyArray<readonly [key: string, value: string]> {
return [
...URL_DEFAULTS.map(([key, host, path]) => [key, localUrl(endpoint, host, path)] as const),
...HOST_KEYS.map((key) => [key, hostPort(endpoint)] as const),
...HOST_KEYS.map((key) => [key, LOOPBACK] as const),
['fallbackIP', LOOPBACK],
];
}
@@ -8,41 +8,23 @@
* - every environment block (a block with `charServer` entries) gets certificate checking
* turned off and its login component settings pointed at the local service.
*/
import { ensureBlock, findParam, setParam, visitParams, type BlkBlock } from '@wto/blk';
import { rewriteAddress } from './address-rewrite.ts';
import { ensureBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
import { redirectAddresses, type AddressChange } from './address-rewrite.ts';
import type { LocalEndpoint } from './local-endpoint.ts';
import { loginOverrides } from './login-overrides.ts';
export interface AddressChange {
readonly path: string;
readonly before: string;
readonly after: string;
}
export interface NetworkRedirectReport {
readonly environments: readonly string[];
readonly addresses: readonly AddressChange[];
}
export function redirectNetworkConfig(root: BlkBlock, endpoint: LocalEndpoint): NetworkRedirectReport {
const addresses = rewriteAllAddresses(root, endpoint);
const addresses = redirectAddresses(root, endpoint);
const environments = root.blocks.filter((block) => findParam(block, 'charServer'));
for (const environment of environments) configureEnvironment(environment, endpoint);
return { environments: environments.map((block) => block.name), addresses };
}
function rewriteAllAddresses(root: BlkBlock, endpoint: LocalEndpoint): AddressChange[] {
const changes: AddressChange[] = [];
visitParams(root, (param, path) => {
if (param.value.type !== 'string') return;
const rewritten = rewriteAddress(param.value.value, endpoint);
if (rewritten === null || rewritten === param.value.value) return;
changes.push({ path: [...path, param.name].join('/'), before: param.value.value, after: rewritten });
param.value = { type: 'string', value: rewritten };
});
return changes;
}
function configureEnvironment(environment: BlkBlock, endpoint: LocalEndpoint): void {
setParam(environment, 'enableSslCertCheck', { type: 'bool', value: false });
const login = ensureBlock(environment, 'yuplay');
+30
View File
@@ -0,0 +1,30 @@
/**
* Rebuild a data pack with one of its BLK documents edited. Every other file of the pack is
* kept byte for byte. The edited document is stored self-contained (it no longer depends on
* the pack's shared name map), which the game accepts in every loading mode
*.
*/
import { decodeBlk, encodeBlk, parseSharedNameMap, type BlkBlock } from '@wto/blk';
import { getFile, NAME_MAP_PATH, putFile, readArchive, writeArchive, type Archive } from '@wto/vromfs';
export interface PackEditResult<T> {
readonly pack: Uint8Array;
readonly report: T;
}
export function editPackBlk<T>(stockPack: Uint8Array, blkPath: string, edit: (root: BlkBlock) => T): PackEditResult<T> {
const archive = readArchive(stockPack);
const dictionary = findDictionary(archive);
const names = archive.files.has(NAME_MAP_PATH) ? parseSharedNameMap(getFile(archive, NAME_MAP_PATH), dictionary).names : [];
const root = decodeBlk(getFile(archive, blkPath), { names, dictionary });
const report = edit(root);
putFile(archive, blkPath, encodeBlk(root));
return { pack: writeArchive(archive), report };
}
/** The pack's zstd dictionary, if it has one. */
function findDictionary(archive: Archive): Uint8Array | undefined {
const dictionaries = [...archive.files.keys()].filter((path) => path.endsWith('.dict'));
if (dictionaries.length > 1) throw new Error(`the data pack has several zstd dictionaries: ${dictionaries.join(', ')}`);
return dictionaries.length ? archive.files.get(dictionaries[0]!) : undefined;
}