/** * Client-writable profile preferences persisted via `cln_update` * (aces.exe 2.61.0.37 `ClientEconomicState::saveOnline` -> `EconomicState::serialize` 0x917870, * mode 0x80 `CHARSRV_GET_FROM_CLIENT`): * - hangar toggles `autoRefillWeapons:b`, `autoRepairAircrafts:b`, `autoBuyModifications:b` (0x918ef0); * - privacy / save metadata `onlineSaveVersion:i`, `allowToBeAddedToContacts:b`, `allowToBeAddedToLB:b` (0x9179d4..0x917a4c); * - `classinessMarkPriorities:i64` (0x92b2cb); * - sub-block `mapPreferences` (0x927530 -> 0x9483d0); * - per-vehicle `hangar/` client preferences (`AircraftInfo::serialize` mode 0x20/0x80, * owned vehicles only per the stock chard guard at 0x938081): * - `lastSkin:t` (2.61.0.37 0x940fbc/0x94111b, 2.61.0.58 0x943a2f/0x943b8e); * - `lastWeapon:t` (2.61.0.37 0x940ff4/0x941084, 2.61.0.58 0x943a67/0x943af7); * - `lastBullets0..5:t` (2.61.0.37 0x94078d..0x940914 / 0x940b2c..0x940f8d, 2.61.0.58 0x943200..0x94393e); * - `aileronTrim:r`, `elevatorTrim:r`, `rudderTrim:r` (2.61.0.37 0x941682..0x941720 / 0x9411e7..0x9412db, * 2.61.0.58 0x943c7a..0x944119). * * Empty shell blocks that `saveOnline` (mode 0x20) also emits (`entitlementsInfo{}`, * `pveProgress{}`, `weaponPresets{}` — custom weapon presets use `cln_save_weapon_presets`, and * mode 0x80 skips `weaponPresets` at 0x9677d8) are intentionally ignored so server-authoritative * state is preserved. */ import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto/blk'; import { updateOwnedVehicle } from './profile-hangar.ts'; import { disableUserLogs } from './profile-trophies-log.ts'; const BOOL_SETTINGS = [ 'autoRefillWeapons', 'autoRepairAircrafts', 'autoBuyModifications', 'allowToBeAddedToContacts', 'allowToBeAddedToLB', ] as const; const VEHICLE_STRING_SETTINGS = [ 'lastSkin', 'lastWeapon', 'lastBullets0', 'lastBullets1', 'lastBullets2', 'lastBullets3', 'lastBullets4', 'lastBullets5', ] as const; const VEHICLE_TRIM_SETTINGS = [ 'aileronTrim', 'elevatorTrim', 'rudderTrim', ] as const; /** * Whether hangar ammunition/expendable auto-refill is enabled (`EconomicState` +0xe979). * Defaults to `true` when absent from `profile.blk`, matching `aces.exe` 0x90b6a0 and 0x918ef0. */ export function isAutoRefillWeaponsEnabled(profile: BlkBlock): boolean { const param = findParam(profile, 'autoRefillWeapons')?.value; return param?.type === 'bool' ? param.value : true; } /** Whether vehicles are repaired automatically after a battle (`EconomicState` +0xe978); `true` when absent (0x90b6a0). */ export function isAutoRepairEnabled(profile: BlkBlock): boolean { const param = findParam(profile, 'autoRepairAircrafts')?.value; return param?.type === 'bool' ? param.value : true; } export function applyClientProfileUpdate(profile: BlkBlock, request: BlkBlock): void { for (const name of BOOL_SETTINGS) { const param = findParam(request, name)?.value; if (param?.type === 'bool') setParam(profile, name, param); } const onlineSaveVer = findParam(request, 'onlineSaveVersion')?.value; if (onlineSaveVer?.type === 'int') setParam(profile, 'onlineSaveVersion', onlineSaveVer); const markPriorities = findParam(request, 'classinessMarkPriorities')?.value; if (markPriorities?.type === 'int64') setParam(profile, 'classinessMarkPriorities', markPriorities); const mapPreferences = findBlock(request, 'mapPreferences'); if (mapPreferences) { const target = ensureBlock(profile, 'mapPreferences'); const cloned = structuredClone(mapPreferences); target.params = cloned.params; target.blocks = cloned.blocks; } for (const vehicle of findBlock(request, 'hangar')?.blocks ?? []) { applyVehicleClientSettings(profile, vehicle); } const userlogs = findBlock(request, 'userlogs'); if (userlogs) { const idsToDisable = userlogs.blocks .filter((entry) => { const flag = findParam(entry, 'haveToDisable')?.value; return flag?.type === 'bool' && flag.value; }) .map((entry) => entry.name); if (idsToDisable.length > 0) disableUserLogs(profile, idsToDisable); } } function applyVehicleClientSettings(profile: BlkBlock, vehicle: BlkBlock): void { updateOwnedVehicle(profile, vehicle.name, (entry) => { for (const name of VEHICLE_STRING_SETTINGS) { const param = findParam(vehicle, name)?.value; if (param?.type === 'string') setParam(entry, name, param); } for (const name of VEHICLE_TRIM_SETTINGS) { const param = findParam(vehicle, name)?.value; if (param?.type === 'real' && Number.isFinite(param.value)) setParam(entry, name, param); } }); }