feat(equipment): persist custom weapon presets and correct decal research
Save revisions to custom weapon presets and return the full profile. Keep an empty top-level weaponPresets block after the final deletion so the client clears its cached presets. Treat the tier-zero allowPremDecals modification as researchable. Type checking passed. In-game acceptance is pending.
This commit is contained in:
1 parent
71ba962e75
commit
f829c9a45f
6 files changed
+168
-6
No files matched your search
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Custom weapon presets in the profile:
|
||||
*
|
||||
* weaponPresets{
|
||||
* fa_18d_late{
|
||||
* custom0{
|
||||
* name:t="编组方案 #1"
|
||||
* Weapon{ preset:t="aim_120_default_slot4" slot:i=4 }
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* `EconomicState::serialize` (aces.exe 0x937a50 at 0x93e62e) delegates top-level `weaponPresets`
|
||||
* to 0x9675e0 (`GameSaveData + 0x1a0`), which calls `DataBlock::setFrom` (0x30934e0) in client
|
||||
* read mode (0x8) ONLY when a `weaponPresets` sub-block is present in `profile.blk`; if the
|
||||
* sub-block is absent, 0x9675e0 returns without clearing `GameSaveData + 0x1a0`. Keeping the
|
||||
* top-level `weaponPresets{}` block present even after the last preset is deleted ensures the
|
||||
* client clears its in-memory custom preset table on profile update.
|
||||
*/
|
||||
import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const WEAPON_PRESETS = 'weaponPresets';
|
||||
|
||||
export function vehicleWeaponPresets(profile: BlkBlock, vehicle: string): readonly BlkBlock[] {
|
||||
const root = findBlock(profile, WEAPON_PRESETS);
|
||||
const unitBlock = root && findBlock(root, vehicle);
|
||||
return unitBlock?.blocks ?? [];
|
||||
}
|
||||
|
||||
export function upsertVehicleWeaponPreset(profile: BlkBlock, vehicle: string, preset: BlkBlock): void {
|
||||
const root = ensureBlock(profile, WEAPON_PRESETS);
|
||||
const unitBlock = ensureBlock(root, vehicle);
|
||||
const copy = structuredClone(preset);
|
||||
const existingIndex = unitBlock.blocks.findIndex((entry) => entry.name === preset.name);
|
||||
if (existingIndex >= 0) unitBlock.blocks[existingIndex] = copy;
|
||||
else unitBlock.blocks.push(copy);
|
||||
}
|
||||
|
||||
export function deleteVehicleWeaponPreset(profile: BlkBlock, vehicle: string, presetName: string): void {
|
||||
const root = ensureBlock(profile, WEAPON_PRESETS);
|
||||
const unitBlock = findBlock(root, vehicle);
|
||||
if (!unitBlock) return;
|
||||
unitBlock.blocks = unitBlock.blocks.filter((entry) => entry.name !== presetName);
|
||||
if (unitBlock.blocks.length === 0 && unitBlock.params.length === 0) {
|
||||
root.blocks = root.blocks.filter((entry) => entry !== unitBlock);
|
||||
}
|
||||
}
|
||||
|
||||
export function clearVehicleWeaponPresets(profile: BlkBlock, vehicle: string): void {
|
||||
const root = ensureBlock(profile, WEAPON_PRESETS);
|
||||
root.blocks = root.blocks.filter((entry) => entry.name !== vehicle);
|
||||
}
|
||||
Reference in new issue
Block a user