feat(inventory): add external inventory, marketplace, and supply chests

Define external inventory items and support GJN purchases, recycling,
and supply chest drops.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 07:19:07 +08:00
1 parent 129d796095
commit 415f78e761
27 files changed
+2538 -15

No files matched your search

@@ -0,0 +1,157 @@
/**
* Dataset: stock game references to external inventory itemdef IDs outside shop.blk vehicles
*:
* - Decorator marketplace coupons in char.vromfs.bin config/{skins,decals,attachable}.blk;
* - Unlock/pilot-icon marketplace coupons in char.vromfs.bin config/unlocks.blk;
* - Workshop referenced itemdef IDs in aces.vromfs.bin config/workshop.blk.
*/
import type { BlkBlock } from '@wto/blk';
import { numberField, stringField } from './blk-fields.ts';
import type { Dataset, DatasetSource } from './dataset.ts';
import type { DecorKind } from './decor-catalogue.ts';
import type { LocalizedText } from './unit-names.ts';
export interface MarketplaceDecorCoupon {
readonly itemdefId: number;
readonly kind: DecorKind;
readonly resourceKey: string;
readonly rarityColor?: string;
readonly name: LocalizedText;
}
export interface MarketplaceUnlockCoupon {
readonly itemdefId: number;
readonly unlockId: string;
readonly unlockType: string;
readonly name: LocalizedText;
}
export interface ExternalItemSources {
readonly decorCoupons: readonly MarketplaceDecorCoupon[];
readonly unlockCoupons: readonly MarketplaceUnlockCoupon[];
readonly workshopItemdefIds: readonly number[];
}
const DECOR_FILES: readonly { kind: DecorKind; blkPath: string; csvPath: string }[] = [
{ kind: 'skin', blkPath: 'config/skins.blk', csvPath: 'lang/unlocks_skins.csv' },
{ kind: 'decal', blkPath: 'config/decals.blk', csvPath: 'lang/unlocks_decals.csv' },
{ kind: 'attachable', blkPath: 'config/attachable.blk', csvPath: 'lang/unlocks_attachables.csv' },
];
export const externalItemSources: Dataset<ExternalItemSources> = {
id: 'external-item-sources',
version: 1,
extract: (source) => {
const decorCoupons = DECOR_FILES.flatMap(({ kind, blkPath, csvPath }) => extractDecorCoupons(source, kind, blkPath, csvPath));
const unlockCoupons = extractUnlockCoupons(source);
const workshopItemdefIds = [...collectWorkshopIds(source.readBlk('aces.vromfs.bin', 'config/workshop.blk'))].sort((a, b) => a - b);
return { decorCoupons, unlockCoupons, workshopItemdefIds };
},
};
function extractDecorCoupons(
source: DatasetSource,
kind: DecorKind,
blkPath: string,
csvPath: string,
): MarketplaceDecorCoupon[] {
const locMap = parseCsvNames(source.readText('lang.vromfs.bin', csvPath));
const root = source.readBlk('char.vromfs.bin', blkPath);
const out: MarketplaceDecorCoupon[] = [];
for (const entry of root.blocks) {
const itemdefId = numberField(entry, 'marketplaceItemdefId');
if (!itemdefId || itemdefId <= 0) continue;
const key = entry.name;
const localized = locMap.get(key)
?? locMap.get(`decals/${key}`)
?? locMap.get(`attachables/${key}`)
?? { en: humanizeKey(key), zh: humanizeKey(key) };
const rarityColor = stringField(entry, 'userlogColoredText') ?? undefined;
out.push({ itemdefId, kind, resourceKey: key, ...(rarityColor ? { rarityColor } : {}), name: localized });
}
return out;
}
function extractUnlockCoupons(source: DatasetSource): MarketplaceUnlockCoupon[] {
const menuLoc = parseCsvNames(source.readText('lang.vromfs.bin', 'lang/menu.csv'));
const achieveLoc = parseCsvNames(source.readText('lang.vromfs.bin', 'lang/unlocks_achievements.csv'));
const root = source.readBlk('char.vromfs.bin', 'config/unlocks.blk');
const out: MarketplaceUnlockCoupon[] = [];
for (const entry of root.blocks) {
const itemdefId = numberField(entry, 'marketplaceItemdefId');
const unlockId = stringField(entry, 'id');
if (!itemdefId || itemdefId <= 0 || !unlockId) continue;
const unlockType = stringField(entry, 'type') ?? 'unlock';
const localized = achieveLoc.get(`${unlockId}/name`)
?? menuLoc.get(`${unlockId}/name`)
?? achieveLoc.get(unlockId)
?? menuLoc.get(unlockId)
?? { en: humanizeKey(unlockId), zh: humanizeKey(unlockId) };
out.push({ itemdefId, unlockId, unlockType, name: localized });
}
return out;
}
function collectWorkshopIds(block: BlkBlock, out = new Set<number>()): Set<number> {
for (const param of block.params) {
if (param.value.type === 'int' && param.value.value >= 1000) out.add(param.value.value);
else if (param.value.type === 'string' && /^\d{4,}$/.test(param.value.value)) out.add(Number(param.value.value));
}
if (/^\d{4,}$/.test(block.name)) out.add(Number(block.name));
for (const child of block.blocks) collectWorkshopIds(child, out);
return out;
}
function parseCsvNames(csvText: string): Map<string, LocalizedText> {
const lines = csvText.split(/\r?\n/);
const header = parseSemicolonRow(lines[0] ?? '');
const idIdx = 0;
const enIdx = Math.max(1, header.findIndex((col) => col.includes('<English>')));
const zhIdx = header.findIndex((col) => col.includes('<Chinese>'));
const hzhIdx = header.findIndex((col) => col.includes('<HChinese>'));
const map = new Map<string, LocalizedText>();
for (let i = 1; i < lines.length; i += 1) {
const line = lines[i];
if (!line) continue;
const cols = parseSemicolonRow(line);
const id = cols[idIdx];
if (!id) continue;
const en = cleanText(cols[enIdx] ?? '') || id;
const zh = cleanText((zhIdx >= 0 ? cols[zhIdx] : '') || (hzhIdx >= 0 ? cols[hzhIdx] : '') || '') || en;
map.set(id, { en, zh });
}
return map;
}
function parseSemicolonRow(line: string): string[] {
const fields: string[] = [];
let current = '';
let inQuotes = false;
for (let i = 0; i < line.length; i += 1) {
const ch = line[i]!;
if (ch === '"') {
if (inQuotes && line[i + 1] === '"') {
current += '"';
i += 1;
} else {
inQuotes = !inQuotes;
}
} else if (ch === ';' && !inQuotes) {
fields.push(current);
current = '';
} else {
current += ch;
}
}
fields.push(current);
return fields;
}
function cleanText(text: string): string {
return text.replace(/\u200b/g, '').trim();
}
function humanizeKey(key: string): string {
const leaf = key.includes('/') ? key.slice(key.indexOf('/') + 1) : key;
return leaf.replace(/[_-]+/g, ' ').replace(/\b[a-z]/g, (ch) => ch.toUpperCase());
}
@@ -66,11 +66,13 @@ export interface ItemDefinition {
readonly spare?: SpareConditions;
readonly wager?: WagerLimits;
readonly discount?: DiscountDefinition;
/** External inventory craft-part itemdef id granted on recycling (299000..299004; implementation notes). */
readonly recycleItemResult?: number;
}
export const itemCatalogue: Dataset<readonly ItemDefinition[]> = {
id: 'item-catalogue',
version: 1,
version: 2,
extract: (source) => source.readBlk('char.vromfs.bin', ITEMS).blocks.flatMap(itemOf),
};
@@ -81,6 +83,7 @@ function itemOf(entry: BlkBlock): ItemDefinition[] {
const lifetimeHoursAfterActivation = positive(numberField(entry, 'expiredTimeHAfterActivation'));
const expiresAt = utcTime(stringField(entry, 'expiredAt'));
const purchaseFeature = stringField(entry, 'purchase_feature');
const recycleItemResult = positive(numberField(entry, 'recycleItemResult'));
const spare = spareOf(blockAt(entry, 'universalSpareParams'));
const wager = wagerOf(blockAt(entry, 'wagerParams'));
const discount = discountOf(blockAt(entry, 'personalDiscountsParams'));
@@ -95,6 +98,7 @@ function itemOf(entry: BlkBlock): ItemDefinition[] {
...(lifetimeHours !== undefined ? { lifetimeHours } : {}),
...(lifetimeHoursAfterActivation !== undefined ? { lifetimeHoursAfterActivation } : {}),
...(expiresAt !== undefined ? { expiresAt } : {}),
...(recycleItemResult !== undefined ? { recycleItemResult } : {}),
...(spare ? { spare } : {}),
...(wager ? { wager } : {}),
...(discount ? { discount } : {}),