Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
131 lines
5.2 KiB
TypeScript
131 lines
5.2 KiB
TypeScript
/**
|
|
* Trophy open counts and UserLog entries in the profile:
|
|
* - `trophies{ <trophyId>{ count:i=<openCount> } }` (aces.exe 0x92d16b, 0x92d4df);
|
|
* - `userlogs{ <16-hex-id>{ type:i=<EULT> time:i=<unixSec> roomId:i64=0 [disabled:b=yes] body{ ... } } }`
|
|
* (UserLog::serialize 0x95f160, entry fields 0x95ec30; EULT_OPEN_TROPHY = 30 at 0x1a5599b).
|
|
*/
|
|
import { appendParam, emptyBlock, ensureBlock, findBlock, findParam, setParam, type BlkBlock, type BlkParam } from '@wto/blk';
|
|
import { intField } from './blk-fields.ts';
|
|
import { serverTimeToUnixSeconds, type ServerTime } from './server-time.ts';
|
|
|
|
const TROPHIES = 'trophies';
|
|
const USERLOGS = 'userlogs';
|
|
const PURCHASE_RECEIPT = 'purchaseReceipt';
|
|
|
|
// Registered by the client at 0x1a554dc / 0x1a5569e / 0x1a5599b (2.61.0.37).
|
|
export const EULT_SESSION_RESULT = 2;
|
|
const EULT_BUYENTITLEMENT = 13;
|
|
export const EULT_OPEN_TROPHY = 30;
|
|
export const EULT_BUY_TROPHY = 20;
|
|
// Registered by the client at 0x1a558ba / 0x1a55ad6 (2.61.0.37).
|
|
export const EULT_CHARD_AWARD = 25;
|
|
export const EULT_REMOVE_ITEM = 37;
|
|
|
|
export function trophyOpenCount(profile: BlkBlock, trophyId: string): number {
|
|
const trophies = findBlock(profile, TROPHIES);
|
|
return intField(trophies && findBlock(trophies, trophyId), 'count');
|
|
}
|
|
|
|
export function incrementTrophyOpenCount(profile: BlkBlock, trophyId: string, delta = 1): number {
|
|
const entry = ensureBlock(ensureBlock(profile, TROPHIES), trophyId);
|
|
const next = trophyOpenCount(profile, trophyId) + delta;
|
|
setParam(entry, 'count', { type: 'int', value: next });
|
|
return next;
|
|
}
|
|
|
|
export interface NewUserLogEntry {
|
|
readonly type: number;
|
|
readonly timeSec: number;
|
|
readonly roomId?: bigint;
|
|
readonly bodyParams: readonly BlkParam[];
|
|
readonly bodyBlocks?: readonly BlkBlock[];
|
|
}
|
|
|
|
export function appendUserLog(profile: BlkBlock, entry: NewUserLogEntry): string {
|
|
const logs = ensureBlock(profile, USERLOGS);
|
|
const timeId = BigInt(entry.timeSec) * 1000n;
|
|
// Older entries may be out of timestamp order after a system clock correction.
|
|
let highestId = 0n;
|
|
for (const log of logs.blocks) {
|
|
if (!/^[0-9a-f]{16}$/i.test(log.name)) continue;
|
|
const logId = BigInt('0x' + log.name);
|
|
if (logId > highestId) highestId = logId;
|
|
}
|
|
const id = timeId > highestId ? timeId : highestId + 1n;
|
|
const idHex = id.toString(16).padStart(16, '0');
|
|
logs.blocks.push({
|
|
name: idHex,
|
|
params: [
|
|
{ name: 'type', value: { type: 'int', value: entry.type } },
|
|
{ name: 'time', value: { type: 'int', value: entry.timeSec } },
|
|
{ name: 'roomId', value: { type: 'int64', value: entry.roomId ?? 0n } },
|
|
],
|
|
blocks: [{
|
|
name: 'body',
|
|
params: [...entry.bodyParams],
|
|
blocks: [...(entry.bodyBlocks ?? [])],
|
|
}],
|
|
});
|
|
return idHex;
|
|
}
|
|
|
|
interface EntitlementPurchase {
|
|
readonly productId: string;
|
|
readonly goldenEagleCost: number | undefined;
|
|
readonly goldenEagles: number;
|
|
readonly silverLions: number;
|
|
readonly premiumDays: number;
|
|
readonly vehicles: readonly string[];
|
|
}
|
|
|
|
export function appendEntitlementPurchase(
|
|
profile: BlkBlock, purchase: EntitlementPurchase, time: ServerTime,
|
|
): void {
|
|
const bodyParams: BlkParam[] = [
|
|
{ name: 'name', value: { type: 'string', value: purchase.productId } },
|
|
];
|
|
if (purchase.goldenEagleCost !== undefined) {
|
|
bodyParams.push({ name: 'cost', value: { type: 'int', value: purchase.goldenEagleCost } });
|
|
}
|
|
|
|
const receipt = emptyBlock(PURCHASE_RECEIPT);
|
|
if (purchase.goldenEagles > 0) setParam(receipt, 'goldIncome', { type: 'int', value: purchase.goldenEagles });
|
|
if (purchase.silverLions > 0) setParam(receipt, 'wpIncome', { type: 'int64', value: BigInt(purchase.silverLions) });
|
|
if (purchase.premiumDays > 0) setParam(receipt, 'premiumDays', { type: 'int', value: purchase.premiumDays });
|
|
for (const vehicle of purchase.vehicles) {
|
|
appendParam(receipt, 'aircraftGift', { type: 'string', value: vehicle });
|
|
}
|
|
appendUserLog(profile, {
|
|
type: EULT_BUYENTITLEMENT,
|
|
timeSec: serverTimeToUnixSeconds(time),
|
|
bodyParams,
|
|
bodyBlocks: [receipt],
|
|
});
|
|
}
|
|
|
|
/** Mark seen user logs as disabled (`cln_update` `haveToDisable:b=yes` -> `disabled:b=yes`, 0x95ed29/0x95ed66). */
|
|
export function disableUserLogs(profile: BlkBlock, ids: Iterable<string>): void {
|
|
const logs = findBlock(profile, USERLOGS);
|
|
if (!logs) return;
|
|
const targets = new Set(ids);
|
|
for (const entry of logs.blocks) {
|
|
if (targets.has(entry.name)) setParam(entry, 'disabled', { type: 'bool', value: true });
|
|
}
|
|
}
|
|
|
|
function isPendingPurchaseReceipt(log: BlkBlock): boolean {
|
|
if (intField(log, 'type') !== EULT_BUYENTITLEMENT) return false;
|
|
const disabled = findParam(log, 'disabled')?.value;
|
|
if (disabled?.type === 'bool' && disabled.value) return false;
|
|
const body = findBlock(log, 'body');
|
|
return body !== undefined && findBlock(body, PURCHASE_RECEIPT) !== undefined;
|
|
}
|
|
|
|
/** Keep the newest `keep` user logs and any purchase receipts the client has not seen. */
|
|
export function trimUserLogs(profile: BlkBlock, keep: number): void {
|
|
const logs = findBlock(profile, USERLOGS);
|
|
if (!logs || logs.blocks.length <= keep) return;
|
|
const cutoff = logs.blocks.length - keep;
|
|
logs.blocks = logs.blocks.filter((log, index) => index >= cutoff || isPendingPurchaseReceipt(log));
|
|
}
|