From 58241a513f78689058b3e4dc634024d630b8fcba Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:08:29 +0800 Subject: [PATCH] Require explicit accounts and register GUI script edits 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. --- .../patch.json | 32 +++++++ packages/build/src/cli.ts | 20 ++-- packages/build/src/gui-pack.ts | 96 ++++++++++++++----- packages/build/src/index.ts | 4 +- .../src/accounts/account-store.ts | 12 --- .../src/char/actions/action-table.ts | 1 - .../src/char/actions/store-actions.ts | 7 +- .../src/inventory/inventory-service.ts | 11 +-- .../src/inventory/marketplace-service.ts | 6 +- .../local-service/src/store/store-service.ts | 4 +- 10 files changed, 131 insertions(+), 62 deletions(-) create mode 100644 gui-patches/online-shop/bypass-external-sso-for-local-urls/patch.json diff --git a/gui-patches/online-shop/bypass-external-sso-for-local-urls/patch.json b/gui-patches/online-shop/bypass-external-sso-for-local-urls/patch.json new file mode 100644 index 0000000..274a2b3 --- /dev/null +++ b/gui-patches/online-shop/bypass-external-sso-for-local-urls/patch.json @@ -0,0 +1,32 @@ +{ + "id": "online-shop/bypass-external-sso-for-local-urls", + "title": "本地服务地址打开网页时跳过 Gaijin 外网单点登录跳转", + "file": "scripts/onlineshop/url.nut", + + "program_behaviour": { + "stock": "打开带 auto_login 标签的链接(如 inventoryClient.nut 的 getMarketplaceBaseUrl())时,scripts/onlineshop/url.nut 调用原生 SsoLoggedUrlAction(yu_sessionProc.cpp:951),把目标地址包装进写死的 https://login.gaijin.net/sso/LoginByStoken 链接后交给系统默认浏览器。", + "patched": "当目标链接指向本次启动的本地服务地址(://:)时,shouldLogin 取 false,让系统默认浏览器直接打开本地网页(/store、/trade.gaijin.net 等)。" + }, + + "derivation": { + "requirement": "功能清单 G「礼包商店」「市场」与 A「不连 Gaijin」。玩家在游戏内点击「在交易所中查找」或顶栏「交易所」时,必须在默认浏览器直接打开本地交易所页面,且浏览器不访问 login.gaijin.net。", + "cause": "yu_sessionProc.cpp:951 的 SsoLoggedUrlAction 硬编码拼接 https://login.gaijin.net/sso/LoginByStoken(YuSession::setOptionStringSync 无覆盖该域名的选项),再调用 shell_launch() 启动外部浏览器;外部浏览器进程不加载游戏的 wto_ws.dll,会直接连向真实 Gaijin 登录服务器。", + "lighter_options_ruled_out": [ + "在 network.blk 去掉 marketplaceURL 的 auto_login:auto_login 不在 network.blk 配置值里,而是由 scripts/inventory/inventoryClient.nut 的 getMarketplaceBaseUrl() 在脚本里前置拼接。", + "让本地登录服务的 get_short_token 返回错误以触发回退分支:url.nut 为配合 SSO 参数对 notAuthUrl 做了 Base64 编码,SsoLoggedUrlAction 失败回调会把这段 Base64 字符串原样传给 shell_launch(),Windows 无法作为 URL 打开。" + ], + "conclusion": "在 gui.vromfs.bin 的 scripts/onlineshop/url.nut 单点为 shouldLogin 增加本地服务地址排除条件(仅对包含 ://<本地地址>:<端口> 的链接跳过 auto_login)。", + "if_not_applied": "在机库点击交易所或市场载具「在交易所中查找」时,系统浏览器会跳转到真实 https://login.gaijin.net/sso/LoginByStoken,无法打开本地交易所且产生外网请求。" + }, + + "features": ["A-不连 Gaijin", "G-礼包商店", "G-市场"], + "evidence": [ + "2.61.0.37 gui.vromfs.bin:scripts/onlineshop/url.nut(let shouldLogin = isInArray(URL_TAG_AUTO_LOGIN, urlTags))、scripts/inventory/inventoryClient.nut(getMarketplaceBaseUrl 前置 auto_login)。", + "DagorEngine 公开源码:prog/gameLibs/yuplay2/yu_sessionProc.cpp 第 951 行 SsoLoggedUrlAction。" + ], + + "edit": { + "find": " let shouldLogin = isInArray(URL_TAG_AUTO_LOGIN, urlTags)", + "replace": " let shouldLogin = isInArray(URL_TAG_AUTO_LOGIN, urlTags) && url.indexof(\"://{{LOCAL_ENDPOINT}}\") == null" + } +} diff --git a/packages/build/src/cli.ts b/packages/build/src/cli.ts index 30011b1..1887848 100644 --- a/packages/build/src/cli.ts +++ b/packages/build/src/cli.ts @@ -3,11 +3,12 @@ * files of the game copy. * * node packages/build/src/cli.ts --game --out --port - * [--patches exe-patches] [--native build/native] [--verbose] + * [--patches exe-patches] [--gui-patches gui-patches] + * [--native build/native] [--verbose] * - * Writes /char.vromfs.bin, /aces.vromfs.bin, /win64/aces.exe and the network - * hook library the patched executable loads (/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 /char.vromfs.bin, /aces.vromfs.bin, /gui.vromfs.bin, /win64/aces.exe + * and the network hook library the patched executable loads (/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 --out --port [--patches exe-patches] [--native build/native] [--verbose]'); + console.error('usage: cli.ts --game --out --port [--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}`); diff --git a/packages/build/src/gui-pack.ts b/packages/build/src/gui-pack.ts index e6ac1c6..1e0cf80 100644 --- a/packages/build/src/gui-pack.ts +++ b/packages/build/src/gui-pack.ts @@ -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; } diff --git a/packages/build/src/index.ts b/packages/build/src/index.ts index 3489513..77965e4 100644 --- a/packages/build/src/index.ts +++ b/packages/build/src/index.ts @@ -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'; diff --git a/packages/local-service/src/accounts/account-store.ts b/packages/local-service/src/accounts/account-store.ts index 47e6b5f..313f2d3 100644 --- a/packages/local-service/src/accounts/account-store.ts +++ b/packages/local-service/src/accounts/account-store.ts @@ -35,7 +35,6 @@ const NICK_MAX_LENGTH = 16; export class AccountStore { readonly #path: string; #file: AccountFile; - #lastSignedInUserId: string | undefined; constructor(dataFolder: string) { this.#path = join(dataFolder, 'accounts.json'); @@ -46,7 +45,6 @@ export class AccountStore { const existing = this.#find(login); if (existing) { if (!verifyPassword(password, existing.passwordHash)) return { kind: 'wrong-password' }; - this.#lastSignedInUserId = existing.userId; return { kind: 'signed-in', account: existing, registered: false }; } @@ -54,7 +52,6 @@ export class AccountStore { const account: Account = { login, userId, nick: nickFromLogin(login, userId), passwordHash: hashPassword(password), created: new Date().toISOString() }; this.#file = { ...this.#file, nextUserId: this.#file.nextUserId + 1, accounts: [...this.#file.accounts, account] }; writeFileAtomic(this.#path, JSON.stringify(this.#file, null, 2)); - this.#lastSignedInUserId = account.userId; return { kind: 'signed-in', account, registered: true }; } @@ -62,15 +59,6 @@ export class AccountStore { return this.#file.accounts; } - /** User id of the account that signed in most recently, or the newest account when none signed in yet. */ - activeAccount(): Account | undefined { - if (this.#lastSignedInUserId !== undefined) { - const active = this.byUserId(this.#lastSignedInUserId); - if (active) return active; - } - return this.#file.accounts[this.#file.accounts.length - 1]; - } - byUserId(userId: string): Account | undefined { return this.#file.accounts.find((account) => account.userId === userId); } diff --git a/packages/local-service/src/char/actions/action-table.ts b/packages/local-service/src/char/actions/action-table.ts index 4ff8e8a..7d95e68 100644 --- a/packages/local-service/src/char/actions/action-table.ts +++ b/packages/local-service/src/char/actions/action-table.ts @@ -104,7 +104,6 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap 0x2a1240 sends `entitlement` and `costGold` - * in the HTTP headers, job type 5, answer applied as a full profile update). + * - cln_buy_entitlement: Golden-Eagle entitlement purchase (aces.exe 0x17a0f50 -> 0x2a1240 + * sends `entitlement` and `costGold` in the HTTP headers, job type 5, answer applied as a + * full profile update). Note: `cln_buy_entitlement_and_get_reward_for_day` is not referenced + * anywhere in 2.61.0.37 GUI scripts and is intentionally not registered. */ import type { AccountStore } from '../../accounts/account-store.ts'; import { clientProfile } from '../../profile/client-profile.ts'; diff --git a/packages/local-service/src/inventory/inventory-service.ts b/packages/local-service/src/inventory/inventory-service.ts index a4fea87..47354ee 100644 --- a/packages/local-service/src/inventory/inventory-service.ts +++ b/packages/local-service/src/inventory/inventory-service.ts @@ -124,17 +124,10 @@ export class InventoryService implements Service { #resolveAccount(request: ServiceRequest): Account | undefined { const uidHint = headerOf(request, 'uidhint'); - if (uidHint) { - const found = this.#accounts.byUserId(uidHint); - if (found) return found; - } + if (uidHint) return this.#accounts.byUserId(uidHint); const token = headerOf(request, 'token'); const tokenUid = token ? userIdFromToken(token) : undefined; - if (tokenUid) { - const found = this.#accounts.byUserId(tokenUid); - if (found) return found; - } - return this.#accounts.activeAccount(); + return tokenUid ? this.#accounts.byUserId(tokenUid) : undefined; } } diff --git a/packages/local-service/src/inventory/marketplace-service.ts b/packages/local-service/src/inventory/marketplace-service.ts index e29fe2d..1b8fda0 100644 --- a/packages/local-service/src/inventory/marketplace-service.ts +++ b/packages/local-service/src/inventory/marketplace-service.ts @@ -63,7 +63,7 @@ export class MarketplaceService implements Service { #state(request: ServiceRequest): ServiceResponse { const requestedId = request.query.get('userId') ?? ''; - const account = (requestedId ? this.#accounts.byUserId(requestedId) : undefined) ?? this.#accounts.activeAccount(); + const account = requestedId ? this.#accounts.byUserId(requestedId) : this.#accounts.all()[0]; const profile = account ? this.#profiles.profileOf(account.userId) : undefined; const balance = profile ? balanceOf(profile) : { silverLions: 0, goldenEagles: 0, gjn: 0 }; @@ -102,8 +102,8 @@ export class MarketplaceService implements Service { return jsonMessage(false, '请求格式无效', 'marketplace buy: bad json'); } - const account = (payload.userId ? this.#accounts.byUserId(payload.userId) : undefined) ?? this.#accounts.activeAccount(); - if (!account) return jsonMessage(false, '请先在游戏客户端登录一次账号', 'marketplace buy: no account'); + const account = payload.userId ? this.#accounts.byUserId(payload.userId) : undefined; + if (!account) return jsonMessage(false, '未找到指定账号,请先在游戏客户端登录并在页面右上角选择账号', 'marketplace buy: unknown account'); const itemdefId = Number(payload.itemdefId ?? 0); const quantity = Math.max(1, Math.min(20, Number(payload.quantity ?? 1))); diff --git a/packages/local-service/src/store/store-service.ts b/packages/local-service/src/store/store-service.ts index 9adec7b..ef73429 100644 --- a/packages/local-service/src/store/store-service.ts +++ b/packages/local-service/src/store/store-service.ts @@ -139,7 +139,7 @@ export class StoreService implements Service { #webState(request: ServiceRequest): ServiceResponse { const requestedId = request.query.get('userId') ?? ''; - const account = (requestedId ? this.#accounts.byUserId(requestedId) : undefined) ?? this.#accounts.activeAccount(); + const account = requestedId ? this.#accounts.byUserId(requestedId) : this.#accounts.all()[0]; const now = serverTimeNow(); const profile = account ? this.#profiles.profileOf(account.userId) : undefined; const balance = profile ? balanceOf(profile) : { silverLions: 0, goldenEagles: 0, gjn: 0 }; @@ -203,7 +203,7 @@ export class StoreService implements Service { #accountFromForm(form: URLSearchParams): Account | undefined { const userId = userIdFromToken(form.get('token') ?? undefined) ?? userIdFromJwt(form.get('jwt') ?? undefined); - return (userId ? this.#accounts.byUserId(userId) : undefined) ?? this.#accounts.activeAccount(); + return userId ? this.#accounts.byUserId(userId) : undefined; } }