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:
N0VAN0M4LY committed 2026-12-03 01:18:14 +08:00
1 parent 5c09c4e47a
commit 4e72bf3746
5 files changed
+121 -21

No files matched your search

@@ -4,7 +4,12 @@
* carry 30,000+ flat sub-blocks; indexing once drops refresh cost from O(N^2) to O(N).
*/
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock, type BlkParam } from '@wto/blk';
import { recordName, type ModificationRecord } from '../profile/profile-modifications.ts';
import {
allModificationBlocks,
MAX_MODIFICATION_BLOCK_ENTRIES,
recordName,
type ModificationRecord,
} from '../profile/profile-modifications.ts';
import type { WeaponRecord } from '../profile/profile-weapons.ts';
const HANGAR = 'hangar';
@@ -21,7 +26,7 @@ export class ProfileEquipmentIndex {
readonly #weapons = new Map<string, BlkBlock>();
readonly #modsResearch = new Map<string, BlkBlock>();
readonly #removedResearch = new Set<string>();
#modificationsBlock: BlkBlock | undefined;
readonly #modificationsBlocks: BlkBlock[];
#weaponsBlock: BlkBlock | undefined;
#modsResearchBlock: BlkBlock | undefined;
@@ -30,9 +35,9 @@ export class ProfileEquipmentIndex {
const hangar = findBlock(profile, HANGAR);
if (hangar) for (const entry of hangar.blocks) this.#hangar.set(entry.name, entry);
this.#modificationsBlock = findBlock(profile, MODIFICATIONS);
if (this.#modificationsBlock) {
for (const entry of this.#modificationsBlock.blocks) this.#modifications.set(entry.name, entry);
this.#modificationsBlocks = allModificationBlocks(profile);
for (const chunk of this.#modificationsBlocks) {
for (const entry of chunk.blocks) this.#modifications.set(entry.name, entry);
}
this.#weaponsBlock = findBlock(profile, WEAPONS);
@@ -103,14 +108,32 @@ export class ProfileEquipmentIndex {
const key = recordName(vehicle, modification);
let block = this.#modifications.get(key);
if (!block) {
this.#modificationsBlock ??= ensureBlock(this.#profile, MODIFICATIONS);
block = { name: key, params: [], blocks: [] };
this.#modificationsBlock.blocks.push(block);
this.#appendModificationBlock(block);
this.#modifications.set(key, block);
}
block.params = orderedModParams(record);
}
#appendModificationBlock(entry: BlkBlock): void {
for (let index = this.#modificationsBlocks.length - 1; index >= 0; index--) {
const chunk = this.#modificationsBlocks[index]!;
if (chunk.blocks.length < MAX_MODIFICATION_BLOCK_ENTRIES) {
chunk.blocks.push(entry);
return;
}
}
const nextChunk: BlkBlock = { name: MODIFICATIONS, params: [], blocks: [entry] };
const lastChunk = this.#modificationsBlocks[this.#modificationsBlocks.length - 1];
if (lastChunk) {
const insertAt = this.#profile.blocks.lastIndexOf(lastChunk) + 1;
this.#profile.blocks.splice(insertAt, 0, nextChunk);
} else {
this.#profile.blocks.push(nextChunk);
}
this.#modificationsBlocks.push(nextChunk);
}
weaponRecord(vehicle: string, weapon: string): WeaponRecord | undefined {
const block = this.#weapons.get(`${vehicle}_${weapon}`);
if (!block) return undefined;
@@ -11,7 +11,7 @@
*/
import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk';
import type { BattleSpawnRulesData } from '../game-data/datasets/battle-spawn-rules.ts';
import { recordName } from '../profile/profile-modifications.ts';
import { allModificationBlocks, appendModificationEntry, recordName } from '../profile/profile-modifications.ts';
import type { EquipmentCatalogue } from './equipment-catalogue.ts';
export interface SupportPlaneModification {
@@ -98,13 +98,14 @@ export function supportPlaneModifications(
export function grantSupportPlaneModifications(profile: BlkBlock, grants: SupportUnitEquipmentGrants): void {
if (grants.modifications.length > 0) {
let modsBlock = findBlock(profile, 'modifications');
const existing = new Set((modsBlock?.blocks ?? []).map((entry) => entry.name));
const existing = new Set<string>();
for (const chunk of allModificationBlocks(profile)) {
for (const entry of chunk.blocks) existing.add(entry.name);
}
for (const { vehicle, modification } of grants.modifications) {
const key = recordName(vehicle, modification);
if (existing.has(key)) continue;
modsBlock ??= ensureBlock(profile, 'modifications');
modsBlock.blocks.push({ name: key, params: [{ name: 'count', value: { type: 'int64', value: 1n } }], blocks: [] });
appendModificationEntry(profile, { name: key, params: [{ name: 'count', value: { type: 'int64', value: 1n } }], blocks: [] });
existing.add(key);
}
}