feat(patcher,server): wire ground AI tuning, bot weights, and pack build

Add ground-ai.jsonc tuning validation, realistic tank class weights for
customBots pools, on-demand game.vromfs.bin / ailist.blk injection in
@wto/patcher, and launcher/CLI build integration while keeping all
ground AI layers disabled by default in shipped configuration.
This commit is contained in:
N0VAN0M4LY committed 2026-12-03 12:07:30 +08:00
1 parent 18637cf1ff
commit 4ac3484f56
17 files changed
+836 -75

No files matched your search

+70 -9
View File
@@ -24,25 +24,43 @@ import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseArgs } from 'node:util';
import type { PatchFailure } from '@wto/exepatch';
import { discoverMods, touchedClientPacks, type DiscoveredMod, type ModdableClientPack } from '@wto/mods';
import {
assertWritableCopy,
buildGameCopy,
computeModsBuildFingerprint,
copyPlayerDecalCache,
CORE_BUILD_PACKS,
GAME_PACK_FILE,
isGroundAiActive,
NETWORK_HOOK_LIBRARY,
playerDecalCacheProblem,
prepareOptionalStockPacks,
readPlayerDecalIndexFiles,
readStockGameFiles,
syncExternalModFiles,
writeGameCopy,
type GameCopyBuild,
} from '@wto/patcher';
import { multiVehiclePackIds } from '@wto/server';
import { loadGroundAiTuning, multiVehiclePackIds } from '@wto/server';
const REPOSITORY = fileURLToPath(new URL('..', import.meta.url));
const USAGE = 'usage: build-game-copy.ts --game <stock game folder> --out <game copy folder> --port <n> --data <local server data folder> '
+ '[--patches <patch set>] [--native <folder with wto_ws.dll>] [--decal-cache <folder>] '
+ '[--skip-unavailable] [--verbose]';
+ '[--patches <patch set>] [--native <folder with wto_ws.dll>] [--ground-ai <folder>] '
+ '[--mods-dir <folder> --mod <id>...] [--decal-cache <folder>] [--skip-unavailable] [--verbose]';
function main(): number {
function resolveCliMods(modsDir: string | undefined, modIds: readonly string[] | undefined): DiscoveredMod[] {
if (!modsDir || !modIds || modIds.length === 0) return [];
const discovered = discoverMods(modsDir);
const byId = new Map(discovered.mods.map((mod) => [mod.manifest.id, mod]));
return modIds.map((id) => {
const mod = byId.get(id);
if (!mod) throw new Error(`enabled mod "${id}" was not found in ${modsDir}`);
return mod;
});
}
function parseCliOptions() {
const { values } = parseArgs({
options: {
game: { type: 'string' },
@@ -51,11 +69,19 @@ function main(): number {
data: { type: 'string' },
patches: { type: 'string', default: join(REPOSITORY, 'patches') },
native: { type: 'string', default: join(REPOSITORY, 'build', 'native') },
'ground-ai': { type: 'string', default: join(REPOSITORY, 'game-ai', 'ground') },
'mods-dir': { type: 'string' },
mod: { type: 'string', multiple: true },
'decal-cache': { type: 'string' },
'skip-unavailable': { type: 'boolean', default: false },
verbose: { type: 'boolean', default: false },
},
});
return values;
}
function main(): number {
const values = parseCliOptions();
if (!values.game || !values.out || !values.port || !values.data) {
console.error(USAGE);
return 2;
@@ -73,18 +99,43 @@ function main(): number {
return 1;
}
const port = Number(values.port);
const enabledMods = resolveCliMods(values['mods-dir'], values.mod);
const groundAiConfig = loadGroundAiTuning(values.data, (line) => console.log(line), enabledMods);
const touchedSet = new Set<ModdableClientPack>(
touchedClientPacks(enabledMods).filter((pack) => !CORE_BUILD_PACKS.has(pack)),
);
if (isGroundAiActive(groundAiConfig)) touchedSet.add(GAME_PACK_FILE);
const optionalPacksInBuild = [...touchedSet];
const extraStockPacks = optionalPacksInBuild.length > 0
? prepareOptionalStockPacks(values.out, values.game, optionalPacksInBuild)
: undefined;
const decalIndexFiles = decalCache === undefined ? undefined : readPlayerDecalIndexFiles(decalCache);
const build = buildGameCopy({
stock: readStockGameFiles(values.game),
port: Number(values.port),
port,
patches: values.patches,
networkHookLibrary: readFileSync(hookLibraryPath),
multiVehiclePackIds: multiVehiclePackIds(values.data, (line) => console.log(line)),
multiVehiclePackIds: multiVehiclePackIds(values.data, (line) => console.log(line), enabledMods),
placeholderDecals: decalCache === undefined,
...(decalIndexFiles ? { decalIndexFiles } : {}),
...(enabledMods.length > 0 ? { mods: enabledMods } : {}),
...(extraStockPacks ? { extraStockPacks } : {}),
groundAi: { scriptsFolder: values['ground-ai'], config: groundAiConfig },
});
report(build, values.verbose);
return finishCliWrite(values, build, enabledMods, optionalPacksInBuild, groundAiConfig, port);
}
function finishCliWrite(
values: ReturnType<typeof parseCliOptions>,
build: GameCopyBuild,
enabledMods: readonly DiscoveredMod[],
optionalPacksInBuild: readonly ModdableClientPack[],
groundAiConfig: ReturnType<typeof loadGroundAiTuning>,
port: number,
): number {
const failures = [...build.exePatches.failures, ...build.guiPatches.failures, ...build.nativeModules.failures];
if (build.blocking.length) {
console.error(`essential patch(es) unavailable: ${build.blocking.map((failure) => failure.patchId).join(', ')}; nothing was written`);
@@ -95,9 +146,16 @@ function main(): number {
return 1;
}
for (const path of writeGameCopy(values.out, build.files)) console.log(`wrote ${path}`);
if (decalCache !== undefined) {
const copied = copyPlayerDecalCache(decalCache, values.out);
for (const path of writeGameCopy(values.out!, build.files)) console.log(`wrote ${path}`);
const fingerprint = computeModsBuildFingerprint(
enabledMods,
port,
`${values.patches}|groundAi=${JSON.stringify(groundAiConfig)}`,
);
const deploy = syncExternalModFiles(values.out!, values.game!, enabledMods, optionalPacksInBuild, fingerprint);
for (const restored of deploy.restoredOptionalPacks) console.log(`restored stock ${restored}`);
if (values['decal-cache'] !== undefined) {
const copied = copyPlayerDecalCache(values['decal-cache'], values.out!);
console.log(`copied the player's web cache to ${copied.copiedTo} (decal indexes: ${copied.decalIndexes.join(', ')})`);
}
return 0;
@@ -126,6 +184,9 @@ function report(build: GameCopyBuild, verbose: boolean): void {
console.log(`wto_ws.cfg: ${build.nativeModules.available.length} native module(s) ready, ${build.nativeModules.failures.length} unavailable`);
if (verbose) for (const module of build.nativeModules.available) console.log(` ready ${module}`);
reportFailures(build.nativeModules.failures);
if (build.gamePack) {
console.log(`${GAME_PACK_FILE}: ${build.gamePack.modules.length} ground AI module(s) ready in ${build.gamePack.archiveFolder}`);
}
}
function reportFailures(failures: readonly PatchFailure[]): void {
+1
View File
@@ -71,6 +71,7 @@ async function stageInstaller(stage: string, manifest: LauncherManifest): Promis
await cp(join(repository, 'LICENSE'), join(resources, 'LICENSE-WTOffline'));
await cp(join(native, 'wto_ws.dll'), join(resources, 'native', 'wto_ws.dll'));
await cp(join(repository, 'mod-dev-docs', 'templates'), join(resources, 'mod-templates'), { recursive: true });
await cp(join(repository, 'game-ai', 'ground'), join(resources, 'game-ai', 'ground'), { recursive: true });
for (const folder of ['exe', 'gui', 'native', 'versions']) {
await cp(join(repository, 'patches', folder), join(resources, 'patches', folder), { recursive: true });
}