Files
WT-Offline/packages/local-service/src/profile/profile-client-settings.ts
T
N0VAN0M4LY 533a263d6e Persist acknowledged user logs and hangar preferences
Handle cln_update so acknowledged notifications do not reappear.
Persist client preferences and ignore unrelated placeholder blocks.
2026-11-25 22:46:35 +08:00

56 lines
2.4 KiB
TypeScript

/**
* 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).
*
* 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 { disableUserLogs } from './profile-trophies-log.ts';
const BOOL_SETTINGS = [
'autoRefillWeapons',
'autoRepairAircrafts',
'autoBuyModifications',
'allowToBeAddedToContacts',
'allowToBeAddedToLB',
] as const;
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;
}
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);
}
}