Let each patch carry variants written for different game builds

A game update used to fail a patch whenever any byte it compared moved, even
when only an address in the instruction changed. Patch definitions now say
what a change needs and read the rest from the code:

- patch.jsonc holds a list of variants, each written for one game build
  (written_for) with its own locate block and edit; locate.jsonc is merged
  into it. Exactly one variant must apply, otherwise the patch is left out.
  GUI script patches use the same variants rule.
- expect_original and the bytes to write use the signature syntax, so
  addresses that differ between builds can be wildcards.
- A locate block can capture values at the site (rel32 targets, immediates,
  displacements); a rel32 fixup fills a hole in the written bytes from a
  capture. allow-local-host-bot-spawns now jumps to the target of the
  conditional jump it replaces instead of a stored distance, which makes it
  apply to 2.61.0.43 as well.
- verified_on is gone from the definitions. patches/versions/<version>.jsonc
  records, per checked game build, which variant of every patch applies and
  where; scripts/record-game-version.ts writes it and the launcher reads the
  recorded versions from there.

The Python tools (check-patches, patch-exe, check-gui) read the same format;
check-patches assembles a variant whose assembly names captures at the site
it was located at.

Checked: root and launcher type checks; check-patches and check-gui on
2.61.0.37 and 2.61.0.43 (12 exe and 35 GUI patches each); check-patches and
check-gui report a deliberately broken patch with a non-zero exit;
build-game-copy from 2.61.0.43 into a temporary folder. The computed bytes of
allow-local-host-bot-spawns on 2.61.0.37 equal the bytes it stored before.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 11:47:08 +08:00
1 parent 3f366651bd
commit b819912733
94 files changed
+1884 -933

No files matched your search

+2 -2
View File
@@ -1,5 +1,5 @@
import { app, BrowserWindow, dialog, shell } from 'electron';
import { patchFeatures, verifiedGameVersions } from '@wto/patcher';
import { patchFeatures, recordedGameVersions } from '@wto/patcher';
import { AppError } from '@shared/errors.ts';
import { listBackgroundPictures } from '../services/background-art/art-catalog.ts';
import { getSettings, updateSettings } from '../services/config/settings-store.ts';
@@ -20,7 +20,7 @@ export function registerIpcHandlers(): void {
electron: process.versions.electron,
systemLocale: app.getLocale(),
userDataPath: app.getPath('userData'),
supportedGameVersions: verifiedGameVersions(resources.exePatches, resources.guiPatches),
supportedGameVersions: recordedGameVersions(resources.versionRecords),
};
});
handle('app:listBackgrounds', async () => {
@@ -1,6 +1,6 @@
import { access, readFile, stat } from 'node:fs/promises';
import { join } from 'node:path';
import { executableVersion, GAME_FILES, isInSteamLibrary, verifiedGameVersions } from '@wto/patcher';
import { executableVersion, GAME_FILES, isInSteamLibrary, recordedGameVersions } from '@wto/patcher';
import { AppError } from '@shared/errors.ts';
import type { GameFolderInspection } from '@shared/schemas/install.ts';
import { resourcePaths } from '../resources/resource-paths.ts';
@@ -21,7 +21,7 @@ export async function inspectGameFolder(path: string): Promise<GameFolderInspect
path,
missingFiles,
version: missingFiles.includes(GAME_FILES.executable) ? null : await readVersion(join(path, GAME_FILES.executable)),
verifiedVersions: verifiedGameVersions(resources.exePatches, resources.guiPatches),
verifiedVersions: recordedGameVersions(resources.versionRecords),
inSteamLibrary: isInSteamLibrary(path),
};
}
@@ -2,12 +2,14 @@ import { join, resolve } from 'node:path';
import { app } from 'electron';
/**
* Where the launcher finds what it ships besides its own code: the patch definitions and the
* network hook library. In development they are this repository's folders.
* Where the launcher finds what it ships besides its own code: the patch definitions, the version
* records and the network hook library. In development they are this repository's folders.
*/
export interface ResourcePaths {
readonly exePatches: string;
readonly guiPatches: string;
/** One record per adapted game version (@wto/patcher version-record.ts). */
readonly versionRecords: string;
/** wto_ws.dll, built by native/wto-net/build.ps1. */
readonly networkHookLibrary: string;
}
@@ -22,6 +24,7 @@ export function resourcePaths(): ResourcePaths {
return {
exePatches: join(repository, 'patches', 'exe'),
guiPatches: join(repository, 'patches', 'gui'),
versionRecords: join(repository, 'patches', 'versions'),
networkHookLibrary: join(repository, 'build', 'native', 'wto_ws.dll'),
};
}