/** * Mission completion in the profile: which difficulties the player has completed a mission * on (tutorials and other single-player missions). * * pveProgress{ * missions{ * "tutorial/tutorialB_takeoff_and_landing"{ diff_0:b=yes diff_1:b=yes diff_2:b=yes } * } * } * * Read by the client's profile serializer (aces.exe 2.61.0.37 0x92bd40: "pveProgress" -> * "missions", one sub-block per mission, 0x92f090), each entry by 0x92f7d0: * onlineDiff:i, singleDiff:i optional, -1 when missing * timesCompleted:i, timesPlayed:i optional, 0 when missing * diff_0:b, diff_1:b, diff_2:b completed on arcade, historical, simulator * The entry's name is the mission's full name, "/", the key that the * script function get_mission_progress (0x179c900 -> 0xebad60) looks up. It returns the * highest difficulty completed (0, 1, 2), or 3 or more when there is none. */ import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto/blk'; const PVE_PROGRESS = 'pveProgress'; const MISSIONS = 'missions'; const DIFFICULTIES = [0, 1, 2] as const; export function hasCompletedMissionDifficulty(profile: BlkBlock, fullMissionName: string, difficulty: 0 | 1 | 2): boolean { const pve = findBlock(profile, PVE_PROGRESS); const missions = pve && findBlock(pve, MISSIONS); const mission = missions && findBlock(missions, fullMissionName); const flag = mission && findParam(mission, `diff_${difficulty}`)?.value; return flag?.type === 'bool' && flag.value; } /** Record the mission as completed on every difficulty up to and including `highest` (0, 1 or 2). */ export function recordMissionCompleted(profile: BlkBlock, fullMissionName: string, highest: 0 | 1 | 2): void { const entry = ensureBlock(ensureBlock(ensureBlock(profile, PVE_PROGRESS), MISSIONS), fullMissionName); for (const difficulty of DIFFICULTIES) { if (difficulty <= highest) setParam(entry, `diff_${difficulty}`, { type: 'bool', value: true }); } }