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,163 @@
|
||||
/**
|
||||
* Dataset: every vehicle's modifications, ammunition, weapon presets and spare, with their
|
||||
* research and purchase facts.
|
||||
*
|
||||
* char.vromfs.bin config/wpcost.blk, per vehicle:
|
||||
* needBuyToOpenNextInTier<N>:i researched modifications of tier N needed to open tier N+1
|
||||
* modifications{ <name>{ tier:i reqExp:i value:i costGold:i openCostGold:i
|
||||
* reqModification:t (repeated) maxCount:i ammoCount:i ... } }
|
||||
* Ammunition and expendables are modifications too (tier 0, maxCount, ammoCount).
|
||||
* weapons{ <preset>{ value:i costGold:i maxCount:i reqModification:t ... } }
|
||||
* Paid presets (bombs, rockets) are bought by the piece, up to maxCount; the rest are free,
|
||||
* custom_presets (the custom preset slots) among them.
|
||||
* spare{ value:i costGold:i }
|
||||
*
|
||||
* Only what the file says is recorded; what it means is the rules layer's (modifications/).
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { findBlock } from '@wto/blk';
|
||||
import { boolField, numberField, stringField, stringList } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
const VEHICLE_ECONOMY = 'config/wpcost.blk';
|
||||
const MODIFICATIONS_CONFIG = 'config/modifications.blk';
|
||||
/** wpcost.blk has needBuyToOpenNextInTier1..4; the modification tree has tiers 1..5 at most. */
|
||||
const TIER_REQUIREMENT_COUNT = 4;
|
||||
|
||||
export interface ModificationFacts {
|
||||
readonly name: string;
|
||||
readonly tier: number;
|
||||
/** reqExp; 0 when the modification is not researched (ammunition, expendables, premium). */
|
||||
readonly researchPoints: number;
|
||||
readonly silverLions: number;
|
||||
readonly goldenEagles: number;
|
||||
/** openCostGold: golden eagles to get it without the research (scaled by progress, implementation notes). */
|
||||
readonly openGoldenEagles: number;
|
||||
/** reqModification, repeated: modifications that must be bought first. */
|
||||
readonly requires: readonly string[];
|
||||
/** maxCount; 0 when the modification is not counted (bought once). */
|
||||
readonly maxCount: number;
|
||||
/** ammoCount present: an ammunition belt or shell type. */
|
||||
readonly ammunition: boolean;
|
||||
/** Initial enabled state when acquired (`turn_it_off` / `isEnabledByDefaultForAddMrank`). */
|
||||
readonly defaultEnabled: boolean;
|
||||
/** Non-bullet `group` name when modifications in the same group are mutually exclusive. */
|
||||
readonly exclusiveGroup?: string;
|
||||
}
|
||||
|
||||
export interface WeaponFacts {
|
||||
readonly name: string;
|
||||
/** value: silver lions per piece. */
|
||||
readonly silverLions: number;
|
||||
readonly goldenEagles: number;
|
||||
/** reqModification (direct + inherited from `sum_weapons` containers, initUnitWeapons.nut). */
|
||||
readonly requires: readonly string[];
|
||||
/** maxCount; 0 when the preset is not bought by the piece. */
|
||||
readonly maxCount: number;
|
||||
}
|
||||
|
||||
export interface VehicleEquipment {
|
||||
readonly vehicle: string;
|
||||
/** needBuyToOpenNextInTier1..4 (index 0 = tier 1). */
|
||||
readonly tierRequirements: readonly number[];
|
||||
readonly modifications: readonly ModificationFacts[];
|
||||
readonly weapons: readonly WeaponFacts[];
|
||||
/** spare; absent when the vehicle has no spare price. */
|
||||
readonly spare?: { readonly silverLions: number; readonly goldenEagles: number };
|
||||
}
|
||||
|
||||
interface GlobalModificationMeta {
|
||||
readonly turnOffByDefault: boolean;
|
||||
readonly bulletGroup: boolean;
|
||||
readonly group?: string;
|
||||
}
|
||||
|
||||
export const vehicleEquipment: Dataset<readonly VehicleEquipment[]> = {
|
||||
id: 'vehicle-equipment',
|
||||
version: 3,
|
||||
extract: (source) => {
|
||||
const modMeta = readGlobalModificationMeta(source.readBlk('char.vromfs.bin', MODIFICATIONS_CONFIG));
|
||||
return source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map((vehicle) => equipmentOf(vehicle, modMeta));
|
||||
},
|
||||
};
|
||||
|
||||
function readGlobalModificationMeta(configRoot: BlkBlock): ReadonlyMap<string, GlobalModificationMeta> {
|
||||
const modsBlock = findBlock(configRoot, 'modifications');
|
||||
const map = new Map<string, GlobalModificationMeta>();
|
||||
for (const entry of modsBlock?.blocks ?? []) {
|
||||
const effects = findBlock(entry, 'effects');
|
||||
const bulletGroup = Boolean(
|
||||
effects?.params.some((p) => p.name === 'bulletMod' || p.name === 'additiveBulletMod')
|
||||
|| effects?.blocks.some((b) => b.name === 'bulletMod' || b.name === 'additiveBulletMod'),
|
||||
);
|
||||
const group = stringField(entry, 'group');
|
||||
map.set(entry.name, {
|
||||
turnOffByDefault: boolField(entry, 'turn_it_off') === true,
|
||||
bulletGroup,
|
||||
...(group !== undefined ? { group } : {}),
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function equipmentOf(vehicle: BlkBlock, modMeta: ReadonlyMap<string, GlobalModificationMeta>): VehicleEquipment {
|
||||
const tierRequirements: number[] = [];
|
||||
for (let tier = 1; tier <= TIER_REQUIREMENT_COUNT; tier++) tierRequirements.push(numberField(vehicle, `needBuyToOpenNextInTier${tier}`) ?? 0);
|
||||
const spare = findBlock(vehicle, 'spare');
|
||||
return {
|
||||
vehicle: vehicle.name,
|
||||
tierRequirements,
|
||||
modifications: (findBlock(vehicle, 'modifications')?.blocks ?? []).map((mod) => modificationOf(mod, modMeta.get(mod.name))),
|
||||
weapons: weaponsOf(findBlock(vehicle, 'weapons')),
|
||||
...(spare ? { spare: { silverLions: numberField(spare, 'value') ?? 0, goldenEagles: numberField(spare, 'costGold') ?? 0 } } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function modificationOf(modification: BlkBlock, meta: GlobalModificationMeta | undefined): ModificationFacts {
|
||||
const ammunition = numberField(modification, 'ammoCount') !== undefined;
|
||||
const defaultEnabled = !(meta?.turnOffByDefault ?? false) && (boolField(modification, 'isEnabledByDefaultForAddMrank') ?? true);
|
||||
const group = stringField(modification, 'group') ?? meta?.group;
|
||||
const exclusiveGroup = !ammunition && !(meta?.bulletGroup ?? false) ? group : undefined;
|
||||
return {
|
||||
name: modification.name,
|
||||
tier: numberField(modification, 'tier') ?? 0,
|
||||
researchPoints: numberField(modification, 'reqExp') ?? 0,
|
||||
silverLions: numberField(modification, 'value') ?? 0,
|
||||
goldenEagles: numberField(modification, 'costGold') ?? 0,
|
||||
openGoldenEagles: numberField(modification, 'openCostGold') ?? 0,
|
||||
requires: stringList(modification, 'reqModification'),
|
||||
maxCount: numberField(modification, 'maxCount') ?? 0,
|
||||
ammunition,
|
||||
defaultEnabled,
|
||||
...(exclusiveGroup !== undefined ? { exclusiveGroup } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function weaponsOf(weaponsBlock: BlkBlock | undefined): WeaponFacts[] {
|
||||
if (!weaponsBlock) return [];
|
||||
const containerRequires = new Map<string, readonly string[]>();
|
||||
for (const entry of weaponsBlock.blocks) {
|
||||
if (boolField(entry, 'isWeaponForCustomSlot') === true) {
|
||||
containerRequires.set(entry.name, stringList(entry, 'reqModification'));
|
||||
}
|
||||
}
|
||||
return weaponsBlock.blocks
|
||||
.filter((entry) => boolField(entry, 'isWeaponForCustomSlot') !== true)
|
||||
.map((entry) => weaponOf(entry, containerRequires));
|
||||
}
|
||||
|
||||
function weaponOf(entry: BlkBlock, containerRequires: ReadonlyMap<string, readonly string[]>): WeaponFacts {
|
||||
const requires = [...stringList(entry, 'reqModification')];
|
||||
for (const param of findBlock(entry, 'sum_weapons')?.params ?? []) {
|
||||
for (const req of containerRequires.get(param.name) ?? []) {
|
||||
if (!requires.includes(req)) requires.push(req);
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: entry.name,
|
||||
silverLions: numberField(entry, 'value') ?? 0,
|
||||
goldenEagles: numberField(entry, 'costGold') ?? 0,
|
||||
requires,
|
||||
maxCount: numberField(entry, 'maxCount') ?? 0,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user