Files
WT-Offline/packages/patcher/src/decals/offline-decal-index.ts
T
N0VAN0M4LY 27fc535301 Split the repository into apps, packages and patches
Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:

  apps/server        the local server (was packages/local-service),
                     package @wto/server
  packages/patcher   builds the game copy (was packages/build),
                     package @wto/patcher
  patches/exe        exe patch definitions (was exe-patches)
  patches/gui        GUI script patches (was gui-patches)

Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".

The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.

The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.


Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
2026-11-29 03:20:54 +08:00

121 lines
5.4 KiB
TypeScript

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