From d043a8f0f8f186d9df49ce8984be575832f49817 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sun, 29 Nov 2026 18:00:21 +0800 Subject: [PATCH] feat(accounts)!: require explicit local account registration Open the local signup page in the game's embedded browser before sign-in. Return the existing login error for unknown accounts or invalid passwords. BREAKING CHANGE: First-time players must register in the game's signup window or create a save in the launcher before signing in. Existing accounts can sign in with their saved credentials. --- README.md | 8 +++-- .../src/renderer/src/i18n/locales/en.json | 1 + .../src/renderer/src/i18n/locales/zh-CN.json | 1 + apps/server/src/accounts/account-store.ts | 28 +++++----------- apps/server/src/login/login-service.ts | 7 ++-- apps/server/src/web-ui/web/register.js | 3 +- packages/patcher/src/build-game-copy.ts | 12 +++++-- packages/patcher/src/char-pack.ts | 3 +- .../src/network/redirect-network-config.ts | 9 ++++-- .../keep-local-page-embedded/find-close.nut | 1 + .../keep-local-page-embedded/find-crash.nut | 1 + .../find-external.nut | 1 + .../keep-local-page-embedded/find-frame.nut | 1 + .../keep-local-page-embedded/patch.jsonc | 32 +++++++++++++++++++ .../replace-close.nut | 3 ++ .../replace-crash.nut | 6 ++++ .../replace-external.nut | 3 ++ .../replace-frame.nut | 11 +++++++ .../open-local-page/find-external.nut | 1 + .../open-local-page/find-open.nut | 1 + .../registration/open-local-page/patch.jsonc | 24 ++++++++++++++ .../open-local-page/replace-external.nut | 6 ++++ .../open-local-page/replace-open.nut | 3 ++ 23 files changed, 134 insertions(+), 32 deletions(-) create mode 100644 patches/gui/registration/keep-local-page-embedded/find-close.nut create mode 100644 patches/gui/registration/keep-local-page-embedded/find-crash.nut create mode 100644 patches/gui/registration/keep-local-page-embedded/find-external.nut create mode 100644 patches/gui/registration/keep-local-page-embedded/find-frame.nut create mode 100644 patches/gui/registration/keep-local-page-embedded/patch.jsonc create mode 100644 patches/gui/registration/keep-local-page-embedded/replace-close.nut create mode 100644 patches/gui/registration/keep-local-page-embedded/replace-crash.nut create mode 100644 patches/gui/registration/keep-local-page-embedded/replace-external.nut create mode 100644 patches/gui/registration/keep-local-page-embedded/replace-frame.nut create mode 100644 patches/gui/registration/open-local-page/find-external.nut create mode 100644 patches/gui/registration/open-local-page/find-open.nut create mode 100644 patches/gui/registration/open-local-page/patch.jsonc create mode 100644 patches/gui/registration/open-local-page/replace-external.nut create mode 100644 patches/gui/registration/open-local-page/replace-open.nut diff --git a/README.md b/README.md index 501f608..2c84a19 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ AI 的驾驶、寻路和战术使用游戏自带的 AI,目前仍有明显不 - **服务地址**:`config/network.blk`(`char.vromfs.bin`)和 `config/settings.blk`(`aces.vromfs.bin`)中所有 Gaijin 地址改写为 `127.0.0.1:<端口>`。端口在构建时写入,因此服务器必须使用相同的端口。 - **配置表**:开启离线需要的功能开关,放出隐藏载具,写入贴花索引,为本地商店的礼包登记 GUID。 - **exe 补丁**:`patches/exe/` 下共 12 项,见下表。 -- **界面脚本补丁**:`patches/gui/` 下共 35 项,用于本地对局的开局与结算、本地商店的购买回执,以及库存签名公钥等。 +- **界面脚本补丁**:`patches/gui/` 下共 37 项,用于本地账号注册、本地对局的开局与结算、本地商店的购买回执,以及库存签名公钥等。 - **网络钩子库**:exe 的导入表把 `WS2_32.dll` 改为同长度的 `wto_ws.dll`。该库转发系统 `ws2_32.dll` 的全部导出,并用 MinHook 挂钩域名解析(`getaddrinfo` 等)、连接(`connect`、`ConnectEx` 等)和 UDP 发送,把所有外部连接重定向到本地服务器端口。端口从 exe 旁的 `wto_ws.cfg` 读取。 | exe 补丁 | 作用 | @@ -178,6 +178,8 @@ node scripts/build-game-copy.ts --game "<原版目录>" --out "<副本目录>" - node apps/server/src/cli.ts --game "<副本目录>" --data "<数据目录>" --port 27015 ``` +第一次登录前,在游戏登录界面点击「注册」,或在启动器的「存档」页创建本地账号。已有本地账号可以直接登录。 + `build-game-copy.ts` 的可选参数: | 参数 | 说明 | @@ -327,7 +329,7 @@ Static data such as vehicles, tech trees, prices, and reward factors is extracte - **Service addresses**: every Gaijin address in `config/network.blk` (`char.vromfs.bin`) and `config/settings.blk` (`aces.vromfs.bin`) is rewritten to `127.0.0.1:`. The port is written at build time, so the server must use the same port. - **Config tables**: enables feature flags the offline copy needs, reveals hidden vehicles, adds a decal index, and registers GUIDs for local store packs. - **exe patches**: 12 patches under `patches/exe/`, listed below. -- **UI script patches**: 35 patches under `patches/gui/`, covering local battle start and settlement, local store purchase receipts, and the inventory signing key, among others. +- **UI script patches**: 37 patches under `patches/gui/`, covering local account registration, battle start and settlement, store purchase receipts, and the inventory signing key. - **Network hook library**: the import table entry `WS2_32.dll` is renamed to `wto_ws.dll`, which has the same length. The library forwards every export of the system `ws2_32.dll` and uses MinHook to hook name resolution (`getaddrinfo` and others), connections (`connect`, `ConnectEx`, and others), and UDP sends, redirecting every external connection to the local server port. The port is read from `wto_ws.cfg` next to the exe. | exe patch | Purpose | @@ -431,6 +433,8 @@ node scripts/build-game-copy.ts --game "" --out "" -- node apps/server/src/cli.ts --game "" --data "" --port 27015 ``` +Before the first sign-in, select **Register** on the game login screen or create a local account on the launcher's **Saves** page. Existing local accounts can sign in directly. + Optional arguments for `build-game-copy.ts`: | Argument | Description | diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index 4aba473..097f71e 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -520,6 +520,7 @@ }, "features": { "A-Offline startup": "Offline startup", + "A-Local accounts": "Local accounts", "A-Isolation from the official game": "Isolation from the official game", "A-No Gaijin connections": "Gaijin connections blocked", "A-Tutorials": "Tutorial", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index c4b8121..c4a5792 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -520,6 +520,7 @@ }, "features": { "A-Offline startup": "离线启动", + "A-Local accounts": "本地账号", "A-Isolation from the official game": "与正版隔离", "A-No Gaijin connections": "阻断 Gaijin 连接", "A-Tutorials": "新手教程", diff --git a/apps/server/src/accounts/account-store.ts b/apps/server/src/accounts/account-store.ts index bda0b02..7c8f4ed 100644 --- a/apps/server/src/accounts/account-store.ts +++ b/apps/server/src/accounts/account-store.ts @@ -1,8 +1,8 @@ /** * Local accounts behind the login service. * - * Signing in with a login name that does not exist yet registers it with the password given; - * later sign-ins must use the same password. Accounts are kept in /accounts.json. + * Accounts are created through explicit registration. Sign-in verifies the credentials of + * an existing account. Accounts are kept in /accounts.json. */ import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; @@ -20,8 +20,8 @@ export interface Account { } export type SignInResult = - | { readonly kind: 'signed-in'; readonly account: Account; readonly registered: boolean } - | { readonly kind: 'wrong-password' }; + | { readonly kind: 'signed-in'; readonly account: Account } + | { readonly kind: 'unknown-login' | 'wrong-password' }; export type RegistrationResult = | { readonly kind: 'registered'; readonly account: Account } @@ -47,16 +47,11 @@ export class AccountStore { } signIn(login: string, password: string): SignInResult { - 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 }; - } - - const account = this.#create(login, password, nickFromLogin(login, String(this.#file.nextUserId))); + const account = this.#find(login); + if (!account) return { kind: 'unknown-login' }; + if (!verifyPassword(password, account.passwordHash)) return { kind: 'wrong-password' }; this.#lastSignedInUserId = account.userId; - return { kind: 'signed-in', account, registered: true }; + return { kind: 'signed-in', account }; } register(login: string, password: string, nick: string): RegistrationResult { @@ -138,10 +133,3 @@ function readAccountFile(path: string): AccountFile { if (file.formatVersion !== 1) throw new Error(`${path}: unsupported account file version ${String(file.formatVersion)}`); return file; } - -/** A login is often an e-mail address; the nick is its readable part. */ -function nickFromLogin(login: string, userId: string): string { - const local = login.split('@')[0] ?? ''; - const cleaned = local.replace(/[^A-Za-z0-9_\-]/g, '').slice(0, NICK_MAX_LENGTH); - return cleaned || `Player${userId}`; -} diff --git a/apps/server/src/login/login-service.ts b/apps/server/src/login/login-service.ts index f3c730b..4c3465f 100644 --- a/apps/server/src/login/login-service.ts +++ b/apps/server/src/login/login-service.ts @@ -50,7 +50,10 @@ export class LoginService implements Service { if (!login) return yuplayAnswer('LOGINERROR', {}, 'sign-in: empty login'); const result = this.#accounts.signIn(login, password); - if (result.kind === 'wrong-password') return yuplayAnswer('LOGINERROR', {}, `sign-in ${login}: wrong password`); + if (result.kind !== 'signed-in') { + const problem = result.kind === 'unknown-login' ? 'account not registered' : 'wrong password'; + return yuplayAnswer('LOGINERROR', {}, `sign-in ${login}: ${problem}`); + } const { account } = result; const credentials = issueCredentials(account); @@ -67,7 +70,7 @@ export class LoginService implements Service { nickorig: account.nick, nicksfx: '', meta: {}, - }, `sign-in ${login} -> user ${account.userId}${result.registered ? ' (new account)' : ''}`); + }, `sign-in ${login} -> user ${account.userId}`); } } diff --git a/apps/server/src/web-ui/web/register.js b/apps/server/src/web-ui/web/register.js index de79903..b0b6b7b 100644 --- a/apps/server/src/web-ui/web/register.js +++ b/apps/server/src/web-ui/web/register.js @@ -30,7 +30,8 @@ const zh = { failed: '无法注册本地账号。', }; -const chinese = navigator.language.toLowerCase().startsWith('zh'); +const language = new URLSearchParams(location.search).get('skin_lang') || navigator.language; +const chinese = language.toLowerCase().startsWith('zh'); const text = chinese ? zh : en; document.documentElement.lang = chinese ? 'zh-CN' : 'en'; document.title = text.title; diff --git a/packages/patcher/src/build-game-copy.ts b/packages/patcher/src/build-game-copy.ts index 6e5c5e4..20ddcce 100644 --- a/packages/patcher/src/build-game-copy.ts +++ b/packages/patcher/src/build-game-copy.ts @@ -84,10 +84,16 @@ export function buildGameCopy(inputs: GameCopyInputs): GameCopyBuild { const executable = patchExecutable(inputs.stock.executable, folders.exe); const stockImage = new PeImage(inputs.stock.executable); const native = resolveNativeModules(stockImage, loadNativeModules(folders.native)); - const { pack: charPack, ...charReport } = rebuildCharPack(inputs.stock.charPack, endpoint, { placeholderDecals: inputs.placeholderDecals }); + const guiPack = rebuildGuiPack(inputs.stock.guiPack, endpoint, folders.gui); + const appliedGuiPatches = guiPack.applied.map((item) => item.patch.id); + const localRegistration = appliedGuiPatches.includes('registration/open-local-page') && + appliedGuiPatches.includes('registration/keep-local-page-embedded'); + const { pack: charPack, ...charReport } = rebuildCharPack(inputs.stock.charPack, endpoint, { + placeholderDecals: inputs.placeholderDecals, + localRegistration, + }); const bundles = offlinePackBundleGuids(inputs.stock.charPack, inputs.multiVehiclePackIds); const mainPack = rebuildMainPack(inputs.stock.mainPack, endpoint, bundles); - const guiPack = rebuildGuiPack(inputs.stock.guiPack, endpoint, folders.gui); const executableFolder = dirname(GAME_FILES.executable); const hookSettings = networkHookSettings(endpoint, stockImage, native.values); @@ -105,7 +111,7 @@ export function buildGameCopy(inputs: GameCopyInputs): GameCopyBuild { files, endpoint, exePatches: { applied: executable.plan.writes.map((write) => ({ patchId: write.patchId, rva: write.rva })), failures: executable.plan.failures }, - guiPatches: { applied: guiPack.applied.map((item) => item.patch.id), failures: guiPack.failures }, + guiPatches: { applied: appliedGuiPatches, failures: guiPack.failures }, nativeModules: { available: [...native.available.keys()], failures: native.failures }, blocking: blockingFailures(failures), charPack: charReport, diff --git a/packages/patcher/src/char-pack.ts b/packages/patcher/src/char-pack.ts index 9a58277..85b4164 100644 --- a/packages/patcher/src/char-pack.ts +++ b/packages/patcher/src/char-pack.ts @@ -27,6 +27,7 @@ export interface CharPackResult { export interface CharPackOptions { /** Store the placeholder decal index (false when the player's own web cache is copied). */ readonly placeholderDecals: boolean; + readonly localRegistration: boolean; } export function rebuildCharPack(stockPack: Uint8Array, endpoint: LocalEndpoint, options: CharPackOptions): CharPackResult { @@ -35,7 +36,7 @@ export function rebuildCharPack(stockPack: Uint8Array, endpoint: LocalEndpoint, let revealedVehicles = 0; const decals = options.placeholderDecals ? offlineDecalIndex(readPackBlk(stockPack, DECALS_CONFIG_PATH)) : undefined; const pack = editPackBlks(stockPack, [ - { path: NETWORK_CONFIG_PATH, edit: (root) => { network = redirectNetworkConfig(root, endpoint); } }, + { path: NETWORK_CONFIG_PATH, edit: (root) => { network = redirectNetworkConfig(root, endpoint, options.localRegistration); } }, { path: GAME_SETTINGS_PATH, edit: (root) => { features = enableFeaturesForEveryone(root, OFFLINE_FEATURES); } }, { path: SHOP_PATH, edit: (root) => { revealedVehicles = revealHiddenVehicles(root); } }, ], decals?.files ?? []); diff --git a/packages/patcher/src/network/redirect-network-config.ts b/packages/patcher/src/network/redirect-network-config.ts index bf2e27a..b3168a5 100644 --- a/packages/patcher/src/network/redirect-network-config.ts +++ b/packages/patcher/src/network/redirect-network-config.ts @@ -18,19 +18,22 @@ export interface NetworkRedirectReport { readonly addresses: readonly AddressChange[]; } -export function redirectNetworkConfig(root: BlkBlock, endpoint: LocalEndpoint): NetworkRedirectReport { +export function redirectNetworkConfig(root: BlkBlock, endpoint: LocalEndpoint, localRegistration: boolean): NetworkRedirectReport { const addresses = redirectAddresses(root, endpoint); const environments = root.blocks.filter((block) => findParam(block, 'charServer')); - for (const environment of environments) configureEnvironment(environment, endpoint); + for (const environment of environments) configureEnvironment(environment, endpoint, localRegistration); return { environments: environments.map((block) => block.name), addresses }; } -function configureEnvironment(environment: BlkBlock, endpoint: LocalEndpoint): void { +function configureEnvironment(environment: BlkBlock, endpoint: LocalEndpoint, localRegistration: boolean): void { setParam(environment, 'enableSslCertCheck', { type: 'bool', value: false }); // The local store page. The stock value carries URL tags; here only // auto_local, so scripts/onlineShop/url.nut adds ?skin_lang= and opens it in // the built-in browser. No auto_login: that goes through Gaijin's login.gaijin.net. setParam(environment, 'webstoreURL', { type: 'string', value: `auto_local http://${endpoint.host}:${endpoint.port}/store` }); + if (localRegistration) { + setParam(environment, 'signUpURL', { type: 'string', value: `auto_local http://${endpoint.host}:${endpoint.port}/register` }); + } const login = ensureBlock(environment, 'yuplay'); for (const [key, value] of loginOverrides(endpoint)) setParam(login, key, { type: 'string', value }); } diff --git a/patches/gui/registration/keep-local-page-embedded/find-close.nut b/patches/gui/registration/keep-local-page-embedded/find-close.nut new file mode 100644 index 0000000..4492851 --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/find-close.nut @@ -0,0 +1 @@ + function browserCloseAndUpdateEntitlements() { diff --git a/patches/gui/registration/keep-local-page-embedded/find-crash.nut b/patches/gui/registration/keep-local-page-embedded/find-crash.nut new file mode 100644 index 0000000..3a65999 --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/find-crash.nut @@ -0,0 +1 @@ + else if (eventType == BROWSER_EVENT_BROWSER_CRASHED) { diff --git a/patches/gui/registration/keep-local-page-embedded/find-external.nut b/patches/gui/registration/keep-local-page-embedded/find-external.nut new file mode 100644 index 0000000..6d999dd --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/find-external.nut @@ -0,0 +1 @@ + function browserForceExternal() { diff --git a/patches/gui/registration/keep-local-page-embedded/find-frame.nut b/patches/gui/registration/keep-local-page-embedded/find-frame.nut new file mode 100644 index 0000000..a252523 --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/find-frame.nut @@ -0,0 +1 @@ + function initScreen() { diff --git a/patches/gui/registration/keep-local-page-embedded/patch.jsonc b/patches/gui/registration/keep-local-page-embedded/patch.jsonc new file mode 100644 index 0000000..41ab257 --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/patch.jsonc @@ -0,0 +1,32 @@ +// Close registration without refreshing account entitlements or retrying in the system browser. +{ + "id": "registration/keep-local-page-embedded", + "title": "Keep local registration inside the game window", + "features": [ + "A-Local accounts" + ], + "variants": [ + { + "written_for": "2.61.0.37", + "file": "scripts/onlineshop/browserwnd.nut", + "edits": [ + { + "find": "find-frame.nut", + "replace": "replace-frame.nut" + }, + { + "find": "find-close.nut", + "replace": "replace-close.nut" + }, + { + "find": "find-external.nut", + "replace": "replace-external.nut" + }, + { + "find": "find-crash.nut", + "replace": "replace-crash.nut" + } + ] + } + ] +} diff --git a/patches/gui/registration/keep-local-page-embedded/replace-close.nut b/patches/gui/registration/keep-local-page-embedded/replace-close.nut new file mode 100644 index 0000000..6e9c699 --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/replace-close.nut @@ -0,0 +1,3 @@ + function browserCloseAndUpdateEntitlements() { + if (this.isLocalRegistrationPage()) + return this.goBack() diff --git a/patches/gui/registration/keep-local-page-embedded/replace-crash.nut b/patches/gui/registration/keep-local-page-embedded/replace-crash.nut new file mode 100644 index 0000000..334764f --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/replace-crash.nut @@ -0,0 +1,6 @@ + else if (eventType == BROWSER_EVENT_BROWSER_CRASHED) { + if (this.isLocalRegistrationPage()) { + this.goBack() + showInfoMsgBox(loc("browser/error_load_url"), "error_load_url") + return + } diff --git a/patches/gui/registration/keep-local-page-embedded/replace-external.nut b/patches/gui/registration/keep-local-page-embedded/replace-external.nut new file mode 100644 index 0000000..9c73760 --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/replace-external.nut @@ -0,0 +1,3 @@ + function browserForceExternal() { + if (this.isLocalRegistrationPage()) + return diff --git a/patches/gui/registration/keep-local-page-embedded/replace-frame.nut b/patches/gui/registration/keep-local-page-embedded/replace-frame.nut new file mode 100644 index 0000000..56c32ec --- /dev/null +++ b/patches/gui/registration/keep-local-page-embedded/replace-frame.nut @@ -0,0 +1,11 @@ + function isLocalRegistrationPage() { + let registrationUrl = "http://{{LOCAL_ENDPOINT}}/register" + return this.url == registrationUrl || startsWith(this.url, registrationUrl + "?") + } + + function initScreen() { + if (this.isLocalRegistrationPage()) { + let externalButton = this.scene.findObject("btn_browser_force_external") + if (checkObj(externalButton)) + externalButton.show(false) + } diff --git a/patches/gui/registration/open-local-page/find-external.nut b/patches/gui/registration/open-local-page/find-external.nut new file mode 100644 index 0000000..42af47b --- /dev/null +++ b/patches/gui/registration/open-local-page/find-external.nut @@ -0,0 +1 @@ + defer(function() { diff --git a/patches/gui/registration/open-local-page/find-open.nut b/patches/gui/registration/open-local-page/find-open.nut new file mode 100644 index 0000000..e1d5183 --- /dev/null +++ b/patches/gui/registration/open-local-page/find-open.nut @@ -0,0 +1 @@ + if (!useExternalBrowser && use_embedded_browser() && !canUseSteamBrowser && hasFeat) { diff --git a/patches/gui/registration/open-local-page/patch.jsonc b/patches/gui/registration/open-local-page/patch.jsonc new file mode 100644 index 0000000..917489e --- /dev/null +++ b/patches/gui/registration/open-local-page/patch.jsonc @@ -0,0 +1,24 @@ +// Keep the local registration URL out of the system browser. +{ + "id": "registration/open-local-page", + "title": "Open local registration in the embedded browser", + "features": [ + "A-Local accounts" + ], + "variants": [ + { + "written_for": "2.61.0.37", + "file": "scripts/onlineshop/url.nut", + "edits": [ + { + "find": "find-open.nut", + "replace": "replace-open.nut" + }, + { + "find": "find-external.nut", + "replace": "replace-external.nut" + } + ] + } + ] +} diff --git a/patches/gui/registration/open-local-page/replace-external.nut b/patches/gui/registration/open-local-page/replace-external.nut new file mode 100644 index 0000000..5f8efc4 --- /dev/null +++ b/patches/gui/registration/open-local-page/replace-external.nut @@ -0,0 +1,6 @@ + if (localRegistration) { + showInfoMsgBox(loc("browser/error_load_url"), "error_load_url") + return + } + + defer(function() { diff --git a/patches/gui/registration/open-local-page/replace-open.nut b/patches/gui/registration/open-local-page/replace-open.nut new file mode 100644 index 0000000..7208945 --- /dev/null +++ b/patches/gui/registration/open-local-page/replace-open.nut @@ -0,0 +1,3 @@ + let localRegistration = urlWithoutTags == "http://{{LOCAL_ENDPOINT}}/register" + let useEmbeddedBrowser = localRegistration || (!useExternalBrowser && !canUseSteamBrowser && hasFeat) + if (useEmbeddedBrowser && use_embedded_browser()) {