fix(cosmetics): deliver decal indexes in the local character pack
The client never downloads downloadable_decals.<hash>.blk: webdlcontent only looks for it in its web cache folder (aces.exe 2.61.0.37 0xd3e710 -> 0xd3f610) and deletes a file whose signature check fails (0xd383e0), so the index the local service served never reached it and every decal was dropped for lack of a texture. The build now stores dldata/downloadable_skins.blk and dldata/downloadable_decals.blk in char.vromfs.bin. The client's vromfs index path (0xd3bc40 -> 0xd3cc60) loads both without hash or signature checks and skips the download path. Each decal points at a built-in decals.dxp.bin texture (star, or panther for wide decals) as placeholder; the texture manager strips the "?options" suffix before the lookup (DagorEngine TextureMetaData::decode), so the existing textures are used. --decal-cache <folder> copies the cache/content folder of the player's online installation into the game copy instead; the client then uses that signed index and its cached textures, and falls back to the cached dldata_s.info because the local service now answers the dldata hosts with 404. The service's index generation, the content hash helper and the decal texture dataset are removed. Checked: typecheck; client startup log shows 1598 decals registered from the vromfs index with no missing textures.
This commit is contained in:
1 parent
8e4d4b6ea3
commit
9ed92c33d4
10 files changed
+242
-407
No files matched your search
@@ -1,12 +1,14 @@
|
||||
/**
|
||||
* Rebuild char.vromfs.bin: config/network.blk pointed at the local service, the offline
|
||||
* version's features turned on in config/game_settings.blk, and every vehicle shown in the
|
||||
* tech tree (config/shop.blk).
|
||||
* 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 } from './pack-edit.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';
|
||||
@@ -18,16 +20,24 @@ export interface CharPackResult {
|
||||
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 function rebuildCharPack(stockPack: Uint8Array, endpoint: LocalEndpoint): CharPackResult {
|
||||
export interface CharPackOptions {
|
||||
/** Store the placeholder decal index (false when the player's own web cache is copied). */
|
||||
readonly placeholderDecals: 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); } },
|
||||
{ path: GAME_SETTINGS_PATH, edit: (root) => { features = enableFeaturesForEveryone(root, OFFLINE_FEATURES); } },
|
||||
{ path: SHOP_PATH, edit: (root) => { revealedVehicles = revealHiddenVehicles(root); } },
|
||||
]);
|
||||
return { pack, network: network!, features, revealedVehicles };
|
||||
], decals?.files ?? []);
|
||||
return { pack, network: network!, features, revealedVehicles, placeholderDecals: decals?.decals };
|
||||
}
|
||||
@@ -4,11 +4,14 @@
|
||||
*
|
||||
* node packages/build/src/cli.ts --game <stock game folder> --out <game copy folder> --port <n>
|
||||
* [--patches exe-patches] [--gui-patches gui-patches]
|
||||
* [--native build/native] [--verbose]
|
||||
* [--native build/native] [--decal-cache <folder>] [--verbose]
|
||||
*
|
||||
* Writes <out>/char.vromfs.bin, <out>/aces.vromfs.bin, <out>/gui.vromfs.bin, <out>/win64/aces.exe
|
||||
* and the network hook library the patched executable loads (<out>/win64/wto_ws.dll from --native,
|
||||
* built by native/wto-net/build.ps1, and its settings wto_ws.cfg). The stock folder is only read.
|
||||
* --decal-cache names the cache/content folder of the player's online installation; it is copied
|
||||
* to <out>/cache/content (decals/player-decal-cache.ts), otherwise char.vromfs.bin gets the
|
||||
* placeholder decal index (decals/offline-decal-index.ts).
|
||||
* The launcher will run the same steps at every launch, with the port the player chose.
|
||||
*/
|
||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
@@ -16,6 +19,7 @@ import { dirname, join } from 'node:path';
|
||||
import { parseArgs } from 'node:util';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { rebuildCharPack } from './char-pack.ts';
|
||||
import { copyPlayerDecalCache, playerDecalCacheProblem } from './decals/player-decal-cache.ts';
|
||||
import { patchExecutable } from './executable.ts';
|
||||
import { assertWritableCopy, GAME_FILES } from './game-copy.ts';
|
||||
import { rebuildGuiPack } from './gui-pack.ts';
|
||||
@@ -36,15 +40,22 @@ function main(): number {
|
||||
patches: { type: 'string', default: 'exe-patches' },
|
||||
'gui-patches': { type: 'string' },
|
||||
native: { type: 'string', default: join('build', 'native') },
|
||||
'decal-cache': { type: 'string' },
|
||||
verbose: { type: 'boolean', default: false },
|
||||
},
|
||||
});
|
||||
if (!values.game || !values.out || !values.port) {
|
||||
console.error('usage: cli.ts --game <stock game folder> --out <game copy folder> --port <n> [--patches exe-patches] [--gui-patches gui-patches] [--native build/native] [--verbose]');
|
||||
console.error('usage: cli.ts --game <stock game folder> --out <game copy folder> --port <n> [--patches exe-patches] [--gui-patches gui-patches] [--native build/native] [--decal-cache <folder>] [--verbose]');
|
||||
return 2;
|
||||
}
|
||||
assertWritableCopy(values.game, values.out);
|
||||
const endpoint = localEndpoint(Number(values.port));
|
||||
const decalCache = values['decal-cache'];
|
||||
const decalCacheProblem = decalCache === undefined ? undefined : playerDecalCacheProblem(decalCache);
|
||||
if (decalCacheProblem) {
|
||||
console.error(`--decal-cache: ${decalCacheProblem}; nothing was written`);
|
||||
return 1;
|
||||
}
|
||||
const hookLibraryPath = join(values.native, NETWORK_HOOK_LIBRARY);
|
||||
if (!existsSync(hookLibraryPath)) {
|
||||
console.error(`${hookLibraryPath} not found (build it with native/wto-net/build.ps1); nothing was written`);
|
||||
@@ -59,7 +70,7 @@ function main(): number {
|
||||
}
|
||||
|
||||
const stockCharPack = readFileSync(join(values.game, GAME_FILES.charPack));
|
||||
const charPack = rebuildCharPack(stockCharPack, endpoint);
|
||||
const charPack = rebuildCharPack(stockCharPack, endpoint, { placeholderDecals: decalCache === undefined });
|
||||
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) {
|
||||
@@ -67,6 +78,7 @@ 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`);
|
||||
if (charPack.placeholderDecals !== undefined) console.log(`dldata: placeholder textures for ${charPack.placeholderDecals} decals`);
|
||||
|
||||
const packBundles = offlinePackBundleGuids(stockCharPack, STORE_TUNING_PATH);
|
||||
const mainPack = rebuildMainPack(readFileSync(join(values.game, GAME_FILES.mainPack)), endpoint, packBundles);
|
||||
@@ -85,6 +97,10 @@ function main(): number {
|
||||
writeOutput(values.out, join(executableFolder, NETWORK_HOOK_LIBRARY), readFileSync(hookLibraryPath));
|
||||
const settings = networkHookSettings(endpoint);
|
||||
writeOutput(values.out, join(executableFolder, settings.name), settings.content);
|
||||
if (decalCache !== undefined) {
|
||||
const copied = copyPlayerDecalCache(decalCache, values.out);
|
||||
console.log(`copied the player's web cache to ${copied.copiedTo} (decal indexes: ${copied.decalIndexes.join(', ')})`);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* Decal and skin indexes stored in char.vromfs.bin, for a game copy that has no decal source
|
||||
* from the player (player-decal-cache.ts): every decal of the stock list shows one of the
|
||||
* client's built-in decal textures as a placeholder.
|
||||
*
|
||||
* How the client gets its decal list (aces.exe 2.61.0.37):
|
||||
* - webdlcontent init (0xd3bc40) first calls the vromfs index loader (0xd3cc60, also run when
|
||||
* regional.vromfs.bin is mounted, 0x15fe55b). If the setting debug{ dldataAllowVromIndex:b }
|
||||
* (default true) allows it and the mounted packs hold both dldata/downloadable_skins.blk and
|
||||
* dldata/downloadable_decals.blk, it loads them ("vromfs:dldata/downloadable_decals.blk"),
|
||||
* registers the decals (0xd3da50) and returns true; init then skips the download path
|
||||
* (jne 0xd3cc0d). No content hash and no signature is checked on this path.
|
||||
* - Otherwise the client reads dldata_s.info and looks for downloadable_decals.<hash>.blk in
|
||||
* its web cache folder (cache/content/, 0xd3e710 -> 0xd3f610). It does not download the
|
||||
* index there: a missing file leaves the list empty ("dldata: selected existing ...",
|
||||
* "registering 0 decals"), and a file that fails the signature check over its last 0x100
|
||||
* bytes (0xd383e0, "dlData: <%s> signature check failed") is deleted. An index the offline
|
||||
* version makes can only reach the client through the vromfs path.
|
||||
* - Each decal is registered as the managed texture "<lod0>*?<texProps_lod0>" (0xd44fc0). The
|
||||
* texture manager drops everything from the last '?' before the name lookup (DagorEngine
|
||||
* prog/engine/baseUtil/texMetaData.cpp TextureMetaData::decode), so lod0 "star" resolves to
|
||||
* "star*" from content/base/res/decals.dxp.bin. Only if no such texture is registered does
|
||||
* the client create a downloadable one from the hdr0 header (0xd49e00).
|
||||
* - config/decals.blk (char.vromfs.bin) is laid over the index afterwards (0xd48380, not
|
||||
* re-verified) and gives each decal its category, aspect ratio, price, unlock and
|
||||
* marketplace id; the index only adds textures.
|
||||
*/
|
||||
import { emptyBlock, encodeBlk, type BlkBlock } from '@wto/blk';
|
||||
import type { AddedFile } from '../pack-edit.ts';
|
||||
|
||||
export const DECALS_CONFIG_PATH = 'config/decals.blk';
|
||||
export const SKINS_INDEX_PATH = 'dldata/downloadable_skins.blk';
|
||||
export const DECALS_INDEX_PATH = 'dldata/downloadable_decals.blk';
|
||||
|
||||
interface PlaceholderTexture {
|
||||
/** Texture name in content/base/res/decals.dxp.bin (without the trailing '*'). */
|
||||
readonly name: string;
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
}
|
||||
|
||||
/** Built-in decal textures of the stock client (decals.dxp.bin: lang, panther, star). */
|
||||
const SQUARE_PLACEHOLDER: PlaceholderTexture = { name: 'star', width: 512, height: 512 };
|
||||
const WIDE_PLACEHOLDER: PlaceholderTexture = { name: 'panther', width: 512, height: 256 };
|
||||
/** Offline design: decals at least this much wider than tall use the wide placeholder. */
|
||||
const WIDE_ASPECT_RATIO = 1.5;
|
||||
|
||||
/** Dagor ddsx::Header (32 bytes) of an unpacked DXT5 texture, the layout hdr0/hdr1 carry. */
|
||||
const DDSX_HEADER_BYTES = 32;
|
||||
const DDSX_MAGIC = 0x78534444; // "DDSx"
|
||||
const DDSX_DXT5_FOURCC = 0x35545844; // "DXT5"
|
||||
const DDSX_UNPACKED_FLAGS = 0x00000044;
|
||||
const DDSX_QUALITY_WORD = 0x7401;
|
||||
const DXT5_BLOCK_BYTES = 16;
|
||||
|
||||
export interface OfflineDecalIndex {
|
||||
readonly files: readonly AddedFile[];
|
||||
readonly decals: number;
|
||||
}
|
||||
|
||||
export function offlineDecalIndex(decalsConfig: BlkBlock): OfflineDecalIndex {
|
||||
const square = textureParams(SQUARE_PLACEHOLDER);
|
||||
const wide = textureParams(WIDE_PLACEHOLDER);
|
||||
const index: BlkBlock = {
|
||||
name: '',
|
||||
params: [],
|
||||
blocks: decalsConfig.blocks.map((decal) => ({
|
||||
name: decal.name,
|
||||
params: aspectRatio(decal) >= WIDE_ASPECT_RATIO ? wide : square,
|
||||
blocks: [],
|
||||
})),
|
||||
};
|
||||
return {
|
||||
files: [
|
||||
{ path: SKINS_INDEX_PATH, content: encodeBlk(emptyBlock()) },
|
||||
{ path: DECALS_INDEX_PATH, content: encodeBlk(index) },
|
||||
],
|
||||
decals: index.blocks.length,
|
||||
};
|
||||
}
|
||||
|
||||
function aspectRatio(decal: BlkBlock): number {
|
||||
const value = decal.params.find((param) => param.name === 'aspect_ratio')?.value;
|
||||
return value?.type === 'real' && Number.isFinite(value.value) && value.value > 0 ? value.value : 1;
|
||||
}
|
||||
|
||||
function textureParams(texture: PlaceholderTexture): BlkBlock['params'] {
|
||||
const header = ddsxDxt5Header(texture.width, texture.height);
|
||||
return [
|
||||
{ name: 'hdr0', value: { type: 'string', value: header } },
|
||||
{ name: 'lod0', value: { type: 'string', value: texture.name } },
|
||||
{ name: 'hdr1', value: { type: 'string', value: header } },
|
||||
{ name: 'lod1', value: { type: 'string', value: texture.name } },
|
||||
];
|
||||
}
|
||||
|
||||
/** Base64 of the 32-byte header; read by 0xd49e00 only when the texture is not registered. */
|
||||
function ddsxDxt5Header(width: number, height: number): string {
|
||||
const header = Buffer.alloc(DDSX_HEADER_BYTES);
|
||||
header.writeUInt32LE(DDSX_MAGIC, 0);
|
||||
header.writeUInt32LE(DDSX_DXT5_FOURCC, 4);
|
||||
header.writeUInt32LE(DDSX_UNPACKED_FLAGS, 8);
|
||||
header.writeUInt16LE(width, 12);
|
||||
header.writeUInt16LE(height, 14);
|
||||
let w = width;
|
||||
let h = height;
|
||||
let levels = 0;
|
||||
let memSize = 0;
|
||||
for (;;) {
|
||||
levels += 1;
|
||||
memSize += Math.ceil(w / 4) * Math.ceil(h / 4) * DXT5_BLOCK_BYTES;
|
||||
if (w === 1 && h === 1) break;
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
header[16] = levels;
|
||||
header.writeUInt16LE(DDSX_QUALITY_WORD, 22);
|
||||
header.writeUInt32LE(memSize, 24);
|
||||
return header.toString('base64');
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Decals from the player's own online client: the player names the web cache folder of an
|
||||
* installation they have played online with (<game>/cache/content), and the build copies it
|
||||
* into the game copy's cache/content. The offline version never looks for that folder itself.
|
||||
*
|
||||
* What the copy gives the client (aces.exe 2.61.0.37):
|
||||
* - cache/content/ is the web cache root ("ContentProvider::init mount=<game>/cache/content/").
|
||||
* - dldata_s.info names the current indexes; when the request for it fails, the client reads
|
||||
* the cached copy ("failed to get dlContent index hashes from %s, will fallback local copy",
|
||||
* 0xd3eb40), and the local service answers that request with 404.
|
||||
* - downloadable_decals.<hash>.blk is the decal index as the CDN served it, with its signature
|
||||
* (0xd383e0 checks it and deletes a file that fails). If the file named by dldata_s.info is
|
||||
* missing, the newest valid downloadable_decals.*.blk in the folder is used (0xd3f610).
|
||||
* - Each decal's texture is fetched through the web cache by its lod0 name (0xd44fc0); the
|
||||
* textures the player's client has cached are in the copied folder (assumed, not verified
|
||||
* against an online cache: the folder layout below httpCache/ was not examined). Textures it
|
||||
* never cached cannot be fetched offline and stay blank.
|
||||
*
|
||||
* With a player source the build leaves the vromfs index (offline-decal-index.ts) out of
|
||||
* char.vromfs.bin, because the client takes the vromfs index first and then skips the web cache.
|
||||
*/
|
||||
import { cpSync, existsSync, readdirSync, statSync } from 'node:fs';
|
||||
import { join, relative, resolve } from 'node:path';
|
||||
|
||||
export const WEB_CACHE_FOLDER = join('cache', 'content');
|
||||
const INDEX_LIST_FILE = 'dldata_s.info';
|
||||
const DECALS_INDEX_FILE = /^downloadable_decals\.[a-z2-7]{32}-[a-z2-7]{1,8}\.blk$/;
|
||||
|
||||
export interface PlayerDecalCache {
|
||||
readonly copiedTo: string;
|
||||
readonly decalIndexes: readonly string[];
|
||||
}
|
||||
|
||||
/** Check that the folder looks like an online client's web cache; returns the problem or undefined. */
|
||||
export function playerDecalCacheProblem(source: string): string | undefined {
|
||||
if (!existsSync(source) || !statSync(source).isDirectory()) return `${source} is not a folder`;
|
||||
if (!existsSync(join(source, INDEX_LIST_FILE))) return `${source} has no ${INDEX_LIST_FILE} (expected the cache/content folder of an online installation)`;
|
||||
if (decalIndexes(source).length === 0) return `${source} has no downloadable_decals.<hash>.blk`;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Copy the player's web cache folder into <copy>/cache/content; the source is only read. */
|
||||
export function copyPlayerDecalCache(source: string, copyFolder: string): PlayerDecalCache {
|
||||
const target = join(copyFolder, WEB_CACHE_FOLDER);
|
||||
const from = resolve(source);
|
||||
const to = resolve(target);
|
||||
if (from === to || !relative(from, to).startsWith('..')) throw new Error(`the decal source ${source} contains the game copy's web cache`);
|
||||
cpSync(from, to, { recursive: true, force: true });
|
||||
return { copiedTo: target, decalIndexes: decalIndexes(source) };
|
||||
}
|
||||
|
||||
function decalIndexes(folder: string): string[] {
|
||||
return readdirSync(folder).filter((name) => DECALS_INDEX_FILE.test(name));
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Rebuild a data pack with some of its BLK documents edited. Every other file of the pack is
|
||||
* kept byte for byte. Edited documents are stored self-contained (they no longer depend on
|
||||
* Rebuild a data pack with some of its BLK documents edited and, optionally, new files added.
|
||||
* Every other file of the pack is kept byte for byte. Edited documents are stored self-contained (they no longer depend on
|
||||
* the pack's shared name map), which the game accepts in every loading mode
|
||||
*.
|
||||
*/
|
||||
@@ -24,7 +24,13 @@ export function editPackBlk<T>(stockPack: Uint8Array, blkPath: string, edit: (ro
|
||||
return { pack, report: report as T };
|
||||
}
|
||||
|
||||
export function editPackBlks(stockPack: Uint8Array, edits: readonly BlkEdit[]): Uint8Array {
|
||||
/** A file the stock pack does not have, stored as is. */
|
||||
export interface AddedFile {
|
||||
readonly path: string;
|
||||
readonly content: Uint8Array;
|
||||
}
|
||||
|
||||
export function editPackBlks(stockPack: Uint8Array, edits: readonly BlkEdit[], added: readonly AddedFile[] = []): Uint8Array {
|
||||
const archive = readArchive(stockPack);
|
||||
const dictionary = findDictionary(archive);
|
||||
const names = archive.files.has(NAME_MAP_PATH) ? parseSharedNameMap(getFile(archive, NAME_MAP_PATH), dictionary).names : [];
|
||||
@@ -33,6 +39,10 @@ export function editPackBlks(stockPack: Uint8Array, edits: readonly BlkEdit[]):
|
||||
edit(root);
|
||||
putFile(archive, path, encodeBlk(root));
|
||||
}
|
||||
for (const file of added) {
|
||||
if (archive.files.has(file.path)) throw new Error(`the data pack already has ${file.path}`);
|
||||
putFile(archive, file.path, file.content);
|
||||
}
|
||||
return writeArchive(archive);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user