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,95 @@
/**
* Saving, renaming and deleting custom secondary weapon presets (`cln_save_weapon_presets`,
* scripts/unit/unitWeaponryCustomPresets.nut `savePresetInProfile`; implementation notes).
*
* Sent via `charSendBlk` (job type 13 -> full profile update). Request payload:
* <vehicle>{ <presetId>{ name:t="..." Weapon{ preset:t="..." slot:i=... } ... } }
* - Add / copy / edit / rename: `<presetId>` (`custom0`, `custom1`, ...) carries `name:t` and
* zero or more `Weapon{ preset:t, slot:i }` (or infantry `soldier{ index:i, weapon{...} }`)
* blocks -> upserts that single preset under `weaponPresets/<vehicle>`.
* - Delete (`deleteCustomPreset`): `<presetId>{}` is an empty block -> removes that preset.
*/
import { findParam, type BlkBlock } from '@wto/blk';
import { ownsVehicle } from '../profile/profile-hangar.ts';
import {
clearVehicleWeaponPresets,
deleteVehicleWeaponPreset,
upsertVehicleWeaponPreset,
vehicleWeaponPresets,
} from '../profile/profile-weapon-presets.ts';
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
import type { EquipmentCatalogue } from './equipment-catalogue.ts';
/** Client limit (`scripts/weaponry/weaponryPresets.nut` line 7 `MAX_PRESETS_NUM = 20`). */
export const MAX_CUSTOM_PRESETS = 20;
const CUSTOM_PRESET_ID = /^custom\d+$/;
export function saveWeaponPresets(profile: BlkBlock, catalogue: EquipmentCatalogue, request: BlkBlock): RuleOutcome {
if (request.params.length > 0 || request.blocks.length === 0) return refused('BAD_PARAMS');
for (const vehicleBlock of request.blocks) {
const check = validateVehiclePresets(profile, catalogue, vehicleBlock);
if (!check.ok) return check;
}
for (const vehicleBlock of request.blocks) applyVehiclePresets(profile, vehicleBlock);
return ACCEPTED;
}
function validateVehiclePresets(profile: BlkBlock, catalogue: EquipmentCatalogue, vehicleBlock: BlkBlock): RuleOutcome {
if (!vehicleBlock.name || vehicleBlock.params.length > 0 || !catalogue.vehicle(vehicleBlock.name)) {
return refused('BAD_PARAMS');
}
if (!ownsVehicle(profile, vehicleBlock.name) || !catalogue.weapon(vehicleBlock.name, 'custom_presets')) {
return refused('NOT_AVAILABLE');
}
const projected = new Set(vehicleWeaponPresets(profile, vehicleBlock.name).map((preset) => preset.name));
if (vehicleBlock.blocks.length === 0) return ACCEPTED;
for (const presetBlock of vehicleBlock.blocks) {
if (!CUSTOM_PRESET_ID.test(presetBlock.name)) return refused('BAD_PARAMS');
if (isEmptyBlock(presetBlock)) {
projected.delete(presetBlock.name);
continue;
}
if (!isValidPresetPayload(presetBlock)) return refused('BAD_PARAMS');
projected.add(presetBlock.name);
}
return projected.size <= MAX_CUSTOM_PRESETS ? ACCEPTED : refused('NOT_AVAILABLE');
}
function applyVehiclePresets(profile: BlkBlock, vehicleBlock: BlkBlock): void {
if (vehicleBlock.blocks.length === 0) {
clearVehicleWeaponPresets(profile, vehicleBlock.name);
return;
}
for (const presetBlock of vehicleBlock.blocks) {
if (isEmptyBlock(presetBlock)) deleteVehicleWeaponPreset(profile, vehicleBlock.name, presetBlock.name);
else upsertVehicleWeaponPreset(profile, vehicleBlock.name, presetBlock);
}
}
function isEmptyBlock(block: BlkBlock): boolean {
return block.params.length === 0 && block.blocks.length === 0;
}
function isValidPresetPayload(preset: BlkBlock): boolean {
if (preset.params.length !== 1 || findParam(preset, 'name')?.value.type !== 'string') return false;
return preset.blocks.every((sub) => isValidWeaponSlot(sub) || isValidInfantrySoldier(sub));
}
function isValidWeaponSlot(block: BlkBlock): boolean {
return block.name === 'Weapon'
&& block.blocks.length === 0
&& block.params.length === 2
&& findParam(block, 'preset')?.value.type === 'string'
&& findParam(block, 'slot')?.value.type === 'int';
}
function isValidInfantrySoldier(block: BlkBlock): boolean {
if (block.name !== 'soldier' || block.params.length !== 1 || findParam(block, 'index')?.value.type !== 'int') return false;
return block.blocks.every((weapon) =>
weapon.name === 'weapon'
&& weapon.blocks.length === 0
&& weapon.params.length === 2
&& findParam(weapon, 'slot')?.value.type === 'int'
&& findParam(weapon, 'preset')?.value.type === 'string');
}