Files
WT-Offline/scripts/build-game-copy.ts
T
N0VAN0M4LY e0a344708d feat(ground-ai): load baked navigation packs in battle
Statically link upstream Detour into wto_ws.dll with a navigation engine
(native/wto-nav) that loads one .wtonav pack per battle, reads the level
file's eVER fingerprint and answers path queries through a cost filter
that multiplies chokepoint polygons. Start and goal points that do not
sit on the ground are retried over the mesh's height range.

The ground AI script talks to it through call_mission_action("wtoNav")
with load_map, unload_map, find_path and get_stats. Requests are string
parameters; replies use the DataBlock setters local_mp_awards already
resolves, with coordinates as centimetre ints, so no new native site is
needed. The local server writes the battle level into customBots
wtoLevel, and the build writes the pack folder as nav.dir in wto_ws.cfg
(build-game-copy.ts --map-nav).

The first load_map of a battle decides it once: loaded, fallback to the
script's own navigation, or refused when navEngine.allowFallback is off,
in which case bots do not plan or drive. A fingerprint mismatch is
logged and the pack is still used. The script proves the round trip
with one path per team at battle start and logs query statistics.

Add the navEngine, navCostsTracked and navCostsWheeled tuning sections
through the server reader, generated daScript constants and the
launcher's bot tuning page in both languages.

Verified with root and launcher type checks, MSVC builds without
warnings in project code, check-patches 14/14 on 2.61.0.58 and
2.61.0.60, native module resolution 14/14 on 2.61.0.37, .58, .60 and
.64, a scratch game copy build packing 29 ground AI modules, and an
offline run of the engine: all three maps load with matching
fingerprints and every spawn-to-capture path on every tier succeeds.
2026-12-05 16:39:26 +08:00

209 lines
10 KiB
TypeScript

/**
* Development script: build the game copy from the stock files of a game folder.
*
* node scripts/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>]
* [--map-nav <folder with <level>.wtonav packs>]
* [--skip-unavailable] [--verbose]
*
* Writes <out>/char.vromfs.bin, <out>/aces.vromfs.bin, <out>/gui.vromfs.bin, <out>/win64/aces.exe
* and the network hook library the patched executable loads (<out>/win64/wto_ws.dll from --native,
* built by native/wto-net/build.ps1, and its settings wto_ws.cfg). The stock folder is only read.
* --data is the folder the local server will run with: the store packs it sells there (its tuning
* with that folder's overrides) get bundle GUIDs in gui.blk. --decal-cache names the cache/content
* folder of the player's online installation; it is copied to <out>/cache/content, otherwise
* char.vromfs.bin gets the placeholder decal index. --map-nav names the folder of the baked
* ground AI navigation packs (tools/navgen); wto_ws.dll loads them from there, nothing is copied.
* When a patch is unavailable nothing is written, unless --skip-unavailable is given and none of
* the unavailable patches is essential (the patcher's essential-features.ts).
* The patch set (exe, GUI and native definitions) and the hook library default to this
* repository's patches/ and build/native. The launcher runs the same build at every launch, with the port the player chose.
*/
import { existsSync, readFileSync } from 'node:fs';
import { join, resolve } 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 { 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>] [--ground-ai <folder>] '
+ '[--mods-dir <folder> --mod <id>...] [--decal-cache <folder>] [--map-nav <folder>] [--skip-unavailable] [--verbose]';
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' },
out: { type: 'string' },
port: { type: 'string' },
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' },
'map-nav': { 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;
}
assertWritableCopy(values.game, values.out);
const decalCache = values['decal-cache'];
const decalCacheProblem = decalCache === undefined ? undefined : playerDecalCacheProblem(decalCache);
if (decalCacheProblem) {
console.error(`--decal-cache: ${decalCacheProblem}; nothing was written`);
return 1;
}
const hookLibraryPath = join(values.native, NETWORK_HOOK_LIBRARY);
if (!existsSync(hookLibraryPath)) {
console.error(`${hookLibraryPath} not found (build it with native/wto-net/build.ps1); nothing was written`);
return 1;
}
const mapNav = values['map-nav'] === undefined ? undefined : resolve(values['map-nav']);
if (mapNav !== undefined && !existsSync(mapNav)) {
console.error(`--map-nav: ${mapNav} not found; nothing was written`);
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,
patches: values.patches,
networkHookLibrary: readFileSync(hookLibraryPath),
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 },
...(mapNav !== undefined ? { mapNavFolder: mapNav } : {}),
});
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`);
return 1;
}
if (failures.length && !values['skip-unavailable']) {
console.error('some patches are unavailable; nothing was written (--skip-unavailable writes the copy without them)');
return 1;
}
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;
}
function report(build: GameCopyBuild, verbose: boolean): void {
const { endpoint, charPack } = build;
const target = `${endpoint.host}:${endpoint.port}`;
console.log(`exe: ${build.exePatches.applied.length} patch(es) ready, ${build.exePatches.failures.length} unavailable`);
for (const write of build.exePatches.applied) console.log(` ready ${write.patchId} at 0x${write.rva.toString(16)}`);
reportFailures(build.exePatches.failures);
console.log(`network.blk: ${charPack.network.addresses.length} address(es) now point to ${target}; ` +
`environments configured: ${charPack.network.environments.join(', ')}`);
if (verbose) {
for (const change of charPack.network.addresses) console.log(` ${change.path}: ${change.before} -> ${change.after}`);
}
console.log(`game_settings.blk: features on for every player: ${charPack.features.join(', ') || '(already on)'}`);
console.log(`shop.blk: ${charPack.revealedVehicles} hidden vehicles shown in the tech tree`);
if (charPack.placeholderDecals !== undefined) console.log(`dldata: placeholder textures for ${charPack.placeholderDecals} decals`);
console.log(`gui.blk: ${build.bundleGuids} offline vehicle pack bundle GUID(s) registered`);
console.log(`settings.blk: ${build.engineAddresses.length} address(es) now point to ${target}`);
for (const change of build.engineAddresses) console.log(` ${change.path}: ${change.before} -> ${change.after}`);
console.log(`gui.vromfs.bin: ${build.guiPatches.applied.length} GUI patch(es) ready, ${build.guiPatches.failures.length} unavailable`);
if (verbose) for (const id of build.guiPatches.applied) console.log(` ready ${id}`);
reportFailures(build.guiPatches.failures);
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) packed in ${build.gamePack.archiveFolder}`);
}
}
function reportFailures(failures: readonly PatchFailure[]): void {
for (const failure of failures) console.log(` FAILED ${failure.patchId}: ${failure.reason}`);
const features = [...new Set(failures.flatMap((failure) => failure.features))].sort();
if (failures.length) console.log(` features affected: ${features.join(', ') || 'none recorded'}`);
}
process.exitCode = main();