fix(accounts): require explicit accounts for game and web requests

Reject game requests whose token or account hint cannot be resolved
and require a valid explicit user ID for web mutations. Remove the
entitlement action without a verified client call site.

Register the loopback store URL script edit and require a unique match
during pack construction. Type checking and patch loading passed.
In-game acceptance is pending.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 08:08:29 +08:00
1 parent 29b731d52d
commit 814ac9409e
10 files changed
+131 -62

No files matched your search

+12 -8
View File
@@ -3,11 +3,12 @@
* files of the game copy.
*
* node packages/build/src/cli.ts --game <stock game folder> --out <game copy folder> --port <n>
* [--patches exe-patches] [--native build/native] [--verbose]
* [--patches exe-patches] [--gui-patches gui-patches]
* [--native build/native] [--verbose]
*
* 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.
* 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';
@@ -28,12 +29,13 @@ function main(): number {
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] [--native build/native] [--verbose]');
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);
@@ -64,12 +66,12 @@ function main(): number {
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);
console.log('gui.vromfs.bin: local URLs bypass external SSO redirect');
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);
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));
@@ -81,6 +83,8 @@ function main(): number {
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}`);
+74 -22
View File
@@ -1,33 +1,85 @@
/**
* Rebuild gui.vromfs.bin so local loopback URLs open directly in the player's browser
* instead of routing through Gaijin's external SSO login endpoint.
* Rebuild gui.vromfs.bin by applying declarative script modification records from `gui-patches/`
*.
*
* Why a client pack edit is required:
* scripts/inventory/inventoryclient.nut getMarketplaceBaseUrl() prepends `auto_login` to
* marketplaceURL. In scripts/onlineshop/url.nut, `auto_login` invokes native SsoLoggedUrlAction
* (yu_sessionProc.cpp:951), which constructs a hardcoded `https://login.gaijin.net/sso/LoginByStoken`
* URL (no option override in YuSession::setOptionStringSync) and hands it to shell_launch().
* Because the external OS browser does not load wto_ws.dll, it connects to the real
* login.gaijin.net; and returning an error from getShortToken falls back to a base64-encoded
* notAuthUrl that shell_launch() cannot open. Skipping `auto_login` when the target URL is the
* local service endpoint lets every local web UI (/store, /trade.gaijin.net) open directly.
* Just like `exe-patches/`, every GUI script modification lives in its own folder under
* `gui-patches/` with a `patch.json` documenting the requirement, why the local service cannot
* handle it alone, lighter options ruled out, and the exact unique text to replace.
*/
import { readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { getFile, putFile, readArchive, writeArchive } from '@wto/vromfs';
import type { LocalEndpoint } from './network/local-endpoint.ts';
export const URL_SCRIPT_PATH = 'scripts/onlineshop/url.nut';
const DEFAULT_GUI_PATCHES_DIR = fileURLToPath(new URL('../../../gui-patches', import.meta.url));
const ENDPOINT_PLACEHOLDER = '{{LOCAL_ENDPOINT}}';
const STOCK_AUTO_LOGIN_LINE = ' let shouldLogin = isInArray(URL_TAG_AUTO_LOGIN, urlTags)';
export interface GuiScriptPatch {
readonly id: string;
readonly title: string;
readonly file: string;
readonly features: readonly string[];
readonly edit: {
readonly find: string;
readonly replace: string;
};
}
export function rebuildGuiPack(stockPack: Uint8Array, endpoint: LocalEndpoint): Uint8Array {
export interface GuiPackResult {
readonly pack: Uint8Array;
readonly applied: readonly GuiScriptPatch[];
}
export function loadGuiPatches(patchesFolder: string = DEFAULT_GUI_PATCHES_DIR): readonly GuiScriptPatch[] {
const files = collectPatchJsonPaths(patchesFolder).sort();
return files.map((filePath) => {
const raw = JSON.parse(readFileSync(filePath, 'utf8')) as GuiScriptPatch;
if (!raw.id || !raw.file || !raw.edit?.find || typeof raw.edit.replace !== 'string') {
throw new Error(`${filePath}: invalid GUI patch record`);
}
return raw;
});
}
export function rebuildGuiPack(
stockPack: Uint8Array,
endpoint: LocalEndpoint,
patchesFolder: string = DEFAULT_GUI_PATCHES_DIR,
): GuiPackResult {
const patches = loadGuiPatches(patchesFolder);
const archive = readArchive(stockPack);
const source = Buffer.from(getFile(archive, URL_SCRIPT_PATH)).toString('utf8');
if (!source.includes(STOCK_AUTO_LOGIN_LINE)) {
throw new Error(`${URL_SCRIPT_PATH} does not contain the expected auto_login check; this game build differs from the verified ones`);
const hostPortText = `${endpoint.host}:${endpoint.port}`;
for (const patch of patches) {
const current = Buffer.from(getFile(archive, patch.file)).toString('utf8');
const firstIndex = current.indexOf(patch.edit.find);
if (firstIndex === -1) {
throw new Error(`GUI patch ${patch.id}: target snippet not found in ${patch.file}; refusing to write`);
}
if (current.indexOf(patch.edit.find, firstIndex + patch.edit.find.length) !== -1) {
throw new Error(`GUI patch ${patch.id}: target snippet appears more than once in ${patch.file}; refusing to write`);
}
const replacement = patch.edit.replace.replaceAll(ENDPOINT_PLACEHOLDER, hostPortText);
const updated = current.slice(0, firstIndex) + replacement + current.slice(firstIndex + patch.edit.find.length);
putFile(archive, patch.file, Buffer.from(updated, 'utf8'));
}
return {
pack: writeArchive(archive),
applied: patches,
};
}
function collectPatchJsonPaths(dir: string): string[] {
const out: string[] = [];
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const full = join(dir, entry.name);
if (entry.isDirectory()) {
out.push(...collectPatchJsonPaths(full));
} else if (entry.isFile() && entry.name === 'patch.json') {
out.push(full);
}
}
const localPrefix = `://${endpoint.host}:${endpoint.port}`;
const replacement = `${STOCK_AUTO_LOGIN_LINE} && url.indexof("${localPrefix}") == null`;
const updated = source.replace(STOCK_AUTO_LOGIN_LINE, replacement);
putFile(archive, URL_SCRIPT_PATH, Buffer.from(updated, 'utf8'));
return writeArchive(archive);
return out;
}
+2 -2
View File
@@ -6,8 +6,8 @@
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 { URL_SCRIPT_PATH, rebuildGuiPack } from './gui-pack.ts';
export { ENGINE_SETTINGS_PATH, rebuildMainPack, type MainPackResult } from './main-pack.ts';
export { loadGuiPatches, rebuildGuiPack, type GuiPackResult, type GuiScriptPatch } from './gui-pack.ts';
export { ENGINE_SETTINGS_PATH, EXTRA_STORE_BUNDLE_GUIDS, 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 NetworkRedirectReport } from './network/redirect-network-config.ts';