Add GJN balances, the local store, and redemption codes

Support currency and entitlement purchases, including packs, from the
local store and the in-game payment flow. Expose the supported
redemption codes.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 06:33:41 +08:00
1 parent d95a5d8f0c
commit cfa6c04aa6
26 files changed
+1352 -29

No files matched your search

@@ -119,6 +119,14 @@ class TrackedSource implements DatasetSource {
return gamePack.readBlk(path);
}
readText(pack: GamePackName, path: string): string {
const gamePack = this.#gameFiles.pack(pack);
const sha1 = gamePack.fileDigest(path);
if (sha1 === undefined) throw new Error(`${pack} has no file ${path}`);
this.#files.set(`${pack}/${path}`, { pack, path, sha1 });
return gamePack.readText(path);
}
listFiles(pack: GamePackName): readonly string[] {
const paths = this.#gameFiles.pack(pack).paths();
this.#listings.set(pack, { pack, sha1: listingDigest(paths) });
@@ -11,6 +11,7 @@ import type { GamePackName } from '../game-files.ts';
export interface DatasetSource {
readBlk(pack: GamePackName, path: string): BlkBlock;
readText(pack: GamePackName, path: string): string;
/** Every file path in a pack, sorted. */
listFiles(pack: GamePackName): readonly string[];
}
@@ -0,0 +1,27 @@
/**
* Dataset: entitlement-to-GUID mappings from aces.vromfs.bin config/gui.blk bundles/guid
* (gui.vromfs.bin scripts/onlineShop/onlineBundles.nut, implementation notes).
*/
import { findBlock } from '@wto/blk';
import type { Dataset } from './dataset.ts';
const GUI_CONFIG = 'config/gui.blk';
/** Entitlement name -> store item GUID (upper-case UUID string). */
export type StoreBundleGuids = Readonly<Record<string, string>>;
export const storeBundles: Dataset<StoreBundleGuids> = {
id: 'store-bundles',
version: 1,
extract: (source) => {
const gui = source.readBlk('aces.vromfs.bin', GUI_CONFIG);
const guidBlock = findBlock(findBlock(gui, 'bundles') ?? { name: '', params: [], blocks: [] }, 'guid');
const result: Record<string, string> = {};
for (const param of guidBlock?.params ?? []) {
if (param.value.type === 'string' && param.value.value) {
result[param.name] = param.value.value;
}
}
return result;
},
};
@@ -0,0 +1,96 @@
/**
* Dataset: localized vehicle names from lang.vromfs.bin lang/units.csv.
*
* Used by the local web store and generated inventory coupon definitions so players see the
* game's own English and Chinese vehicle names without shipping game text with the service.
*/
import type { Dataset } from './dataset.ts';
const UNITS_CSV = 'lang/units.csv';
export interface LocalizedText {
readonly en: string;
readonly zh: string;
}
export type UnitNamesMap = Readonly<Record<string, LocalizedText>>;
export const unitNames: Dataset<UnitNamesMap> = {
id: 'unit-names',
version: 1,
extract: (source) => {
const csv = source.readText('lang.vromfs.bin', UNITS_CSV);
const lines = csv.split(/\r?\n/);
const header = parseCsvRow(lines[0] ?? '');
const enCol = Math.max(1, header.indexOf('<English>'));
const zhCol = header.indexOf('<Chinese>');
const hzhCol = header.indexOf('<HChinese>');
const shopNames = new Map<string, LocalizedText>();
const fullNames = new Map<string, LocalizedText>();
for (let i = 1; i < lines.length; i++) {
const line = lines[i]!;
if (!line.startsWith('"')) continue;
const firstSemi = line.indexOf(';');
if (firstSemi <= 2) continue;
const key = line.slice(1, firstSemi - 1);
const isShop = key.endsWith('_shop');
const isFull = !isShop && key.endsWith('_0');
if (!isShop && !isFull) continue;
const cols = parseCsvRow(line);
const en = cleanText(cols[enCol] ?? '');
if (!en) continue;
const zh = cleanText((hzhCol >= 0 ? cols[hzhCol] : '') || (zhCol >= 0 ? cols[zhCol] : '') || en);
const unitId = key.slice(0, isShop ? -5 : -2);
if (isShop) shopNames.set(unitId, { en, zh });
else fullNames.set(unitId, { en, zh });
}
const result: Record<string, LocalizedText> = {};
for (const [unitId, text] of fullNames) result[unitId] = text;
for (const [unitId, text] of shopNames) result[unitId] = text;
return result;
},
};
function parseCsvRow(line: string): string[] {
const fields: string[] = [];
let i = 0;
while (i < line.length) {
if (line[i] === '"') {
i++;
let value = '';
while (i < line.length) {
if (line[i] === '"') {
if (line[i + 1] === '"') {
value += '"';
i += 2;
} else {
i++;
break;
}
} else {
value += line[i]!;
i++;
}
}
fields.push(value);
if (line[i] === ';') i++;
} else {
const next = line.indexOf(';', i);
if (next < 0) {
fields.push(line.slice(i));
break;
}
fields.push(line.slice(i, next));
i = next + 1;
}
}
return fields;
}
function cleanText(raw: string): string {
// Strip zero-width word-break spaces Gaijin inserts into CJK localization strings.
return raw.replace(/\u200b/g, '').trim();
}
@@ -52,11 +52,13 @@ export interface CatalogueVehicle {
readonly parts: readonly string[];
/** shop.blk showOnlyWhenBought. */
readonly onlyShownWhenOwned: boolean;
/** shop.blk marketplaceItemdefId (vehicles traded as coupons on the market, implementation notes). */
readonly marketplaceItemdefId?: number;
}
export const vehicleCatalogue: Dataset<readonly CatalogueVehicle[]> = {
id: 'vehicle-catalogue',
version: 2,
version: 3,
extract: (source) => {
const shopEntries = new Map<string, BlkBlock>();
for (const country of source.readBlk('char.vromfs.bin', SHOP).blocks) {
@@ -70,6 +72,7 @@ function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined): C
const requires = stringField(vehicle, 'reqAir');
const researchType = stringField(vehicle, 'researchType');
const requiredUnlock = stringField(shopEntry, 'reqUnlock');
const marketplaceItemdefId = numberField(shopEntry, 'marketplaceItemdefId') ?? numberField(vehicle, 'marketplaceItemdefId');
return {
name: vehicle.name,
country: stringField(vehicle, 'country') ?? '',
@@ -87,6 +90,7 @@ function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined): C
...(requiredUnlock ? { requiredUnlock } : {}),
parts: shopEntry ? shopEntry.params.flatMap((param) => (param.name === 'slaveUnit' && param.value.type === 'string' && param.value.value ? [param.value.value] : [])) : [],
onlyShownWhenOwned: boolField(shopEntry, 'showOnlyWhenBought') ?? false,
...(marketplaceItemdefId !== undefined ? { marketplaceItemdefId } : {}),
};
}