Files
WT-Offline/packages/local-service/src/downloadable-content/content-indexes.ts
T
N0VAN0M4LY b260d2899e chore(battle): snapshot the LocalMP rework baseline
Records the uncommitted battle-session work exactly as it was left
(local service matchmaking, settlement, chat, native LocalMP hooks,
battle gui/exe patches) so the following review and rework commits
show every correction as a diff against this state.

This commit is not reviewed and is known to be incomplete: in-game
testing reported wrong settlement rewards, single-country teams,
missing random/fixed supplement slots, misattributed hit messages and
other regressions. Do not merge this branch before the rework lands.
2026-11-28 03:15:47 +08:00

106 lines
4.0 KiB
TypeScript

/**
* 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;
}