feat(patcher): build a loopback client copy with TypeScript

Add the shared BLK, VROMFS, executable patch, and build packages. Preserve
typed fields and shared name tables when reading BLK data. Rewrite the
service endpoints in place so the original environment names remain
available to the client, then build the client copy.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 00:35:13 +08:00
1 parent 89aa5198c3
commit c3914ec0d6
44 files changed
+1986 -1

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
/**
* Rebuild char.vromfs.bin with config/network.blk pointed at the local service. Every other
* file of the pack is kept byte for byte. The rewritten network.blk is stored self-contained
* (it no longer depends on the pack's shared name map), which the game accepts in every
* loading mode.
*/
import { decodeBlk, encodeBlk, parseSharedNameMap } from '@wto/blk';
import { getFile, NAME_MAP_PATH, putFile, readArchive, writeArchive, type Archive } from '@wto/vromfs';
import type { LocalEndpoint } from './network/local-endpoint.ts';
import { redirectNetworkConfig, type NetworkRedirectReport } from './network/redirect-network-config.ts';
export const NETWORK_CONFIG_PATH = 'config/network.blk';
export interface CharPackResult {
readonly pack: Uint8Array;
readonly network: NetworkRedirectReport;
}
export function rebuildCharPack(stockPack: Uint8Array, endpoint: LocalEndpoint): CharPackResult {
const archive = readArchive(stockPack);
const dictionary = findDictionary(archive);
const shared = parseSharedNameMap(getFile(archive, NAME_MAP_PATH), dictionary);
const networkConfig = decodeBlk(getFile(archive, NETWORK_CONFIG_PATH), { names: shared.names, dictionary });
const network = redirectNetworkConfig(networkConfig, endpoint);
putFile(archive, NETWORK_CONFIG_PATH, encodeBlk(networkConfig));
return { pack: writeArchive(archive), network };
}
/** The pack's zstd dictionary, if it has one (char.vromfs.bin in 2.61.0.37 has none). */
function findDictionary(archive: Archive): Uint8Array | undefined {
const dictionaries = [...archive.files.keys()].filter((path) => path.endsWith('.dict'));
if (dictionaries.length > 1) throw new Error(`the data pack has several zstd dictionaries: ${dictionaries.join(', ')}`);
return dictionaries.length ? archive.files.get(dictionaries[0]!) : undefined;
}