/** * Rebuild char.vromfs.bin: config/network.blk pointed at the local server, the offline * version's features turned on in config/game_settings.blk, every vehicle shown in the * tech tree (config/shop.blk), and, unless the player gave a decal source, placeholder decal * and skin indexes (decals/offline-decal-index.ts). */ import { DECALS_CONFIG_PATH, offlineDecalIndex } from './decals/offline-decal-index.ts'; import { enableFeaturesForEveryone, GAME_SETTINGS_PATH, OFFLINE_FEATURES } from './features/offline-features.ts'; import type { LocalEndpoint } from './network/local-endpoint.ts'; import { redirectNetworkConfig, type NetworkRedirectReport } from './network/redirect-network-config.ts'; import { editPackBlks, readPackBlk } from './pack-edit.ts'; import { revealHiddenVehicles, SHOP_PATH } from './tech-tree/reveal-hidden-vehicles.ts'; export const NETWORK_CONFIG_PATH = 'config/network.blk'; export interface CharPackResult { readonly pack: Uint8Array; readonly network: NetworkRedirectReport; /** Features that are now on for every player. */ readonly features: readonly string[]; /** Vehicles that were hidden from players who had not researched or bought them. */ readonly revealedVehicles: number; /** Decals in the placeholder index; undefined when the index was left out. */ readonly placeholderDecals: number | undefined; } 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 { let network: NetworkRedirectReport | undefined; let features: string[] = []; 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, options.localRegistration); } }, { path: GAME_SETTINGS_PATH, edit: (root) => { features = enableFeaturesForEveryone(root, OFFLINE_FEATURES); } }, { path: SHOP_PATH, edit: (root) => { revealedVehicles = revealHiddenVehicles(root); } }, ], decals?.files ?? []); return { pack, network: network!, features, revealedVehicles, placeholderDecals: decals?.decals }; }