Split inventory definition generation by category and select chest contents deterministically. Move squadron queries, membership, and lifecycle into focused modules and enforce role permissions. Serve store and marketplace pages as static files with shared web helpers. Share profile field readers and keep response encoding in the protocol modules. Restrict cloud settings to registered blocks. Type checking and the save CLI ran successfully. In-game acceptance is pending.
56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
/**
|
|
* Entitlements and Premium Account in the profile (implementation notes; read by aces.exe
|
|
* 2.61.0.37 0x91daf0..0x91e474, has_entitlement 0x179ec70, entitlement_expires_in 0x179ed60):
|
|
*
|
|
* entitlementsInfo{
|
|
* PremiumAccount{
|
|
* count:i=1
|
|
* expiredTime:i64=<Windows FILETIME>
|
|
* }
|
|
* wto_pack_f-5c{
|
|
* count:i=1
|
|
* }
|
|
* }
|
|
*/
|
|
import { ensureBlock, findBlock, setParam, type BlkBlock } from '@wto/blk';
|
|
import { EMPTY_BLK, int64Field, intField } from './blk-fields.ts';
|
|
|
|
const ENTITLEMENTS_INFO = 'entitlementsInfo';
|
|
export const PREMIUM_ACCOUNT_ENTITLEMENT = 'PremiumAccount';
|
|
const TICKS_PER_SECOND = 10_000_000n;
|
|
const TICKS_PER_DAY = 86_400n * TICKS_PER_SECOND;
|
|
|
|
export function hasEntitlement(profile: BlkBlock, name: string, nowFiletime: bigint): boolean {
|
|
const entry = findBlock(findBlock(profile, ENTITLEMENTS_INFO) ?? EMPTY_BLK, name);
|
|
if (!entry) return false;
|
|
const count = intField(entry, 'count');
|
|
if (count <= 0) return false;
|
|
const expires = int64Field(entry, 'expiredTime');
|
|
return expires === 0n || expires > nowFiletime;
|
|
}
|
|
|
|
export function recordEntitlementPurchase(profile: BlkBlock, name: string): void {
|
|
const entry = ensureBlock(ensureBlock(profile, ENTITLEMENTS_INFO), name);
|
|
const previous = intField(entry, 'count');
|
|
setParam(entry, 'count', { type: 'int', value: previous + 1 });
|
|
}
|
|
|
|
export function extendPremiumAccount(profile: BlkBlock, days: number, nowFiletime: bigint): void {
|
|
if (!Number.isSafeInteger(days) || days <= 0) throw new RangeError(`invalid premium days: ${days}`);
|
|
const entry = ensureBlock(ensureBlock(profile, ENTITLEMENTS_INFO), PREMIUM_ACCOUNT_ENTITLEMENT);
|
|
const previousCount = intField(entry, 'count');
|
|
const previousExpiry = int64Field(entry, 'expiredTime');
|
|
const base = previousExpiry > nowFiletime ? previousExpiry : nowFiletime;
|
|
setParam(entry, 'count', { type: 'int', value: previousCount + 1 });
|
|
setParam(entry, 'expiredTime', { type: 'int64', value: base + BigInt(days) * TICKS_PER_DAY });
|
|
}
|
|
|
|
/** Remaining whole days (rounded up) of Premium Account, or 0 when inactive. */
|
|
export function remainingPremiumDays(profile: BlkBlock, nowFiletime: bigint): number {
|
|
const entry = findBlock(findBlock(profile, ENTITLEMENTS_INFO) ?? EMPTY_BLK, PREMIUM_ACCOUNT_ENTITLEMENT);
|
|
if (!entry || intField(entry, 'count') <= 0) return 0;
|
|
const expires = int64Field(entry, 'expiredTime');
|
|
if (expires <= nowFiletime) return 0;
|
|
return Number((expires - nowFiletime + TICKS_PER_DAY - 1n) / TICKS_PER_DAY);
|
|
}
|