refactor(repo)!: move apps, shared packages, and patch definitions
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.
This commit is contained in:
1 parent
9c813ccf7d
commit
930ea07630
476 files changed
+275
-251
No files matched your search
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* The player's classic items in the profile (implementation notes; ItemStorage, aces.exe
|
||||
* 2.61.0.37 0x8f2de0):
|
||||
*
|
||||
* items{
|
||||
* numTotalAddedItems:i=2
|
||||
* item_0000019b2f3c1a40_2{ block name = the item's uid
|
||||
* id:t="booster_shop_wp_15_10mp" config/items.blk name
|
||||
* type:t="rateBooster"
|
||||
* expiredTimeH:i64=<FILETIME> absolute expiry; missing = never
|
||||
* instCount:i64=1 pieces under this uid
|
||||
* ... per-type fields (wager: numWins numBattles wager;
|
||||
* personalDiscounts: purchasesCount purchasesMaxCount discountsDesc{})
|
||||
* }
|
||||
* }
|
||||
* itemActiveBoosters{ itemUID:t=<uid> ... } active boosters, any number
|
||||
* itemActiveDiscounts{ itemUID:t=<uid> ... } active personal discounts
|
||||
* itemActiveWagers{ itemUID:t=<uid> } the current contract, at most one
|
||||
*
|
||||
* Every field is read by name (0x8f10d0 and the per-type readers), so order does not matter.
|
||||
* New uids follow the client's own pattern item_%016llx_%x (0x8f2c87): a time stamp and the
|
||||
* running count numTotalAddedItems.
|
||||
*/
|
||||
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock, type BlkParam } from '@wto/blk';
|
||||
import type { ServerTime } from './server-time.ts';
|
||||
|
||||
const ITEMS = 'items';
|
||||
const ADDED_COUNT = 'numTotalAddedItems';
|
||||
const ACTIVE_UID = 'itemUID';
|
||||
|
||||
export type ActiveList = 'itemActiveBoosters' | 'itemActiveDiscounts' | 'itemActiveWagers';
|
||||
export const ACTIVE_LISTS: readonly ActiveList[] = ['itemActiveBoosters', 'itemActiveDiscounts', 'itemActiveWagers'];
|
||||
|
||||
export interface OwnedItem {
|
||||
readonly uid: string;
|
||||
readonly id: string;
|
||||
readonly type: string;
|
||||
readonly count: number;
|
||||
readonly expiresAt?: ServerTime;
|
||||
}
|
||||
|
||||
export interface NewItem {
|
||||
readonly id: string;
|
||||
readonly type: string;
|
||||
readonly count: number;
|
||||
readonly expiresAt?: ServerTime;
|
||||
/** Per-type fields written after the common ones. */
|
||||
readonly params?: readonly BlkParam[];
|
||||
readonly blocks?: readonly BlkBlock[];
|
||||
}
|
||||
|
||||
export function ownedItems(profile: BlkBlock): OwnedItem[] {
|
||||
return (findBlock(profile, ITEMS)?.blocks ?? []).flatMap((record) => {
|
||||
const item = itemOf(record);
|
||||
return item ? [item] : [];
|
||||
});
|
||||
}
|
||||
|
||||
export function ownedItem(profile: BlkBlock, uid: string): OwnedItem | undefined {
|
||||
const record = itemRecord(profile, uid);
|
||||
return record && itemOf(record);
|
||||
}
|
||||
|
||||
/** The item's whole block, for per-type fields; undefined when the player does not have it. */
|
||||
export function itemRecord(profile: BlkBlock, uid: string): BlkBlock | undefined {
|
||||
const items = findBlock(profile, ITEMS);
|
||||
return items && findBlock(items, uid);
|
||||
}
|
||||
|
||||
/** Add an item under a new uid; returns the uid. */
|
||||
export function addItem(profile: BlkBlock, item: NewItem, now: ServerTime): string {
|
||||
const items = ensureBlock(profile, ITEMS);
|
||||
const added = intOf(items, ADDED_COUNT) + 1;
|
||||
setParam(items, ADDED_COUNT, { type: 'int', value: added });
|
||||
const uid = `item_${now.toString(16).padStart(16, '0')}_${added.toString(16)}`;
|
||||
items.blocks.push({
|
||||
name: uid,
|
||||
params: [
|
||||
{ name: 'id', value: { type: 'string', value: item.id } },
|
||||
{ name: 'type', value: { type: 'string', value: item.type } },
|
||||
...(item.expiresAt !== undefined ? [expiryParam(item.expiresAt)] : []),
|
||||
countParam(item.count),
|
||||
...(item.params ?? []),
|
||||
],
|
||||
blocks: [...(item.blocks ?? [])],
|
||||
});
|
||||
return uid;
|
||||
}
|
||||
|
||||
export function setItemCount(profile: BlkBlock, uid: string, count: number): void {
|
||||
const record = itemRecord(profile, uid);
|
||||
if (record) setParam(record, 'instCount', countParam(count).value);
|
||||
}
|
||||
|
||||
export function setItemExpiry(profile: BlkBlock, uid: string, expiresAt: ServerTime): void {
|
||||
const record = itemRecord(profile, uid);
|
||||
if (record) setParam(record, 'expiredTimeH', expiryParam(expiresAt).value);
|
||||
}
|
||||
|
||||
/** Remove an item and every reference to it from the active lists. */
|
||||
export function removeItem(profile: BlkBlock, uid: string): void {
|
||||
const items = findBlock(profile, ITEMS);
|
||||
if (items) items.blocks = items.blocks.filter((record) => record.name !== uid);
|
||||
for (const list of ACTIVE_LISTS) deactivate(profile, list, uid);
|
||||
}
|
||||
|
||||
export function activeUids(profile: BlkBlock, list: ActiveList): string[] {
|
||||
return (findBlock(profile, list)?.params ?? []).flatMap((param) =>
|
||||
param.name === ACTIVE_UID && param.value.type === 'string' ? [param.value.value] : []);
|
||||
}
|
||||
|
||||
export function activate(profile: BlkBlock, list: ActiveList, uid: string): void {
|
||||
if (activeUids(profile, list).includes(uid)) return;
|
||||
ensureBlock(profile, list).params.push({ name: ACTIVE_UID, value: { type: 'string', value: uid } });
|
||||
}
|
||||
|
||||
export function deactivate(profile: BlkBlock, list: ActiveList, uid: string): void {
|
||||
const block = findBlock(profile, list);
|
||||
if (block) block.params = block.params.filter((param) => !(param.name === ACTIVE_UID && param.value.type === 'string' && param.value.value === uid));
|
||||
}
|
||||
|
||||
function itemOf(record: BlkBlock): OwnedItem | undefined {
|
||||
const id = stringOf(record, 'id');
|
||||
const type = stringOf(record, 'type');
|
||||
if (id === undefined || type === undefined) return undefined;
|
||||
const expiry = findParam(record, 'expiredTimeH')?.value;
|
||||
const expiresAt = expiry?.type === 'int64' && expiry.value >= 0n ? expiry.value : undefined;
|
||||
return { uid: record.name, id, type, count: intOf(record, 'instCount'), ...(expiresAt !== undefined ? { expiresAt } : {}) };
|
||||
}
|
||||
|
||||
function countParam(count: number): BlkParam {
|
||||
return { name: 'instCount', value: { type: 'int64', value: BigInt(count) } };
|
||||
}
|
||||
|
||||
function expiryParam(expiresAt: ServerTime): BlkParam {
|
||||
return { name: 'expiredTimeH', value: { type: 'int64', value: expiresAt } };
|
||||
}
|
||||
|
||||
function stringOf(block: BlkBlock, name: string): string | undefined {
|
||||
const value = findParam(block, name)?.value;
|
||||
return value?.type === 'string' ? value.value : undefined;
|
||||
}
|
||||
|
||||
function intOf(block: BlkBlock, name: string): number {
|
||||
const value = findParam(block, name)?.value;
|
||||
if (value?.type === 'int64') return Number(value.value);
|
||||
return value?.type === 'int' ? value.value : 0;
|
||||
}
|
||||
Reference in new issue
Block a user