Locate what the native LocalMP modules need from data

The LocalMP modules of wto_ws.dll scanned for 42 functions at start-up and
used about a hundred structure offsets compiled in as constants, so a game
update could move a field without anything noticing. Their needs are now
definitions under patches/native/<module>.jsonc, resolved by the patcher when
it builds the game copy, the same way exe patches are located:

- Locate methods: "string_ref" finds code by the string it loads (optionally
  with a pattern around the lea, to read the field a scoreboard row stores
  under that name), and "within" searches a short pattern inside the function
  of a site located before it (function ranges from the exception directory).
- Each module lists its sites (functions, globals, call targets and the
  instructions whose captures give structure offsets), its features and the
  modules it requires. A module whose sites are not all found is reported
  like an unavailable patch, with the modules depending on it.
- The resolved values go into wto_ws.cfg as native.<site>[.<capture>] lines,
  with the executable's PE time stamp and image size so the library can
  refuse values resolved for another build.
- Version records include the native module variants and values.
- Patch-set folders: the patcher, the scripts and the launcher take the root
  of a patch set (exe, gui, native, versions) instead of separate folders.
- New feature tags K-Chat and radio and K-Nuclear bomb in both language packs.

The library still scans by itself; reading these values is the next change.

Checked: root and launcher type checks; all 10 modules resolve on 2.61.0.37,
where the 239 values equal what the drafting tool read with a disassembler, and
on 2.61.0.43, where every structure offset is unchanged except the GameSaveData
HUD event queue (0xae8 -> 0xb18); build-game-copy from 2.61.0.37 into a
temporary folder writes the values into wto_ws.cfg.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 12:15:30 +08:00
1 parent fdf859c4c9
commit ddec5c59c0
36 files changed
+3318 -91

No files matched your search

+10 -9
View File
@@ -3,7 +3,7 @@
*
* node scripts/build-game-copy.ts --game <stock game folder> --out <game copy folder> --port <n>
* --data <local server data folder>
* [--patches <exe patches>] [--gui-patches <GUI patches>]
* [--patches <patch set>]
* [--native <folder with wto_ws.dll>] [--decal-cache <folder>]
* [--skip-unavailable] [--verbose]
*
@@ -16,8 +16,8 @@
* char.vromfs.bin gets the placeholder decal index.
* 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 folders and the hook library default to this repository's patches/exe, patches/gui
* and build/native. The launcher runs the same build at every launch, with the port the player chose.
* 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 } from 'node:path';
@@ -38,7 +38,7 @@ import { 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 <exe patches>] [--gui-patches <GUI patches>] [--native <folder with wto_ws.dll>] [--decal-cache <folder>] '
+ '[--patches <patch set>] [--native <folder with wto_ws.dll>] [--decal-cache <folder>] '
+ '[--skip-unavailable] [--verbose]';
function main(): number {
@@ -48,8 +48,7 @@ function main(): number {
out: { type: 'string' },
port: { type: 'string' },
data: { type: 'string' },
patches: { type: 'string', default: join(REPOSITORY, 'patches', 'exe') },
'gui-patches': { type: 'string', default: join(REPOSITORY, 'patches', 'gui') },
patches: { type: 'string', default: join(REPOSITORY, 'patches') },
native: { type: 'string', default: join(REPOSITORY, 'build', 'native') },
'decal-cache': { type: 'string' },
'skip-unavailable': { type: 'boolean', default: false },
@@ -76,15 +75,14 @@ function main(): number {
const build = buildGameCopy({
stock: readStockGameFiles(values.game),
port: Number(values.port),
exePatches: values.patches,
guiPatches: values['gui-patches'],
patches: values.patches,
networkHookLibrary: readFileSync(hookLibraryPath),
multiVehiclePackIds: multiVehiclePackIds(values.data, (line) => console.log(line)),
placeholderDecals: decalCache === undefined,
});
report(build, values.verbose);
const failures = [...build.exePatches.failures, ...build.guiPatches.failures];
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;
@@ -122,6 +120,9 @@ function report(build: GameCopyBuild, verbose: boolean): void {
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);
}
function reportFailures(failures: readonly PatchFailure[]): void {
+38 -24
View File
@@ -1,31 +1,36 @@
/**
* Development script: check every exe and GUI patch against one game build and write its version
* record (packages/patcher/src/version-record.ts).
* Development script: check every exe patch, GUI patch and native module of the patch set against
* one game build and write its version record (packages/patcher/src/version-record.ts).
*
* node scripts/record-game-version.ts --game <stock game folder> [--out <records folder>]
* [--patches <exe patches>] [--gui-patches <GUI patches>]
* node scripts/record-game-version.ts --game <stock game folder> [--patches <patch set>]
*
* The game folder is only read. The record goes to <out>/<game version>.jsonc (default
* patches/versions). Nothing is written when an essential patch is unavailable
* (essential-features.ts), since such a build cannot be adapted by a record alone.
* The game folder is only read. The record goes to <patch set>/versions/<game version>.jsonc; the
* patch set defaults to this repository's patches/. Nothing is written when an essential patch is
* unavailable (essential-features.ts), since such a build cannot be adapted by a record alone.
*/
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseArgs } from 'node:util';
import { loadPatches } from '@wto/exepatch';
import { blockingFailures, checkGameBuild, formatVersionRecord, GAME_FILES, loadGuiPatches, recordFileName } from '@wto/patcher';
import {
blockingFailures,
checkGameBuild,
formatVersionRecord,
GAME_FILES,
patchFeatures,
patchSetFolders,
recordFileName,
type VersionRecord,
} from '@wto/patcher';
const REPOSITORY = fileURLToPath(new URL('..', import.meta.url));
const USAGE = 'usage: record-game-version.ts --game <stock game folder> [--out <records folder>] [--patches <exe patches>] [--gui-patches <GUI patches>]';
const USAGE = 'usage: record-game-version.ts --game <stock game folder> [--patches <patch set>]';
function main(): number {
const { values } = parseArgs({
options: {
game: { type: 'string' },
out: { type: 'string', default: join(REPOSITORY, 'patches', 'versions') },
patches: { type: 'string', default: join(REPOSITORY, 'patches', 'exe') },
'gui-patches': { type: 'string', default: join(REPOSITORY, 'patches', 'gui') },
patches: { type: 'string', default: join(REPOSITORY, 'patches') },
},
});
if (!values.game) {
@@ -35,29 +40,38 @@ function main(): number {
const record = checkGameBuild({
executable: readFileSync(join(values.game, GAME_FILES.executable)),
guiPack: readFileSync(join(values.game, GAME_FILES.guiPack)),
exePatches: values.patches,
guiPatches: values['gui-patches'],
patches: values.patches,
});
const exeCount = Object.keys(record.exePatches).length;
const guiCount = Object.keys(record.guiPatches).length;
console.log(`${record.gameVersion}: ${exeCount} exe patch(es) and ${guiCount} GUI patch(es) apply`);
for (const [id, reason] of Object.entries(record.unavailable)) console.log(` unavailable ${id}: ${reason}`);
describe(record);
const blocking = blockingFailures(unavailableFailures(record.unavailable, values.patches, values['gui-patches']));
const blocking = blockingFailures(unavailableFailures(record, values.patches));
if (blocking.length) {
console.error(`essential patch(es) unavailable: ${blocking.map((failure) => failure.patchId).join(', ')}; nothing was written`);
return 1;
}
const path = join(values.out, recordFileName(record.gameVersion));
const path = join(patchSetFolders(values.patches).versions, recordFileName(record.gameVersion));
writeFileSync(path, formatVersionRecord(record), 'utf-8');
console.log(`wrote ${path}`);
return 0;
}
function describe(record: VersionRecord): void {
const counts = [
`${Object.keys(record.exePatches).length} exe patch(es)`,
`${Object.keys(record.guiPatches).length} GUI patch(es)`,
`${Object.keys(record.nativeModules).length} native module(s)`,
];
console.log(`${record.gameVersion}: ${counts.join(', ')} apply`);
for (const [id, reason] of Object.entries(record.unavailable)) console.log(` unavailable ${id}: ${reason}`);
}
/** The unavailable patches with their feature tags, as the essential-features check takes them. */
function unavailableFailures(unavailable: Readonly<Record<string, string>>, exePatches: string, guiPatches: string) {
const features = new Map([...loadPatches(exePatches), ...loadGuiPatches(guiPatches)].map((patch) => [patch.id, patch.features]));
return Object.entries(unavailable).map(([patchId, reason]) => ({ patchId, reason, features: features.get(patchId) ?? [] }));
function unavailableFailures(record: VersionRecord, patches: string) {
const features = new Map<string, readonly string[]>();
for (const feature of patchFeatures(patches)) {
for (const id of feature.patchIds) features.set(id, [...(features.get(id) ?? []), feature.tag]);
}
return Object.entries(record.unavailable).map(([patchId, reason]) => ({ patchId, reason, features: features.get(patchId) ?? [] }));
}
process.exitCode = main();