Add store and marketplace deep links and coupon resale

Register bundle GUIDs at build time and return local store item URLs.
Route marketplace item links to the requested coupon. Update vehicle
and cosmetic prices from the marketplace snapshot and support selling
coupons back to the system at the configured fee.

Type checking, an isolated build, and local service checks passed.
In-game acceptance is pending.
This commit is contained in:
N0VAN0M4LY committed 2026-11-26 07:12:38 +08:00
1 parent b6964658d7
commit c01ee8ae5a
16 files changed
+588 -250

No files matched your search

+10 -2
View File
@@ -14,6 +14,7 @@
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { parseArgs } from 'node:util';
import { fileURLToPath } from 'node:url';
import { rebuildCharPack } from './char-pack.ts';
import { patchExecutable } from './executable.ts';
import { assertWritableCopy, GAME_FILES } from './game-copy.ts';
@@ -21,6 +22,10 @@ import { rebuildGuiPack } from './gui-pack.ts';
import { rebuildMainPack } from './main-pack.ts';
import { localEndpoint } from './network/local-endpoint.ts';
import { NETWORK_HOOK_LIBRARY, networkHookSettings } from './network/network-hook.ts';
import { offlinePackBundleGuids } from './store/offline-bundles.ts';
/** The local service's default store tuning; its multi-vehicle pack ids get bundle GUIDs too. */
const STORE_TUNING_PATH = fileURLToPath(new URL('../../local-service/tuning/store.jsonc', import.meta.url));
function main(): number {
const { values } = parseArgs({
@@ -53,7 +58,8 @@ function main(): number {
return 1;
}
const charPack = rebuildCharPack(readFileSync(join(values.game, GAME_FILES.charPack)), endpoint);
const stockCharPack = readFileSync(join(values.game, GAME_FILES.charPack));
const charPack = rebuildCharPack(stockCharPack, endpoint);
console.log(`network.blk: ${charPack.network.addresses.length} address(es) now point to ${endpoint.host}:${endpoint.port}; ` +
`environments configured: ${charPack.network.environments.join(', ')}`);
if (values.verbose) {
@@ -62,7 +68,9 @@ function main(): number {
console.log(`game_settings.blk: features on for every player: ${charPack.features.join(', ') || '(already on)'}`);
console.log(`shop.blk: ${charPack.revealedVehicles} hidden vehicles shown in the tech tree`);
const mainPack = rebuildMainPack(readFileSync(join(values.game, GAME_FILES.mainPack)), endpoint);
const packBundles = offlinePackBundleGuids(stockCharPack, STORE_TUNING_PATH);
const mainPack = rebuildMainPack(readFileSync(join(values.game, GAME_FILES.mainPack)), endpoint, packBundles);
console.log(`gui.blk: ${packBundles.length} offline vehicle pack bundle GUID(s) registered`);
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}`);
+8 -4
View File
@@ -39,7 +39,11 @@ export interface MainPackResult {
readonly addresses: readonly AddressChange[];
}
export function rebuildMainPack(stockPack: Uint8Array, endpoint: LocalEndpoint): MainPackResult {
export function rebuildMainPack(
stockPack: Uint8Array,
endpoint: LocalEndpoint,
extraBundles: ReadonlyArray<readonly [string, string]> = [],
): MainPackResult {
let addresses: AddressChange[] = [];
const pack = editPackBlks(stockPack, [
{
@@ -52,15 +56,15 @@ export function rebuildMainPack(stockPack: Uint8Array, endpoint: LocalEndpoint):
},
{
path: GUI_CONFIG_PATH,
edit: (root) => registerStoreBundleGuids(root),
edit: (root) => registerStoreBundleGuids(root, [...EXTRA_STORE_BUNDLE_GUIDS, ...extraBundles]),
},
]);
return { pack, addresses };
}
function registerStoreBundleGuids(guiRoot: BlkBlock): void {
function registerStoreBundleGuids(guiRoot: BlkBlock, bundles: ReadonlyArray<readonly [string, string]>): void {
const guidBlock = ensureBlock(ensureBlock(guiRoot, 'bundles'), 'guid');
for (const [entitlement, guid] of EXTRA_STORE_BUNDLE_GUIDS) {
for (const [entitlement, guid] of bundles) {
setParam(guidBlock, entitlement, { type: 'string', value: guid });
}
}
+8
View File
@@ -36,6 +36,14 @@ export function editPackBlks(stockPack: Uint8Array, edits: readonly BlkEdit[]):
return writeArchive(archive);
}
/** Read one BLK document of a pack without changing anything. */
export function readPackBlk(stockPack: Uint8Array, path: string): BlkBlock {
const archive = readArchive(stockPack);
const dictionary = findDictionary(archive);
const names = archive.files.has(NAME_MAP_PATH) ? parseSharedNameMap(getFile(archive, NAME_MAP_PATH), dictionary).names : [];
return decodeBlk(getFile(archive, path), { names, dictionary });
}
/** The pack's zstd dictionary, if it has one. */
function findDictionary(archive: Archive): Uint8Array | undefined {
const dictionaries = [...archive.files.keys()].filter((path) => path.endsWith('.dict'));
@@ -0,0 +1,35 @@
/**
* Offline store bundle GUIDs for config/gui.blk `bundles/guid`.
*
* The game opens a gift vehicle's own store page only when `getBundleId(<entitlement>)` finds a
* GUID for it (scripts/onlineShop/onlineShopModel.nut showUnitGoods → doBrowserPurchaseByGuid);
* the URL then comes from the local service's item_info.php `url` field. Every vehicle carrying
* `gift` in char.vromfs.bin config/wpcost.blk gets `stableGuid(wto_pack_<vehicle>)`, and every
* multi-vehicle pack listed in the local service's tuning/store.jsonc gets `stableGuid(<pack id>)`;
* entries the store does not sell are never looked up, so registering extra ones is harmless.
*/
import { existsSync, readFileSync } from 'node:fs';
import { singleVehiclePackId, stableGuid, type BlkBlock } from '@wto/blk';
import { readPackBlk } from '../pack-edit.ts';
export const WPCOST_PATH = 'config/wpcost.blk';
export function offlinePackBundleGuids(charPack: Uint8Array, storeTuningPath: string): Array<readonly [string, string]> {
const ids = new Set<string>();
for (const vehicle of giftVehicles(readPackBlk(charPack, WPCOST_PATH))) ids.add(singleVehiclePackId(vehicle));
for (const id of multiVehiclePackIds(storeTuningPath)) ids.add(id);
return [...ids].sort().map((id) => [id, stableGuid(id)] as const);
}
function giftVehicles(wpcost: BlkBlock): string[] {
return wpcost.blocks.filter((unit) => unit.params.some((param) => param.name === 'gift')).map((unit) => unit.name);
}
/** Pack ids of `multiVehiclePacks` in tuning/store.jsonc (a plain scan; the file is JSON with comments). */
function multiVehiclePackIds(storeTuningPath: string): string[] {
if (!existsSync(storeTuningPath)) return [];
const text = readFileSync(storeTuningPath, 'utf8');
const start = text.indexOf('"multiVehiclePacks"');
if (start < 0) return [];
return [...text.slice(start).matchAll(/"id"\s*:\s*"([^"]+)"/g)].map((match) => match[1]!);
}