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:
N0VAN0M4LY committed 2026-11-28 12:44:45 +08:00
1 parent 8e4d4b6ea3
commit 9ed92c33d4
10 files changed
+242 -407

No files matched your search

@@ -1,47 +0,0 @@
/**
* The hash strings that name downloadable-content files: base32 of the file's SHA-1, a dash,
* and base32 of the file's size, e.g. "<32 chars>-<1..8 chars>".
*
* Source: aces.exe 2.61.0.37. The client checks the shape (34..41 characters, '-' at
* position 32, no '.' after it; 0xd3f257 for dldata_s.info, 0xd3741a for a downloaded file),
* decodes the size with the alphabet a-z = 0..25, 2-7 = 26..31, most significant digit first
* (0xd37588), compares it with the file's size, then hashes the file with SHA-1 (0xd37642,
* initial value ends in 0xc3d2e1f0) and compares the base32 of that (0xd37744). The alphabet
* is RFC 4648 base32 in lower case.
*/
import { createHash } from 'node:crypto';
const ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
export function contentHash(content: Uint8Array): string {
const sha1 = createHash('sha1').update(content).digest();
return `${base32Bytes(sha1)}-${base32Number(content.length)}`;
}
/** RFC 4648 base32 without padding; 20 bytes of SHA-1 give exactly 32 characters. */
function base32Bytes(bytes: Uint8Array): string {
let text = '';
let buffer = 0;
let bits = 0;
for (const byte of bytes) {
buffer = (buffer << 8) | byte;
bits += 8;
while (bits >= 5) {
bits -= 5;
text += ALPHABET[(buffer >> bits) & 31];
}
buffer &= (1 << bits) - 1;
}
if (bits > 0) text += ALPHABET[(buffer << (5 - bits)) & 31];
return text;
}
function base32Number(value: number): string {
let text = '';
let rest = value;
do {
text = ALPHABET[rest % 32] + text;
rest = Math.floor(rest / 32);
} while (rest > 0);
return text;
}
@@ -1,105 +0,0 @@
/**
* Downloadable skin and decal indexes served on the dldata CDN hosts.
*
* Why both indexes are served:
* - Startup waits up to 60 seconds per index before giving up (aces.exe 2.61.0.37 0xd3fa20,
* "webcache: downloadable ... index hasn't arrived yet").
* - For decals, webdlcontent::getDecalsBlk (0xd41050) merges downloadable_decals.<hash>.blk
* into sharedDecalsBlk (0xd47e20), overlays char.vromfs.bin config/decals.blk (0xd48380),
* and deletes any block lacking both lod0:t and a "<name>*" managed texture (0xd415d6..0xd4183d).
* Populating downloadable_decals.<hash>.blk from config/decals.blk + local DXP2 decal textures
* keeps all 1,598 Hangar Customization decals and Marketplace decal coupons active offline:
* 0xd44fc0 resolves "<lod>*?" via get_managed_texture_id (0x31aec00) directly to the local DXP
* texture without registering webcache HTTP downloads.
*/
import { emptyBlock, encodeBlk, type BlkBlock } from '@wto/blk';
import {
makeDdsxDxt5HeaderBase64,
type DecalConfigEntry,
type DxpDecalTexture,
} from '../game-data/datasets/decal-textures.ts';
import { contentHash } from './content-hash.ts';
export type IndexKind = 'skins' | 'decals';
export interface ContentIndex {
readonly kind: IndexKind;
readonly bytes: Uint8Array;
/** Names the file: downloadable_<kind>.<hash>.blk (0xd3f43d, 0xd3f491). */
readonly hash: string;
}
/** Stock decals.dxp.bin built-in texture names and dimensions when no DXP pack is scanned. */
const DEFAULT_SQUARE_TEX: DxpDecalTexture = {
name: 'star',
width: 512,
height: 512,
aspectRatio: 1,
ddsxHeaderBase64: makeDdsxDxt5HeaderBase64(512, 512),
};
const DEFAULT_WIDE_TEX: DxpDecalTexture = {
name: 'panther',
width: 512,
height: 256,
aspectRatio: 2,
ddsxHeaderBase64: makeDdsxDxt5HeaderBase64(512, 256),
};
const WIDE_ASPECT_THRESHOLD = 1.5;
export function buildContentIndexes(
decals: readonly DecalConfigEntry[] = [],
localDxp: ReadonlyMap<string, DxpDecalTexture> = new Map(),
): ReadonlyMap<IndexKind, ContentIndex> {
const skinsBytes = encodeBlk(emptyBlock());
const decalsBytes = encodeBlk(decals.length > 0 ? buildDecalsIndexBlk(decals, localDxp) : emptyBlock());
return new Map<IndexKind, ContentIndex>([
['skins', { kind: 'skins', bytes: skinsBytes, hash: contentHash(skinsBytes) }],
['decals', { kind: 'decals', bytes: decalsBytes, hash: contentHash(decalsBytes) }],
]);
}
export function emptyContentIndexes(): ReadonlyMap<IndexKind, ContentIndex> {
return buildContentIndexes();
}
function buildDecalsIndexBlk(
decals: readonly DecalConfigEntry[],
localDxp: ReadonlyMap<string, DxpDecalTexture>,
): BlkBlock {
const squareFallback = localDxp.get('star') ?? firstDxpTexture(localDxp) ?? DEFAULT_SQUARE_TEX;
const wideFallback = localDxp.get('panther') ?? widestDxpTexture(localDxp) ?? DEFAULT_WIDE_TEX;
return {
name: '',
params: [],
blocks: decals.map((entry) => {
const target = localDxp.get(entry.name.toLowerCase())
?? (entry.aspectRatio >= WIDE_ASPECT_THRESHOLD ? wideFallback : squareFallback);
return {
name: entry.name,
params: [
{ name: 'category', value: { type: 'string', value: '' } },
{ name: 'aspect_ratio', value: { type: 'real', value: entry.aspectRatio } },
{ name: 'hdr0', value: { type: 'string', value: target.ddsxHeaderBase64 } },
{ name: 'lod0', value: { type: 'string', value: target.name } },
{ name: 'hdr1', value: { type: 'string', value: target.ddsxHeaderBase64 } },
{ name: 'lod1', value: { type: 'string', value: target.name } },
],
blocks: [],
};
}),
};
}
function firstDxpTexture(localDxp: ReadonlyMap<string, DxpDecalTexture>): DxpDecalTexture | undefined {
return localDxp.values().next().value;
}
function widestDxpTexture(localDxp: ReadonlyMap<string, DxpDecalTexture>): DxpDecalTexture | undefined {
let best: DxpDecalTexture | undefined;
for (const candidate of localDxp.values()) {
if (!best || candidate.aspectRatio > best.aspectRatio) best = candidate;
}
return best;
}
@@ -1,61 +1,38 @@
/**
* Downloadable content (dldata): the list of the current skin and decal indexes, and the
* indexes themselves.
* Downloadable content (dldata): there is no CDN offline, so the index list and every file on
* the dldata hosts are answered with 404, each with a note in the traffic log.
*
* - dldata_s.info, from the public-configs host (webdlcontent::init, aces.exe 2.61.0.37
* 0xd3eb40, "%s/dldata_s.info"): a BLK whose strings "skin" and "decal" hold the content
* hashes of the two indexes (0xd3eed3..0xd3f2bd).
* - downloadable_skins.<hash>.blk and downloadable_decals.<hash>.blk, from the dldata hosts
* (network.blk skinsDecalsCDN, e.g. dldata-aws.warthunder.com/production/). The client
* checks size and SHA-1 against the hash (content-hash.ts).
* Where the client gets its decals instead (aces.exe 2.61.0.37; packages/build/src/decals/):
* - No player decal source: char.vromfs.bin holds dldata/downloadable_skins.blk and
* dldata/downloadable_decals.blk, the client loads them at init (0xd3bc40 -> 0xd3cc60) and
* never asks for dldata_s.info.
* - Player decal source: the player's web cache folder is copied to <game>/cache/content; the
* client asks for dldata_s.info (webdlcontent::init 0xd3eb40, "%s/dldata_s.info"), and on
* failure reads its cached copy ("will fallback local copy"), whose indexes are then in the
* folder. Decal textures the cache lacks would be fetched from the dldata hosts
* (network.blk skinsDecalsCDN) and are not available.
* The client does not download the indexes themselves (0xd3e710 only looks in the cache
* folder), so serving them here would have no effect.
*/
import { emptyBlock, encodeBlk, formatBlkText, setParam } from '@wto/blk';
import { scanLocalDecalDxp, type DecalConfigEntry } from '../game-data/datasets/decal-textures.ts';
import type { Service, ServiceRequest, ServiceResponse } from '../server/exchange.ts';
import { buildContentIndexes, type ContentIndex, type IndexKind } from './content-indexes.ts';
const INFO_HOST = /^public-configs[a-z0-9-]*\.(warthunder\.com|cdn\.gaijin\.net)$/;
const INFO_PATH = /^\/[a-z0-9_-]+\/dldata_s\.info$/;
const INDEX_HOST = /^dldata[a-z0-9-]*\.(warthunder\.com|cdn\.gaijin\.net)$/;
const INDEX_FILE = /\/downloadable_(skins|decals)\.([a-z2-7]{32}-[a-z2-7]{1,8})\.blk$/;
const BINARY = { 'content-type': 'application/octet-stream' };
const CONTENT_HOST = /^dldata[a-z0-9-]*\.(warthunder\.com|cdn\.gaijin\.net)$/;
export class DownloadableContentService implements Service {
readonly name = 'dldata';
readonly #indexes: ReadonlyMap<IndexKind, ContentIndex>;
readonly #decalCount: number;
readonly #info: { readonly bytes: Uint8Array; readonly text: string };
constructor(decals: readonly DecalConfigEntry[] = [], gameFolder?: string) {
this.#indexes = buildContentIndexes(decals, scanLocalDecalDxp(gameFolder));
this.#decalCount = decals.length;
this.#info = this.#infoBlk();
}
accepts(request: ServiceRequest): boolean {
const host = request.originalHost;
if (host === undefined || request.method !== 'GET') return false;
return (INFO_HOST.test(host) && INFO_PATH.test(request.path)) || (INDEX_HOST.test(host) && INDEX_FILE.test(request.path));
return (INFO_HOST.test(host) && INFO_PATH.test(request.path)) || CONTENT_HOST.test(host);
}
handle(request: ServiceRequest): ServiceResponse {
if (INFO_PATH.test(request.path)) {
return { status: 200, headers: BINARY, body: this.#info.bytes, logNotes: { summary: 'dldata_s.info', responseText: this.#info.text } };
}
const match = INDEX_FILE.exec(request.path);
const index = match ? this.#indexes.get(match[1] as ContentIndex['kind']) : undefined;
if (!index || index.hash !== match?.[2]) {
return { status: 404, body: 'unknown index', logNotes: { summary: `index ${request.path}: not one this service listed` } };
}
const detail = index.kind === 'decals' && this.#decalCount > 0 ? `${this.#decalCount} decals` : 'empty';
return { status: 200, headers: BINARY, body: index.bytes, logNotes: { summary: `downloadable_${index.kind} (${detail})` } };
}
#infoBlk(): { readonly bytes: Uint8Array; readonly text: string } {
const info = emptyBlock();
setParam(info, 'skin', { type: 'string', value: this.#indexes.get('skins')!.hash });
setParam(info, 'decal', { type: 'string', value: this.#indexes.get('decals')!.hash });
return { bytes: encodeBlk(info), text: formatBlkText(info) };
const summary = INFO_PATH.test(request.path)
? 'dldata_s.info: no CDN offline, the client falls back to its cached copy'
: `${request.path}: no CDN offline`;
return { status: 404, body: 'not available offline', logNotes: { summary } };
}
}
@@ -1,198 +0,0 @@
/**
* Dataset and local DXP2 scanner for Hangar and Marketplace decals.
*
* Why this exists:
* - char.vromfs.bin config/decals.blk lists all stock and marketplace decals (1,598 blocks)
* with category, group, costGold, unlock, marketplaceItemdefId, and aspect_ratio, but omits
* lod0 / lod1 texture fields because the online client merges downloadable_decals.<hash>.blk
* into sharedDecalsBlk first (aces.exe 2.61.0.37 0xd41050 -> 0xd47e20 -> 0xd48380).
* - In webdlcontent::getDecalsBlk (0xd415d6..0xd4183d), any decal block without a lod0 string
* and without a local managed texture "<name>*" (get_managed_texture_id, 0x31aec00) is
* deleted from sharedDecalsBlk ("failed to find texture for decal '%s', skipping it").
* - Stock client installations only ship built-in decal textures in content/base/res/decals.dxp.bin
* (DxP2 v2 pack: lang, panther, star). Extracting the decal list via DatasetCache and scanning
* any local *decal*.dxp.bin headers lets DownloadableContentService populate every decal block
* with valid lod0/lod1 and 32-byte DDSx headers without outbound CDN requests.
*/
import { closeSync, existsSync, openSync, readdirSync, readSync } from 'node:fs';
import { join } from 'node:path';
import { numberField } from './blk-fields.ts';
import type { Dataset } from './dataset.ts';
const DECALS_CONFIG_PATH = 'config/decals.blk';
/** DxP2 v2 pack header constants (verified on content/base/res/decals.dxp.bin). */
const DXP2_MAGIC = 0x32507844; // "DxP2"
const DXP2_VERSION = 2;
const DXP2_PREAMBLE_BYTES = 0x10;
const DXP2_MAX_HEADER_BYTES = 4 * 1024 * 1024;
/** Dagor ddsx::Header binary layout constants (32 bytes, verified at aces.exe 0xd49e00). */
const DDSX_HEADER_BYTES = 32;
const DDSX_MAGIC = 0x78534444; // "DDSx"
const DDSX_DXT5_FOURCC = 0x35545844; // "DXT5"
const DDSX_COMPRESSION_MASK = 0x0fffffff;
const DDSX_UNPACKED_DECAL_FLAGS = 0x00000044;
const DDSX_DECAL_QUALITY_WORD = 0x7401;
const DXT5_BLOCK_BYTES = 16;
export interface DecalConfigEntry {
readonly name: string;
readonly aspectRatio: number;
}
export interface DxpDecalTexture {
readonly name: string;
readonly width: number;
readonly height: number;
readonly aspectRatio: number;
/** Base64-encoded 32-byte unpacked ddsx::Header expected in hdr0 / hdr1 (0xd49e00). */
readonly ddsxHeaderBase64: string;
}
export const decalTextures: Dataset<readonly DecalConfigEntry[]> = {
id: 'decal-textures',
version: 1,
extract: (source) =>
source.readBlk('char.vromfs.bin', DECALS_CONFIG_PATH).blocks.map((entry) => {
const ratio = numberField(entry, 'aspect_ratio');
return {
name: entry.name,
aspectRatio: ratio !== undefined && Number.isFinite(ratio) && ratio > 0 ? ratio : 1,
};
}),
};
/** Scan local *decal*.dxp.bin headers inside the game folder, keyed by lowercase texture name. */
export function scanLocalDecalDxp(gameFolder?: string): ReadonlyMap<string, DxpDecalTexture> {
const found = new Map<string, DxpDecalTexture>();
if (!gameFolder || !existsSync(gameFolder)) return found;
for (const dxpPath of candidateDecalDxpPaths(gameFolder)) {
for (const entry of readDxp2DecalHeaders(dxpPath)) {
const key = entry.name.toLowerCase();
if (!found.has(key)) found.set(key, entry);
}
}
return found;
}
/** Synthesize a 32-byte Dagor DXT5 ddsx::Header (base64) matching downloadable_decals.blk. */
export function makeDdsxDxt5HeaderBase64(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_DECAL_FLAGS, 8);
header.writeUInt16LE(width, 12);
header.writeUInt16LE(height, 14);
const { levels, memSize } = dxt5MipChainSize(width, height);
header[16] = levels;
header.writeUInt16LE(DDSX_DECAL_QUALITY_WORD, 22);
header.writeUInt32LE(memSize, 24);
return header.toString('base64');
}
function dxt5MipChainSize(width: number, height: number): { readonly levels: number; readonly memSize: number } {
let w = Math.max(1, Math.trunc(width));
let h = Math.max(1, Math.trunc(height));
let levels = 0;
let memSize = 0;
for (;;) {
levels += 1;
memSize += Math.max(1, Math.ceil(w / 4)) * Math.max(1, 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);
}
return { levels, memSize };
}
function candidateDecalDxpPaths(gameFolder: string): string[] {
const paths = new Set<string>();
const addResFolder = (resFolder: string): void => {
if (!existsSync(resFolder)) return;
try {
for (const item of readdirSync(resFolder, { withFileTypes: true })) {
if (item.isFile() && /decal.*\.dxp\.bin$/i.test(item.name)) paths.add(join(resFolder, item.name));
}
} catch { /* unreadable optional pack folder */ }
};
addResFolder(join(gameFolder, 'res'));
addResFolder(join(gameFolder, 'content', 'base', 'res'));
const contentRoot = join(gameFolder, 'content');
if (existsSync(contentRoot)) {
try {
for (const pkg of readdirSync(contentRoot, { withFileTypes: true })) {
if (pkg.isDirectory() && pkg.name !== 'base') addResFolder(join(contentRoot, pkg.name, 'res'));
}
} catch { /* unreadable optional content root */ }
}
return [...paths];
}
function readDxp2DecalHeaders(dxpPath: string): DxpDecalTexture[] {
const headerBuf = readDxp2HeaderSlice(dxpPath);
if (!headerBuf) return [];
const count = headerBuf.readUInt32LE(0x08);
const namesTable = DXP2_PREAMBLE_BYTES + headerBuf.readUInt32LE(0x10);
const ddsxTable = DXP2_PREAMBLE_BYTES + headerBuf.readUInt32LE(0x20);
if (namesTable + count * 8 > headerBuf.length || ddsxTable + count * DDSX_HEADER_BYTES > headerBuf.length) {
return [];
}
const textures: DxpDecalTexture[] = [];
for (let i = 0; i < count; i++) {
const nameOffset = DXP2_PREAMBLE_BYTES + Number(headerBuf.readBigUInt64LE(namesTable + i * 8));
const rawName = readNullTerminatedAscii(headerBuf, nameOffset);
const starIndex = rawName.indexOf('*');
const cleanName = (starIndex >= 0 ? rawName.slice(0, starIndex) : rawName).trim();
const ddsxSlice = headerBuf.subarray(ddsxTable + i * DDSX_HEADER_BYTES, ddsxTable + (i + 1) * DDSX_HEADER_BYTES);
if (!cleanName || ddsxSlice.readUInt32LE(0) !== DDSX_MAGIC) continue;
const width = ddsxSlice.readUInt16LE(12);
const height = ddsxSlice.readUInt16LE(14);
if (width === 0 || height === 0) continue;
textures.push({
name: cleanName,
width,
height,
aspectRatio: width / height,
ddsxHeaderBase64: normalizeDdsxHeader(ddsxSlice),
});
}
return textures;
}
function readDxp2HeaderSlice(dxpPath: string): Buffer | undefined {
let fd: number | undefined;
try {
fd = openSync(dxpPath, 'r');
const preamble = Buffer.alloc(DXP2_PREAMBLE_BYTES);
if (readSync(fd, preamble, 0, DXP2_PREAMBLE_BYTES, 0) < DXP2_PREAMBLE_BYTES) return undefined;
if (preamble.readUInt32LE(0) !== DXP2_MAGIC || preamble.readUInt32LE(4) !== DXP2_VERSION) return undefined;
const hdrSize = preamble.readUInt32LE(0x0c);
if (hdrSize === 0 || hdrSize > DXP2_MAX_HEADER_BYTES) return undefined;
const total = DXP2_PREAMBLE_BYTES + hdrSize;
const full = Buffer.alloc(total);
preamble.copy(full, 0);
if (readSync(fd, full, DXP2_PREAMBLE_BYTES, hdrSize, DXP2_PREAMBLE_BYTES) < hdrSize) return undefined;
return full;
} catch {
return undefined;
} finally {
if (fd !== undefined) {
try { closeSync(fd); } catch { /* ignore close failure */ }
}
}
}
function normalizeDdsxHeader(rawHeader: Uint8Array): string {
const unpacked = Buffer.from(rawHeader);
unpacked.writeUInt32LE(unpacked.readUInt32LE(8) & DDSX_COMPRESSION_MASK, 8);
unpacked.writeUInt32LE(0, 28);
return unpacked.toString('base64');
}
function readNullTerminatedAscii(buffer: Buffer, offset: number): string {
if (offset < 0 || offset >= buffer.length) return '';
let end = offset;
while (end < buffer.length && buffer[end] !== 0) end += 1;
return buffer.subarray(offset, end).toString('ascii');
}
+1 -3
View File
@@ -24,7 +24,6 @@ import { BattleLiveLogs } from './battle/battle-live-log.ts';
import { clanEconomy } from './game-data/datasets/clan-economy.ts';
import { crewSkillData } from './game-data/datasets/crew-skills.ts';
import { DatasetCache } from './game-data/datasets/dataset-cache.ts';
import { decalTextures } from './game-data/datasets/decal-textures.ts';
import { decorCatalogue } from './game-data/datasets/decor-catalogue.ts';
import { externalItemSources } from './game-data/datasets/external-item-sources.ts';
import { itemCatalogue } from './game-data/datasets/item-catalogue.ts';
@@ -92,7 +91,6 @@ export async function startLocalService(options: LocalServiceOptions): Promise<R
const economyData = datasets.load(battleEconomy);
const efficiencyData = datasets.load(researchEfficiency);
const streakDefinitions = datasets.load(battleStreaks);
const decals = datasets.load(decalTextures);
const labels = datasets.load(uiLabels);
const { profiles, research, equipment } = setUpProfiles(options.dataFolder, gameFiles, datasets, tuning, { accounts, clans }, vehicles);
const { clanEconomy: squadronEconomy, ...catalogues } = loadDomainCatalogues(datasets, tuning, vehicles, labels);
@@ -135,7 +133,7 @@ export async function startLocalService(options: LocalServiceOptions): Promise<R
battle: { sessions: battleSessions, economy, efficiency: new ResearchEfficiency(efficiencyData, research.techTree), streaks },
notifyInventoryChanged,
})),
new DownloadableContentService(decals, options.gameFolder),
new DownloadableContentService(),
]);
const log = new TrafficLog(options.dataFolder);
const listener = createPortListener(