fix(profile): split modifications across sibling blocks at 65,535 entries
Dagor's binary DataBlock stores child block counts in a uint16 (65,535 max), and the full 2.61.0.58 vehicle catalogue contains 76,041 modifications. Writing all owned modifications into a single `modifications` block caused encodeBlk to throw BlkFormatError once a save crossed 65,535 entries, preventing saving and login. Match aces.exe's native multi-block layout (2.61.0.37 0x938fae..0x9397e6, 2.61.0.58 0x93ba70 / 0x93bb53), which splits modifications across up to 3 sibling top-level `modifications` blocks of at most 65,535 entries each: - Add allModificationBlocks, appendModificationEntry, and normalizeModificationBlocks in profile-modifications.ts and span all chunks in modificationRecord, ownsModification, and writeModificationRecord. - Index and append across sibling chunks in ProfileEquipmentIndex and grantSupportPlaneModifications. - Filter all sibling chunks in prepareTransferredProfile and normalize before encoding in SaveStore.saveProfile. Verified with root npm run typecheck and a 2.61.0.58 temporary save check encoding, decoding, and filtering >65,535 modifications across sibling chunks. In-game acceptance pending on an isolated 2.61.0.58 client copy.
This commit is contained in:
1 parent
5c09c4e47a
commit
4e72bf3746
5 files changed
+121
-21
No files matched your search
@@ -12,11 +12,19 @@
|
||||
* the first one that does not match (aces.exe 0x942740), so a record is always rewritten whole:
|
||||
* wpSpent:i goldSpent:i lastWpCost:i lastGoldCost:i persist:b rpEarned:i enabled:b count:i64 modLevel:i
|
||||
* Absent values are left out; enabled is only written when false (the default is enabled).
|
||||
*
|
||||
* Dagor's binary DataBlock stores child block counts in a uint16 (65,535 max). Because the full
|
||||
* vehicle catalogue exceeds 65,535 modifications, aces.exe splits modifications across up to 3
|
||||
* sibling top-level `modifications` blocks of at most 65,535 entries each (2.61.0.37 0x938fae..0x9397e6,
|
||||
* 2.61.0.58 0x93ba70 / 0x93bb53). All readers and writers here span every sibling block.
|
||||
*/
|
||||
import { ensureBlock, findBlock, type BlkBlock, type BlkParam } from '@wto/blk';
|
||||
import type { BlkBlock, BlkParam } from '@wto/blk';
|
||||
|
||||
const MODIFICATIONS = 'modifications';
|
||||
|
||||
/** Maximum entries per `modifications` DataBlock (uint16 child count limit in aces.exe 0x939000 / 0x93ba70). */
|
||||
export const MAX_MODIFICATION_BLOCK_ENTRIES = 0xffff;
|
||||
|
||||
export interface ModificationRecord {
|
||||
readonly silverLionsSpent: number;
|
||||
readonly goldenEaglesSpent: number;
|
||||
@@ -29,9 +37,66 @@ export function recordName(vehicle: string, modification: string): string {
|
||||
return `${vehicle}_${modification}`;
|
||||
}
|
||||
|
||||
/** Every top-level `modifications` chunk in the profile, in document order. */
|
||||
export function allModificationBlocks(profile: BlkBlock): BlkBlock[] {
|
||||
return profile.blocks.filter((block) => block.name === MODIFICATIONS);
|
||||
}
|
||||
|
||||
/** Append a new modification entry to a chunk with spare capacity, opening a sibling chunk when full. */
|
||||
export function appendModificationEntry(profile: BlkBlock, entry: BlkBlock): void {
|
||||
const chunks = allModificationBlocks(profile);
|
||||
for (let index = chunks.length - 1; index >= 0; index--) {
|
||||
const chunk = chunks[index]!;
|
||||
if (chunk.blocks.length < MAX_MODIFICATION_BLOCK_ENTRIES) {
|
||||
chunk.blocks.push(entry);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const nextChunk: BlkBlock = { name: MODIFICATIONS, params: [], blocks: [entry] };
|
||||
const lastChunk = chunks[chunks.length - 1];
|
||||
if (lastChunk) {
|
||||
const insertAt = profile.blocks.lastIndexOf(lastChunk) + 1;
|
||||
profile.blocks.splice(insertAt, 0, nextChunk);
|
||||
} else {
|
||||
profile.blocks.push(nextChunk);
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure every top-level `modifications` chunk stays within the 65,535-child DataBlock limit. */
|
||||
export function normalizeModificationBlocks(profile: BlkBlock): void {
|
||||
const chunks = allModificationBlocks(profile);
|
||||
if (chunks.length === 0) return;
|
||||
const needsRebalance = chunks.some((chunk) => chunk.blocks.length > MAX_MODIFICATION_BLOCK_ENTRIES)
|
||||
|| (chunks.length > 1 && chunks.some((chunk) => chunk.blocks.length === 0));
|
||||
if (!needsRebalance) return;
|
||||
|
||||
const firstIndex = profile.blocks.findIndex((block) => block.name === MODIFICATIONS);
|
||||
const entries = chunks.flatMap((chunk) => chunk.blocks);
|
||||
profile.blocks = profile.blocks.filter((block) => block.name !== MODIFICATIONS);
|
||||
if (entries.length === 0) return;
|
||||
|
||||
const rebuilt: BlkBlock[] = [];
|
||||
for (let offset = 0; offset < entries.length; offset += MAX_MODIFICATION_BLOCK_ENTRIES) {
|
||||
rebuilt.push({
|
||||
name: MODIFICATIONS,
|
||||
params: [],
|
||||
blocks: entries.slice(offset, offset + MAX_MODIFICATION_BLOCK_ENTRIES),
|
||||
});
|
||||
}
|
||||
profile.blocks.splice(Math.max(0, firstIndex), 0, ...rebuilt);
|
||||
}
|
||||
|
||||
function findModificationEntry(profile: BlkBlock, key: string): BlkBlock | undefined {
|
||||
for (const chunk of profile.blocks) {
|
||||
if (chunk.name !== MODIFICATIONS) continue;
|
||||
const found = chunk.blocks.find((entry) => entry.name === key);
|
||||
if (found) return found;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function modificationRecord(profile: BlkBlock, vehicle: string, modification: string): ModificationRecord | undefined {
|
||||
const block = findBlock(profile, MODIFICATIONS);
|
||||
const record = block && findBlock(block, recordName(vehicle, modification));
|
||||
const record = findModificationEntry(profile, recordName(vehicle, modification));
|
||||
if (!record) return undefined;
|
||||
return {
|
||||
silverLionsSpent: intOf(record, 'wpSpent'),
|
||||
@@ -42,12 +107,17 @@ export function modificationRecord(profile: BlkBlock, vehicle: string, modificat
|
||||
}
|
||||
|
||||
export function ownsModification(profile: BlkBlock, vehicle: string, modification: string): boolean {
|
||||
return modificationRecord(profile, vehicle, modification) !== undefined;
|
||||
return findModificationEntry(profile, recordName(vehicle, modification)) !== undefined;
|
||||
}
|
||||
|
||||
export function writeModificationRecord(profile: BlkBlock, vehicle: string, modification: string, record: ModificationRecord): void {
|
||||
const block = ensureBlock(ensureBlock(profile, MODIFICATIONS), recordName(vehicle, modification));
|
||||
block.params = orderedParams(record);
|
||||
const key = recordName(vehicle, modification);
|
||||
const existing = findModificationEntry(profile, key);
|
||||
if (existing) {
|
||||
existing.params = orderedParams(record);
|
||||
return;
|
||||
}
|
||||
appendModificationEntry(profile, { name: key, params: orderedParams(record), blocks: [] });
|
||||
}
|
||||
|
||||
function orderedParams(record: ModificationRecord): BlkParam[] {
|
||||
|
||||
Reference in new issue
Block a user