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
@@ -11,6 +11,7 @@
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { decodeBlk, encodeBlk, type BlkBlock } from '@wto/blk';
|
||||
import { normalizeModificationBlocks } from '../profile/profile-modifications.ts';
|
||||
import { writeFileAtomic } from '../storage/atomic-file.ts';
|
||||
import type { SaveUpgrades } from './save-upgrades.ts';
|
||||
|
||||
@@ -44,6 +45,7 @@ export class SaveStore {
|
||||
saveProfile(userId: string, profile: BlkBlock): void {
|
||||
const now = new Date().toISOString();
|
||||
const previous = existsSync(this.#infoPath(userId)) ? (JSON.parse(readFileSync(this.#infoPath(userId), 'utf8')) as SaveInfo) : undefined;
|
||||
normalizeModificationBlocks(profile);
|
||||
writeFileAtomic(this.#profilePath(userId), encodeBlk(profile));
|
||||
const info: SaveInfo = { formatVersion: this.#upgrades.currentFormat, created: previous?.created ?? now, updated: now };
|
||||
writeFileAtomic(this.#infoPath(userId), JSON.stringify(info, null, 2));
|
||||
|
||||
@@ -10,7 +10,7 @@ import { InventoryCatalogue } from '../inventory/itemdef-catalogue.ts';
|
||||
import { intField, stringField } from '../profile/blk-fields.ts';
|
||||
import { allCrews } from '../profile/profile-crews.ts';
|
||||
import { ACTIVE_LISTS } from '../profile/profile-items.ts';
|
||||
import { recordName } from '../profile/profile-modifications.ts';
|
||||
import { normalizeModificationBlocks, recordName } from '../profile/profile-modifications.ts';
|
||||
import { loadTuning } from '../tuning/tuning.ts';
|
||||
import type { SaveLocation } from './save-editor.ts';
|
||||
|
||||
@@ -38,9 +38,13 @@ export function prepareTransferredProfile(location: SaveLocation, bytes: Uint8Ar
|
||||
['modifications', modifications], ['modsResearch', modifications], ['weapons', weapons],
|
||||
] as const;
|
||||
for (const [key, allowed] of blockKeys) {
|
||||
const collection = findBlock(profile, key);
|
||||
if (collection) collection.blocks = collection.blocks.filter((entry) => allowed.has(entry.name));
|
||||
for (const collection of profile.blocks) {
|
||||
if (collection.name === key) {
|
||||
collection.blocks = collection.blocks.filter((entry) => allowed.has(entry.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
normalizeModificationBlocks(profile);
|
||||
for (const crew of allCrews(profile)) {
|
||||
const aircraft = findBlock(crew, 'aircrafts');
|
||||
if (aircraft) {
|
||||
|
||||
Reference in new issue
Block a user