fix(patcher): support regional.vromfs.bin decal and skin indexes on cache import
Modern online War Thunder clients (verified on 2.61.0.58) ship their decal and skin indexes (dldata/downloadable_decals.blk and dldata/downloadable_skins.blk) inside cache/binary.<ver>/regional.vromfs.bin rather than downloading downloadable_decals.<hash>.blk into cache/content/. Requiring downloadable_decals.<hash>.blk rejected every live 2.61 cache/content folder. - Accept modern online caches containing cached .ddsx textures alongside a sibling binary.<ver>/regional.vromfs.bin (as well as selecting the parent cache folder or legacy downloadable_decals.<hash>.blk caches). - Extract both dldata/downloadable_decals.blk and dldata/downloadable_skins.blk into a self-contained .wto-index snapshot on launcher import (excluded from the copied game cache/content folder) and embed them into char.vromfs.bin during copy build so webdlcontent::init mounts cache/content and resolves cached real decals and downloadable skins natively without client patches. - Log the specific rejection reason in launcher decal import and clarify the en/zh-CN prompts. Verified with root and launcher npm run typecheck, launcher electron-vite build, and an end-to-end temporary import + char.vromfs.bin build against a read-only 2.61.0.58 online cache (4,080 decals / 1,930 skins embedded). In-game acceptance pending on an isolated 2.61.0.58 client copy.
This commit is contained in:
1 parent
deffcd6dde
commit
662e837ab2
9 files changed
+218
-42
No files matched your search
@@ -1,47 +1,98 @@
|
||||
/**
|
||||
* 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.
|
||||
* Decals and downloadable skins 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, or its
|
||||
* parent <game>/cache), and the build copies the cached textures 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 server 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.
|
||||
* Two layouts exist across War Thunder builds (verified on 2.61.0.37 and 2.61.0.58):
|
||||
* 1. Modern vromfs-indexed cache (2.61+): cache/content/ holds dldata_s.info and the downloaded
|
||||
* <first2>/<hash>.ddsx textures, while the decal and skin indexes (dldata/downloadable_decals.blk
|
||||
* and dldata/downloadable_skins.blk) ship inside sibling cache/binary.<ver>/regional.vromfs.bin
|
||||
* (mounted by webdlcontent::on_regional_vrom_remounted, 0xd3cf95 -> 0xd3d066). Because the client
|
||||
* reads the vromfs index first, it never writes downloadable_decals.<hash>.blk into cache/content/.
|
||||
* We extract both index BLKs into a self-contained snapshot (.wto-index/) on import and embed
|
||||
* them into char.vromfs.bin during build so webdlcontent::init mounts cache/content/ (0xd3ca11)
|
||||
* and loads the real hashes from vromfs without signature checks (0xd3cb6b).
|
||||
* 2. Legacy webcache-indexed cache: cache/content/ holds dldata_s.info and signed
|
||||
* downloadable_decals.<hash>.blk directly; char.vromfs.bin omits dldata/ so the client reads
|
||||
* the cached index from cache/content/.
|
||||
*/
|
||||
import { cpSync, existsSync, lstatSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
||||
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
||||
import { cpSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
||||
import { basename, dirname, isAbsolute, join, relative, sep } from 'node:path';
|
||||
import { decodeBlk, emptyBlock, encodeBlk, parseSharedNameMap } from '@wto/blk';
|
||||
import { getFile, NAME_MAP_PATH, readArchive } from '@wto/vromfs';
|
||||
import type { AddedFile } from '../pack-edit.ts';
|
||||
import { compareVersions } from '../version-record.ts';
|
||||
import { DECALS_INDEX_PATH, SKINS_INDEX_PATH } from './offline-decal-index.ts';
|
||||
|
||||
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$/;
|
||||
const BINARY_CACHE_DIR = /^binary\.(.+)$/;
|
||||
const REGIONAL_PACK_NAME = 'regional.vromfs.bin';
|
||||
const SNAPSHOT_INDEX_DIR = '.wto-index';
|
||||
const SNAPSHOT_DECALS_FILE = 'downloadable_decals.blk';
|
||||
const SNAPSHOT_SKINS_FILE = 'downloadable_skins.blk';
|
||||
|
||||
export interface PlayerDecalCache {
|
||||
readonly copiedTo: string;
|
||||
readonly decalIndexes: readonly string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the actual cache/content folder when the player selects either <game>/cache/content
|
||||
* or its parent <game>/cache folder.
|
||||
*/
|
||||
export function resolvePlayerDecalCacheFolder(source: string): string {
|
||||
if (!existsSync(source) || !statSync(source).isDirectory()) return source;
|
||||
if (directDecalCacheProblem(source) === undefined) return source;
|
||||
const nested = join(source, 'content');
|
||||
if (existsSync(nested) && statSync(nested).isDirectory() && directDecalCacheProblem(nested) === undefined) {
|
||||
return nested;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/** 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 (!statSync(join(source, INDEX_LIST_FILE), { throwIfNoEntry: false })?.isFile()) 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;
|
||||
const resolved = resolvePlayerDecalCacheFolder(source);
|
||||
return directDecalCacheProblem(resolved);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read real dldata/downloadable_decals.blk and dldata/downloadable_skins.blk for embedding into
|
||||
* char.vromfs.bin when the cache uses either an imported snapshot index or a sibling
|
||||
* binary.<ver>/regional.vromfs.bin. Returns undefined for legacy downloadable_decals.<hash>.blk
|
||||
* caches, which supply their index directly inside cache/content/.
|
||||
*/
|
||||
export function readPlayerDecalIndexFiles(source: string): readonly AddedFile[] | undefined {
|
||||
const folder = resolvePlayerDecalCacheFolder(source);
|
||||
const snapshot = readSnapshotIndexFiles(folder);
|
||||
if (snapshot) return snapshot;
|
||||
if (decalIndexes(folder).length > 0) return undefined;
|
||||
const regional = findRegionalPack(folder);
|
||||
if (!regional) return undefined;
|
||||
return extractRegionalIndexFiles(regional);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist extracted vromfs decal/skin indexes into an imported cache snapshot so subsequent
|
||||
* launches are completely self-contained and never touch the online client directory.
|
||||
*/
|
||||
export function writeDecalCacheIndexSnapshot(source: string, target: string): void {
|
||||
const files = readPlayerDecalIndexFiles(source);
|
||||
if (!files) return;
|
||||
const indexDir = join(target, SNAPSHOT_INDEX_DIR);
|
||||
mkdirSync(indexDir, { recursive: true });
|
||||
for (const file of files) {
|
||||
const fileName = file.path === DECALS_INDEX_PATH ? SNAPSHOT_DECALS_FILE : SNAPSHOT_SKINS_FILE;
|
||||
writeFileSync(join(indexDir, fileName), file.content);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 from = realpathSync(source);
|
||||
const from = realpathSync(resolvePlayerDecalCacheFolder(source));
|
||||
const target = join(realpathSync(copyFolder), WEB_CACHE_FOLDER);
|
||||
if (contains(from, target) || contains(target, from)) {
|
||||
throw new Error('The decal source and game copy cache overlap.');
|
||||
@@ -49,10 +100,12 @@ export function copyPlayerDecalCache(source: string, copyFolder: string): Player
|
||||
if (lstatSync(dirname(target), { throwIfNoEntry: false })?.isSymbolicLink()) {
|
||||
throw new Error('The game cache folder is redirected.');
|
||||
}
|
||||
const snapshotDir = join(from, SNAPSHOT_INDEX_DIR);
|
||||
cpSync(from, target, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
filter: (input, output) => {
|
||||
if (input === snapshotDir || input.startsWith(snapshotDir + sep)) return false;
|
||||
const entry = lstatSync(input);
|
||||
const existing = lstatSync(output, { throwIfNoEntry: false });
|
||||
if ((!entry.isFile() && !entry.isDirectory()) || existing?.isSymbolicLink() ||
|
||||
@@ -62,7 +115,94 @@ export function copyPlayerDecalCache(source: string, copyFolder: string): Player
|
||||
return true;
|
||||
},
|
||||
});
|
||||
return { copiedTo: target, decalIndexes: decalIndexes(from) };
|
||||
const legacy = decalIndexes(from);
|
||||
const indexLabels = legacy.length > 0
|
||||
? legacy
|
||||
: (readSnapshotIndexFiles(from) || findRegionalPack(from) ? [DECALS_INDEX_PATH, SKINS_INDEX_PATH] : []);
|
||||
return { copiedTo: target, decalIndexes: indexLabels };
|
||||
}
|
||||
|
||||
function directDecalCacheProblem(folder: string): string | undefined {
|
||||
if (!existsSync(folder) || !statSync(folder).isDirectory()) return `${folder} is not a folder`;
|
||||
if (readSnapshotIndexFiles(folder)) return undefined;
|
||||
if (statSync(join(folder, INDEX_LIST_FILE), { throwIfNoEntry: false })?.isFile() && decalIndexes(folder).length > 0) {
|
||||
return undefined;
|
||||
}
|
||||
const hasTextures = hasCachedDdsxTextures(folder);
|
||||
const regional = findRegionalPack(folder);
|
||||
if (hasTextures && regional) return undefined;
|
||||
if (!hasTextures && !regional) {
|
||||
return `${folder} has neither cached .ddsx textures nor downloadable_decals.<hash>.blk (log into the online hangar once to populate cache/content)`;
|
||||
}
|
||||
if (!hasTextures) {
|
||||
return `${folder} has no cached .ddsx textures yet (log into the online hangar once to cache decals or skins)`;
|
||||
}
|
||||
return `${folder} has no downloadable_decals.<hash>.blk and no sibling binary.*/${REGIONAL_PACK_NAME}`;
|
||||
}
|
||||
|
||||
function readSnapshotIndexFiles(folder: string): readonly AddedFile[] | undefined {
|
||||
const decalsPath = join(folder, SNAPSHOT_INDEX_DIR, SNAPSHOT_DECALS_FILE);
|
||||
if (!statSync(decalsPath, { throwIfNoEntry: false })?.isFile()) return undefined;
|
||||
const skinsPath = join(folder, SNAPSHOT_INDEX_DIR, SNAPSHOT_SKINS_FILE);
|
||||
const skinsContent = statSync(skinsPath, { throwIfNoEntry: false })?.isFile()
|
||||
? readFileSync(skinsPath)
|
||||
: encodeBlk(emptyBlock());
|
||||
return [
|
||||
{ path: SKINS_INDEX_PATH, content: skinsContent },
|
||||
{ path: DECALS_INDEX_PATH, content: readFileSync(decalsPath) },
|
||||
];
|
||||
}
|
||||
|
||||
function hasCachedDdsxTextures(folder: string): boolean {
|
||||
for (const entry of readdirSync(folder, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory() || entry.name === SNAPSHOT_INDEX_DIR) continue;
|
||||
const sub = join(folder, entry.name);
|
||||
for (const child of readdirSync(sub, { withFileTypes: true })) {
|
||||
if (child.isFile() && child.name.endsWith('.ddsx')) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function findRegionalPack(contentFolder: string): string | undefined {
|
||||
const parent = dirname(contentFolder);
|
||||
if (parent === contentFolder || !existsSync(parent)) return undefined;
|
||||
const candidates: Array<{ readonly path: string; readonly version: string; readonly mtimeMs: number }> = [];
|
||||
for (const entry of readdirSync(parent, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
|
||||
const match = BINARY_CACHE_DIR.exec(entry.name);
|
||||
if (!match) continue;
|
||||
const packPath = join(parent, entry.name, REGIONAL_PACK_NAME);
|
||||
const stat = lstatSync(packPath, { throwIfNoEntry: false });
|
||||
if (!stat || !stat.isFile() || stat.isSymbolicLink()) continue;
|
||||
candidates.push({ path: packPath, version: match[1]!, mtimeMs: stat.mtimeMs });
|
||||
}
|
||||
candidates.sort((a, b) => compareVersions(b.version, a.version) || b.mtimeMs - a.mtimeMs || basename(b.path).localeCompare(basename(a.path)));
|
||||
for (const candidate of candidates) {
|
||||
try {
|
||||
const archive = readArchive(readFileSync(candidate.path));
|
||||
if (archive.files.has(DECALS_INDEX_PATH)) return candidate.path;
|
||||
} catch {
|
||||
// Skip unreadable or partially written regional packs and try older ones.
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function extractRegionalIndexFiles(regionalPackPath: string): readonly AddedFile[] {
|
||||
const archive = readArchive(readFileSync(regionalPackPath));
|
||||
const dictionaries = [...archive.files.keys()].filter((path) => path.endsWith('.dict'));
|
||||
const dictionary = dictionaries.length === 1 ? archive.files.get(dictionaries[0]!) : undefined;
|
||||
const names = archive.files.has(NAME_MAP_PATH) ? parseSharedNameMap(getFile(archive, NAME_MAP_PATH), dictionary).names : [];
|
||||
const shared = { names, dictionary };
|
||||
const decalsBlk = decodeBlk(getFile(archive, DECALS_INDEX_PATH), shared);
|
||||
const skinsBlk = archive.files.has(SKINS_INDEX_PATH)
|
||||
? decodeBlk(getFile(archive, SKINS_INDEX_PATH), shared)
|
||||
: emptyBlock();
|
||||
return [
|
||||
{ path: SKINS_INDEX_PATH, content: encodeBlk(skinsBlk) },
|
||||
{ path: DECALS_INDEX_PATH, content: encodeBlk(decalsBlk) },
|
||||
];
|
||||
}
|
||||
|
||||
function contains(parent: string, child: string): boolean {
|
||||
|
||||
Reference in new issue
Block a user