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:
N0VAN0M4LY committed 2026-11-29 03:20:54 +08:00
1 parent 9c813ccf7d
commit 930ea07630
476 files changed
+275 -251

No files matched your search

@@ -0,0 +1,24 @@
/**
* Player card actions:
* cln_select_title (select_current_title, aces.exe 0x1555b60): name:t; a title has to be an
* earned unlock (titles are unlocks), "" clears it
* cln_save_pilot_appearance (scripts user/profileAppearance.nut): <pilotIcon|background|frame>:t;
* the choices are unlock images the client already filters to the available ones
*/
import type { BlkBlock } from '@wto/blk';
import { APPEARANCE_FIELDS, setAppearance, setChosenTitle, type AppearanceField } from '../profile/profile-appearance.ts';
import { earnedUnlocks } from '../profile/profile-unlocks.ts';
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
export function chooseTitle(profile: BlkBlock, title: string): RuleOutcome {
if (title !== '' && !earnedUnlocks(profile).has(title)) return refused('NOT_AVAILABLE');
setChosenTitle(profile, title);
return ACCEPTED;
}
export function saveAppearance(profile: BlkBlock, choices: readonly { field: string; image: string }[]): RuleOutcome {
const known = choices.filter((choice): choice is { field: AppearanceField; image: string } => (APPEARANCE_FIELDS as readonly string[]).includes(choice.field));
if (known.length === 0) return refused('BAD_PARAMS');
for (const { field, image } of known) setAppearance(profile, field, image);
return ACCEPTED;
}
@@ -0,0 +1,147 @@
/**
* The profile showcase (implementation notes; scripts user/profileShowcase.nut and
* user/showcase/*.nut).
*
* cln_save_profile_showcase carries showcaseType:t and that type's choices under the names its
* getSaveData uses; the client reads them back (cln_get_showcases, the terse info's showcase
* block) under other names. Per type, request -> stored field:
* favorite_mode favoriteMode -> mode
* battle_hardened battleHardenedMode -> h_mode
* favorite_unit favoriteUnit, favoriteUnitDifficulty -> unit, difficulty
* unit_collector unitCollectorFavorites (repeated) -> units
* medalist medals (repeated) -> medals
* achievement_hunter achievements (repeated) -> achievements
* ace_of_spades acedUnitsFilter{ country_<c>:t=<unit type> ... }, kept as it is; the
* answer turns it into aced_units{ <type>{ <c>:i=<count> } } for the chosen
* pairs and aced_units_hidden for the rest, counting the vehicles a crew
* is an ace on (spec 2)
* atomic_ace, peacemaker, tank_footballer nothing
*/
import type { BlkBlock, BlkParam } from '@wto/blk';
import { allCrews } from '../profile/profile-crews.ts';
import { trainedPairs } from '../profile/profile-crew-skills.ts';
import { currentShowcase, savedShowcases, writeShowcase } from '../profile/profile-showcase.ts';
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
import type { TechTree } from '../research/tech-tree.ts';
import type { VehicleType } from '../research/vehicle-types.ts';
const ACE_OF_SPADES = 'ace_of_spades';
const ACED_FILTER = 'acedUnitsFilter';
const ACE = 2;
/** Request parameter -> stored field, per showcase type. */
const STORED_FIELDS: Readonly<Record<string, Readonly<Record<string, string>>>> = {
favorite_mode: { favoriteMode: 'mode' },
battle_hardened: { battleHardenedMode: 'h_mode' },
favorite_unit: { favoriteUnit: 'unit', favoriteUnitDifficulty: 'difficulty' },
unit_collector: { unitCollectorFavorites: 'units' },
medalist: { medals: 'medals' },
achievement_hunter: { achievements: 'achievements' },
[ACE_OF_SPADES]: {},
atomic_ace: {},
peacemaker: {},
tank_footballer: {},
};
/**
* Fields every answer carries for a type even before the player saved it: the client keeps each
* type's block as a table and assigns some fields with `=`, which fails on a missing slot
* (favorite_unit's saveUnit does `showcase.unit = <unit>`; the unit picker broke on it).
*/
const DEFAULT_FIELDS: Readonly<Record<string, readonly BlkParam[]>> = {
favorite_unit: [
{ name: 'unit', value: { type: 'string', value: '' } },
{ name: 'difficulty', value: { type: 'string', value: 'arcade' } },
],
};
/** The client's unit type names (scripts unit/unitTypesList.nut). */
const SHOWCASE_UNIT_TYPE: Partial<Record<VehicleType, string>> = {
Aircraft: 'aircraft', Tank: 'tank', Ship: 'ship', Helicopter: 'helicopter', Boat: 'boat',
};
export function saveShowcase(profile: BlkBlock, request: BlkBlock): RuleOutcome {
const typeParam = request.params.find((param) => param.name === 'showcaseType')?.value;
const type = typeParam?.type === 'string' ? typeParam.value : undefined;
const fields = type === undefined ? undefined : STORED_FIELDS[type];
if (type === undefined || fields === undefined) return refused('BAD_PARAMS');
const stored = request.params.flatMap((param): BlkParam[] => {
const field = fields[param.name];
return field ? [{ name: field, value: param.value }] : [];
});
writeShowcase(profile, type, stored);
if (type === ACE_OF_SPADES) {
const filter = request.blocks.find((block) => block.name === ACED_FILTER);
const saved = savedShowcases(profile).find((block) => block.name === ACE_OF_SPADES);
// An empty filter is still a saved choice (show nothing), unlike no filter at all.
if (saved) saved.blocks = [filter ? { ...filter, blocks: [] } : { name: ACED_FILTER, params: [], blocks: [] }];
}
return ACCEPTED;
}
/** The cln_get_showcases answer: current:t and one block per showcase type, saved or not. */
export function showcasesAnswer(profile: BlkBlock, techTree: TechTree): BlkBlock {
return {
name: '',
params: [{ name: 'current', value: { type: 'string', value: currentShowcase(profile) } }],
blocks: Object.keys(STORED_FIELDS).map((type) => clientView(profile, techTree, type)),
};
}
/** The current showcase for cln_get_users_terse_info: its type and its block named "showcase". */
export function currentShowcaseView(profile: BlkBlock, techTree: TechTree): { type: string; showcase: BlkBlock } {
const type = currentShowcase(profile);
return { type, showcase: { ...clientView(profile, techTree, type), name: 'showcase' } };
}
function clientView(profile: BlkBlock, techTree: TechTree, type: string): BlkBlock {
const saved = savedShowcases(profile).find((block) => block.name === type);
if (type !== ACE_OF_SPADES) {
const params = saved?.params ?? [];
const defaults = (DEFAULT_FIELDS[type] ?? []).filter((field) => !params.some((param) => param.name === field.name));
return { name: type, params: [...defaults, ...params], blocks: [] };
}
// Before the player saves a filter, every category with an ace is shown.
const filter = saved?.blocks.find((block) => block.name === ACED_FILTER);
const chosen = filter && new Set(filter.params
.flatMap((param) => param.value.type === 'string' ? [`${param.value.value}/${param.name.replace(/^country_/, '')}`] : []));
const shown = new Map<string, Map<string, number>>();
const hidden = new Map<string, Map<string, number>>();
for (const [key, count] of acedVehicleCounts(profile, techTree)) {
const [unitType, country] = key.split('/') as [string, string];
const target = !chosen || chosen.has(key) ? shown : hidden;
let byCountry = target.get(unitType);
if (!byCountry) target.set(unitType, byCountry = new Map());
byCountry.set(country, count);
}
return { name: type, params: [], blocks: [countBlock('aced_units', shown), countBlock('aced_units_hidden', hidden)] };
}
/** "<unit type>/<country without the country_ prefix>" -> vehicles a crew is an ace on. */
function acedVehicleCounts(profile: BlkBlock, techTree: TechTree): Map<string, number> {
const aced = new Set<string>();
for (const crew of allCrews(profile)) {
for (const pair of trainedPairs(crew)) if (pair.spec >= ACE) aced.add(pair.vehicle);
}
const counts = new Map<string, number>();
for (const name of aced) {
const vehicle = techTree.vehicle(name);
const type = vehicle && SHOWCASE_UNIT_TYPE[vehicle.type];
if (!vehicle || !type) continue;
const key = `${type}/${vehicle.country.replace(/^country_/, '')}`;
counts.set(key, (counts.get(key) ?? 0) + 1);
}
return counts;
}
function countBlock(name: string, counts: Map<string, Map<string, number>>): BlkBlock {
return {
name,
params: [],
blocks: [...counts].map(([type, byCountry]) => ({
name: type,
params: [...byCountry].map(([country, count]): BlkParam => ({ name: country, value: { type: 'int', value: count } })),
blocks: [],
})),
};
}