Files
WT-Offline/apps/server/src/profile/profile-hangar.ts
T
N0VAN0M4LYandduduyagame f2e73c1cfe fix(profile): persist vehicle camouflage, loadout, and trim preferences
Accept the full client-writable hangar/<vehicle> field set emitted by AircraftInfo::serialize (mode 0x20/0x80) in cln_update for owned vehicles: lastSkin, lastWeapon, lastBullets0..5 (strings), and aileronTrim/elevatorTrim/rudderTrim (finite reals). Ownership and server-authoritative hangar fields remain untouched, matching the stock chard guard (2.61.0.37 0x938081) and serializer (2.61.0.37 0x940510, 2.61.0.58 0x942f80).

Extends the camouflage persistence fix from PR #17 to cover weapon presets, ammo belts, and flight trims reported on the same cln_update path. Verified root and launcher typecheck and SaveStore + clientProfile round-trip persistence. In-game acceptance is pending.

Co-authored-by: duduyagame <[email protected]>
2026-12-04 17:47:09 +08:00

49 lines
1.8 KiB
TypeScript

/**
* The profile's hangar has one sub-block per owned vehicle, as in config/default_user.blk.
*
* hangar{
* bf2c_1{
* }
* }
*/
import { ensureBlock, findBlock, setParam, type BlkBlock } from '@wto/blk';
import { intField } from './blk-fields.ts';
const HANGAR = 'hangar';
const MRANK_DELTA = 'mrankDelta';
function ownedVehicle(profile: BlkBlock, vehicle: string): BlkBlock | undefined {
const hangar = findBlock(profile, HANGAR);
return hangar && findBlock(hangar, vehicle);
}
export function ownsVehicle(profile: BlkBlock, vehicle: string): boolean {
return ownedVehicle(profile, vehicle) !== undefined;
}
export function ownedVehicles(profile: BlkBlock): Set<string> {
return new Set((findBlock(profile, HANGAR)?.blocks ?? []).map((owned) => owned.name));
}
/** Add the vehicle to the owned vehicles; nothing changes when the player owns it already. */
export function addOwnedVehicle(profile: BlkBlock, vehicle: string): void {
const hangar = ensureBlock(profile, HANGAR);
if (!hangar.blocks.some((owned) => owned.name === vehicle)) hangar.blocks.push({ name: vehicle, params: [], blocks: [] });
}
/** Update an owned vehicle's hangar entry in place; ignores vehicles the player does not own. */
export function updateOwnedVehicle(profile: BlkBlock, vehicle: string, update: (entry: BlkBlock) => void): void {
const entry = ownedVehicle(profile, vehicle);
if (entry) update(entry);
}
/** The stock client uses the base rank until it has a non-negative selection. */
export function vehicleMrankDelta(profile: BlkBlock, vehicle: string): number {
return Math.max(0, intField(ownedVehicle(profile, vehicle), MRANK_DELTA));
}
export function setVehicleMrankDelta(profile: BlkBlock, vehicle: string, delta: number): void {
const entry = ownedVehicle(profile, vehicle);
if (entry) setParam(entry, MRANK_DELTA, { type: 'int', value: delta });
}