70 lines
2.9 KiB
TypeScript
70 lines
2.9 KiB
TypeScript
/**
|
|
* Rebuild aces.vromfs.bin with the engine settings' server addresses pointed at the local
|
|
* server.
|
|
*
|
|
* config/settings.blk, block `network`: publicConfigsUrl and publicConfigsUrls are where the
|
|
* engine's public-configs module downloads files at startup, including a signed network.blk
|
|
* that would replace the one in char.vromfs.bin (DagorEngine prog/gameLibs/publicConfigs/
|
|
* publicConfigs.cpp, init). On a machine with internet access the download would succeed and
|
|
* point the game back at Gaijin's servers. Redirected, the request reaches the local server;
|
|
* it has no such file, so the game keeps the network.blk of char.vromfs.bin.
|
|
*
|
|
* Only the `network` block is touched: the rest of settings.blk is engine configuration, not
|
|
* server addresses.
|
|
*/
|
|
import { ensureBlock, findBlock, setParam, type BlkBlock } from '@wto/blk';
|
|
import { redirectAddresses, type AddressChange } from './network/address-rewrite.ts';
|
|
import type { LocalEndpoint } from './network/local-endpoint.ts';
|
|
import { editPackBlks } from './pack-edit.ts';
|
|
|
|
export const ENGINE_SETTINGS_PATH = 'config/settings.blk';
|
|
export const GUI_CONFIG_PATH = 'config/gui.blk';
|
|
const NETWORK_BLOCK = 'network';
|
|
|
|
/**
|
|
* GUIDs added to config/gui.blk bundles/guid so scripts/onlineShop/entitlementsInfo.nut
|
|
* requests GJN prices for GJN-priced Premium Account tiers alongside the stock eagles* packs.
|
|
*/
|
|
export const EXTRA_STORE_BUNDLE_GUIDS: ReadonlyArray<readonly [entitlement: string, guid: string]> = [
|
|
['wto_prem_20d', 'A1E00020-5754-4F46-8F00-000000000020'],
|
|
['wto_prem_60d', 'A1E00060-5754-4F46-8F00-000000000060'],
|
|
['wto_prem_180d', 'A1E00180-5754-4F46-8F00-000000000180'],
|
|
];
|
|
|
|
export const EXTRA_STORE_BUNDLE_GUID_MAP: Readonly<Record<string, string>> = Object.fromEntries(EXTRA_STORE_BUNDLE_GUIDS);
|
|
|
|
export interface MainPackResult {
|
|
readonly pack: Uint8Array;
|
|
readonly addresses: readonly AddressChange[];
|
|
}
|
|
|
|
export function rebuildMainPack(
|
|
stockPack: Uint8Array,
|
|
endpoint: LocalEndpoint,
|
|
extraBundles: ReadonlyArray<readonly [string, string]> = [],
|
|
): MainPackResult {
|
|
let addresses: AddressChange[] = [];
|
|
const pack = editPackBlks(stockPack, [
|
|
{
|
|
path: ENGINE_SETTINGS_PATH,
|
|
edit: (root) => {
|
|
const network = findBlock(root, NETWORK_BLOCK);
|
|
if (!network) throw new Error(`${ENGINE_SETTINGS_PATH} has no "${NETWORK_BLOCK}" block; this game build differs from the verified ones`);
|
|
addresses = redirectAddresses(network, endpoint, [NETWORK_BLOCK]);
|
|
},
|
|
},
|
|
{
|
|
path: GUI_CONFIG_PATH,
|
|
edit: (root) => registerStoreBundleGuids(root, [...EXTRA_STORE_BUNDLE_GUIDS, ...extraBundles]),
|
|
},
|
|
]);
|
|
return { pack, addresses };
|
|
}
|
|
|
|
function registerStoreBundleGuids(guiRoot: BlkBlock, bundles: ReadonlyArray<readonly [string, string]>): void {
|
|
const guidBlock = ensureBlock(ensureBlock(guiRoot, 'bundles'), 'guid');
|
|
for (const [entitlement, guid] of bundles) {
|
|
setParam(guidBlock, entitlement, { type: 'string', value: guid });
|
|
}
|
|
}
|