/** * Earned unlocks in the profile. * * unlocks{ * unlock{ item:t="country_usa" cachedIndex:i=-1 expired:b=no earned:b=yes } * } * * The client's profile reader (aces.exe 2.61.0.37 0x919060, from 0x91bad2) walks the * sub-blocks of "unlocks" named "unlock" and reads each one's parameters in this order, * matching every position by name: * item:t the unlock's id from config/unlocks.blk; must come first * ("TROPHY: Bad DataBlock for unlock - NO id param" otherwise) * cachedIndex:i optional; the unlock's position in the client's table, only a * lookup hint: a negative value makes the client look it up by name * (0x91c052) * expired:b optional * removeTimeMinutes:i optional * earned:b only "earned:b=yes" marks the unlock earned (0x91c289..0x91c2b7 * sets the flag that the script function is_unlocked, 0x179eae0, * reads); without it the unlock is registered but not earned * The client's own profile writer (0x91cd6f..) emits the same head: item, cachedIndex, * expired, then removeTimeMinutes when set, then earned. */ import { ensureBlock, findParam, type BlkBlock, type BlkParam } from '@wto/blk'; const UNLOCKS = 'unlocks'; const UNLOCK = 'unlock'; const ITEM = 'item'; /** The unlocks recorded as earned. */ export function earnedUnlocks(profile: BlkBlock): Set { const unlocks = profile.blocks.find((block) => block.name === UNLOCKS); const earned = new Set(); for (const unlock of unlocks?.blocks ?? []) { const name = unlockName(unlock); const flag = findParam(unlock, 'earned')?.value; if (name !== undefined && flag?.type === 'bool' && flag.value) earned.add(name); } return earned; } /** Record the unlock as earned, rewriting an existing entry for it. */ export function addUnlock(profile: BlkBlock, name: string): void { const unlocks = ensureBlock(profile, UNLOCKS); const existing = unlocks.blocks.find((unlock) => unlockName(unlock) === name); if (existing) existing.params = earnedUnlockParams(name); else unlocks.blocks.push({ name: UNLOCK, params: earnedUnlockParams(name), blocks: [] }); } function earnedUnlockParams(name: string): BlkParam[] { return [ { name: ITEM, value: { type: 'string', value: name } }, { name: 'cachedIndex', value: { type: 'int', value: -1 } }, { name: 'expired', value: { type: 'bool', value: false } }, { name: 'earned', value: { type: 'bool', value: true } }, ]; } function unlockName(unlock: BlkBlock): string | undefined { if (unlock.name !== UNLOCK) return undefined; const item = findParam(unlock, ITEM)?.value; return item?.type === 'string' ? item.value : undefined; }