From dde852e2b1a4ad25b78bf1bf4839aec886daae1f Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sun, 29 Nov 2026 12:15:30 +0800 Subject: [PATCH] feat(patcher): resolve native LocalMP values from patch definitions 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/.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.[.] 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. --- apps/launcher/src/main/ipc/handlers.ts | 4 +- .../game-folder/inspect-game-folder.ts | 2 +- .../src/main/services/install/patch-check.ts | 3 +- .../main/services/resources/resource-paths.ts | 14 +- .../src/main/workers/patch-check-protocol.ts | 4 +- .../src/main/workers/patch-check-worker.ts | 5 +- .../src/renderer/src/i18n/locales/en.json | 2 + .../src/renderer/src/i18n/locales/zh-CN.json | 2 + packages/exepatch/src/index.ts | 3 +- packages/exepatch/src/locate/index.ts | 17 +- packages/exepatch/src/locate/string-ref.ts | 110 ++++ packages/exepatch/src/locate/within.ts | 36 ++ packages/exepatch/src/pe-image.ts | 55 +- packages/exepatch/src/site.ts | 6 +- packages/patcher/src/build-game-copy.ts | 29 +- packages/patcher/src/index.ts | 3 + .../patcher/src/native/native-definition.ts | 118 ++++ packages/patcher/src/native/native-resolve.ts | 70 +++ .../patcher/src/native/native-settings.ts | 23 + packages/patcher/src/network/network-hook.ts | 19 +- packages/patcher/src/patch-features.ts | 15 +- packages/patcher/src/patch-set.ts | 22 + packages/patcher/src/version-record.ts | 42 +- patches/native/local_mp_actions.jsonc | 86 +++ patches/native/local_mp_awards.jsonc | 195 ++++++ patches/native/local_mp_core.jsonc | 434 +++++++++++++ patches/native/local_mp_events.jsonc | 126 ++++ patches/native/local_mp_kills.jsonc | 592 ++++++++++++++++++ patches/native/local_mp_loadout.jsonc | 429 +++++++++++++ patches/native/local_mp_nuke.jsonc | 166 +++++ patches/native/local_mp_players.jsonc | 211 +++++++ patches/native/local_mp_scores.jsonc | 47 ++ patches/native/local_mp_support.jsonc | 63 ++ patches/versions/2.61.0.37.jsonc | 375 +++++++++++ scripts/build-game-copy.ts | 19 +- scripts/record-game-version.ts | 62 +- 36 files changed, 3318 insertions(+), 91 deletions(-) create mode 100644 packages/exepatch/src/locate/string-ref.ts create mode 100644 packages/exepatch/src/locate/within.ts create mode 100644 packages/patcher/src/native/native-definition.ts create mode 100644 packages/patcher/src/native/native-resolve.ts create mode 100644 packages/patcher/src/native/native-settings.ts create mode 100644 packages/patcher/src/patch-set.ts create mode 100644 patches/native/local_mp_actions.jsonc create mode 100644 patches/native/local_mp_awards.jsonc create mode 100644 patches/native/local_mp_core.jsonc create mode 100644 patches/native/local_mp_events.jsonc create mode 100644 patches/native/local_mp_kills.jsonc create mode 100644 patches/native/local_mp_loadout.jsonc create mode 100644 patches/native/local_mp_nuke.jsonc create mode 100644 patches/native/local_mp_players.jsonc create mode 100644 patches/native/local_mp_scores.jsonc create mode 100644 patches/native/local_mp_support.jsonc diff --git a/apps/launcher/src/main/ipc/handlers.ts b/apps/launcher/src/main/ipc/handlers.ts index 69ebc8c..bbc6876 100644 --- a/apps/launcher/src/main/ipc/handlers.ts +++ b/apps/launcher/src/main/ipc/handlers.ts @@ -20,7 +20,7 @@ export function registerIpcHandlers(): void { electron: process.versions.electron, systemLocale: app.getLocale(), userDataPath: app.getPath('userData'), - supportedGameVersions: recordedGameVersions(resources.versionRecords), + supportedGameVersions: recordedGameVersions(resources.patches), }; }); handle('app:listBackgrounds', async () => { @@ -65,7 +65,7 @@ export function registerIpcHandlers(): void { handle('install:getRecord', async () => ({ record: await readInstallRecord(), defaultDataPath: defaultDataPath() })); handle('install:listFeatures', () => { const resources = resourcePaths(); - return patchFeatures(resources.exePatches, resources.guiPatches).map((feature) => ({ ...feature, patchIds: [...feature.patchIds] })); + return patchFeatures(resources.patches).map((feature) => ({ ...feature, patchIds: [...feature.patchIds] })); }); handle('settings:get', () => getSettings()); diff --git a/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts b/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts index bad988c..10e26f7 100644 --- a/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts +++ b/apps/launcher/src/main/services/game-folder/inspect-game-folder.ts @@ -21,7 +21,7 @@ export async function inspectGameFolder(path: string): Promise { diff --git a/apps/launcher/src/main/services/resources/resource-paths.ts b/apps/launcher/src/main/services/resources/resource-paths.ts index 7bbafcb..a5c957f 100644 --- a/apps/launcher/src/main/services/resources/resource-paths.ts +++ b/apps/launcher/src/main/services/resources/resource-paths.ts @@ -2,14 +2,12 @@ import { join, resolve } from 'node:path'; import { app } from 'electron'; /** - * 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. + * Where the launcher finds what it ships besides its own code: the patch set (exe, GUI and native + * definitions and version records, @wto/patcher patch-set.ts) 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; + /** Root of the patch set. */ + readonly patches: string; /** wto_ws.dll, built by native/wto-net/build.ps1. */ readonly networkHookLibrary: string; } @@ -22,9 +20,7 @@ export function resourcePaths(): ResourcePaths { // The app path is apps/launcher; the repository is two levels up. const repository = resolve(app.getAppPath(), '..', '..'); return { - exePatches: join(repository, 'patches', 'exe'), - guiPatches: join(repository, 'patches', 'gui'), - versionRecords: join(repository, 'patches', 'versions'), + patches: join(repository, 'patches'), networkHookLibrary: join(repository, 'build', 'native', 'wto_ws.dll'), }; } diff --git a/apps/launcher/src/main/workers/patch-check-protocol.ts b/apps/launcher/src/main/workers/patch-check-protocol.ts index 8a5f6d9..96dd87e 100644 --- a/apps/launcher/src/main/workers/patch-check-protocol.ts +++ b/apps/launcher/src/main/workers/patch-check-protocol.ts @@ -6,8 +6,8 @@ export interface PatchCheckRequest { readonly stockFolder: string; /** The local server's data folder: its store tuning names the packs that get bundle GUIDs. */ readonly dataFolder: string; - readonly exePatches: string; - readonly guiPatches: string; + /** Root of the patch set (@wto/patcher patch-set.ts). */ + readonly patches: string; readonly networkHookLibrary: string; } diff --git a/apps/launcher/src/main/workers/patch-check-worker.ts b/apps/launcher/src/main/workers/patch-check-worker.ts index 55c63b9..c39c545 100644 --- a/apps/launcher/src/main/workers/patch-check-worker.ts +++ b/apps/launcher/src/main/workers/patch-check-worker.ts @@ -27,13 +27,12 @@ function checkPatches(request: PatchCheckRequest): PatchCheck { const build = buildGameCopy({ stock: readStockGameFiles(request.stockFolder), port: CHECK_PORT, - exePatches: request.exePatches, - guiPatches: request.guiPatches, + patches: request.patches, networkHookLibrary: readFileSync(request.networkHookLibrary), multiVehiclePackIds: multiVehiclePackIds(request.dataFolder, () => undefined), placeholderDecals: true, }); - const failures = [...build.exePatches.failures, ...build.guiPatches.failures]; + const failures = [...build.exePatches.failures, ...build.guiPatches.failures, ...build.nativeModules.failures]; return { exePatchesReady: build.exePatches.applied.length, guiPatchesReady: build.guiPatches.applied.length, diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index b652e1d..746b71c 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -262,6 +262,8 @@ "K-Kill, assist and capture scoring": "Kill, assist and capture scoring", "K-Additional vehicles": "Additional vehicles", "K-Scoreboard": "Scoreboard", + "K-Chat and radio": "Chat and radio", + "K-Nuclear bomb": "Nuclear bomb", "L-Debriefing": "Battle results", "L-Battle awards": "Battle awards" }, diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index fb1598c..d42f0c9 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -262,6 +262,8 @@ "K-Kill, assist and capture scoring": "击杀、助攻与占点计分", "K-Additional vehicles": "补充载具", "K-Scoreboard": "计分板", + "K-Chat and radio": "聊天与无线电", + "K-Nuclear bomb": "核弹", "L-Debriefing": "战后结算", "L-Battle awards": "战斗嘉奖" }, diff --git a/packages/exepatch/src/index.ts b/packages/exepatch/src/index.ts index 4823a6f..70bbd4e 100644 --- a/packages/exepatch/src/index.ts +++ b/packages/exepatch/src/index.ts @@ -11,7 +11,8 @@ export { CAPTURE_TYPES, type Captures, type CaptureSpec, type CaptureType } from export { loadPatches, type PatchDefinition, type PatchEdit, type PatchVariant } from './definition.ts'; export { DefinitionError, LocateError, PatchError, PeFormatError, VerifyError } from './errors.ts'; export { asObject, readJsonObject, rejectUnknownKeys, requiredString, stringList, variantObjects } from './json-fields.ts'; -export { PeImage, type Section } from './pe-image.ts'; +export { NO_CONTEXT, type LocateContext } from './locate/index.ts'; +export { PeImage, type FunctionRange, type Section } from './pe-image.ts'; export { describePlan, planPatches, type PatchFailure, type PatchPlan, type PlannedWrite } from './plan.ts'; export { findSite, readSiteSpec, type FoundSite, type SiteSpec } from './site.ts'; export { chooseVariant, type Chosen, type Variant } from './variants.ts'; diff --git a/packages/exepatch/src/locate/index.ts b/packages/exepatch/src/locate/index.ts index fa3d258..c0aebe2 100644 --- a/packages/exepatch/src/locate/index.ts +++ b/packages/exepatch/src/locate/index.ts @@ -1,21 +1,36 @@ /** * Ways to find a site. Each method returns every RVA it matched; it never picks a winner among * several matches, the caller requires exactly one. + * + * signature a byte pattern with wildcards in a section + * string_ref the code that loads the address of a given string + * within a byte pattern inside the function of an already located site */ import { DefinitionError } from '../errors.ts'; import type { PeImage } from '../pe-image.ts'; import * as signature from './signature.ts'; +import * as stringRef from './string-ref.ts'; +import * as within from './within.ts'; + +/** Sites located before this one, by name, for methods that search relative to them. */ +export interface LocateContext { + readonly sites: ReadonlyMap; +} + +export const NO_CONTEXT: LocateContext = { sites: new Map() }; export interface LocateMethod { /** Keys of a locate block this method reads, besides "method" and "captures". */ readonly keys: readonly string[]; - locate(image: PeImage, spec: Readonly>): number[]; + locate(image: PeImage, spec: Readonly>, context: LocateContext): number[]; /** Number of bytes from the site that the method checked; captures must lie inside them. */ length(spec: Readonly>): number; } const METHODS: ReadonlyMap = new Map([ [signature.METHOD, { keys: signature.KEYS, locate: signature.locateSignature, length: signature.signatureLength }], + [stringRef.METHOD, { keys: stringRef.KEYS, locate: stringRef.locateStringReference, length: stringRef.stringReferenceLength }], + [within.METHOD, { keys: within.KEYS, locate: within.locateWithin, length: within.withinLength }], ]); export function locateMethod(method: unknown): LocateMethod { diff --git a/packages/exepatch/src/locate/string-ref.ts b/packages/exepatch/src/locate/string-ref.ts new file mode 100644 index 0000000..ebc7b76 --- /dev/null +++ b/packages/exepatch/src/locate/string-ref.ts @@ -0,0 +1,110 @@ +/** + * Find code by the string it uses: the instructions that load the address of a zero-terminated + * string with a rip-relative lea, or the functions containing them. Engine code names its + * subsystems, script bindings, data fields and log messages with fixed English strings, so a + * string the code refers to identifies that code across builds by name rather than by bytes. + * + * { "method": "string_ref", "string": "kills", "target": "function" } + * { "method": "string_ref", "string": "kills", + * "pattern": "4c 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", "lea_at": 11 } + * + * target "reference" (the default) returns each lea, whose 7 bytes may be captured; "function" + * returns the start of each function containing one. With "pattern", the site is where the + * pattern starts, the lea of the string must be at "lea_at" inside it, and captures may read any + * byte of the pattern: this reads, say, the structure field that the code stores under that name. + */ +import { parseBytePattern, patternMatches, type BytePattern } from '../byte-pattern.ts'; +import { DefinitionError } from '../errors.ts'; +import type { PeImage } from '../pe-image.ts'; + +export const METHOD = 'string_ref'; +export const KEYS: readonly string[] = ['string', 'section', 'target', 'pattern', 'lea_at']; +const DEFAULT_SECTION = '.rdata'; +const LEA_SIZE = 7; +const TARGETS = ['reference', 'function'] as const; + +interface StringRefSpec { + readonly text: string; + readonly section: string; + readonly target: (typeof TARGETS)[number]; + readonly around?: { readonly pattern: BytePattern; readonly leaAt: number }; +} + +export function locateStringReference(image: PeImage, spec: Readonly>): number[] { + const parsed = readSpec(spec); + const references = stringAddresses(image, parsed.text, parsed.section).flatMap((address) => leaIndex(image).get(address) ?? []); + if (parsed.around) return withPattern(image, references, parsed.around); + if (parsed.target === 'reference') return references.sort((left, right) => left - right); + const starts = references.map((rva) => { + const range = image.functionContaining(rva); + if (!range) throw new DefinitionError(`string_ref "${parsed.text}": the reference at 0x${rva.toString(16)} is in no known function`); + return range.begin; + }); + return [...new Set(starts)].sort((left, right) => left - right); +} + +export function stringReferenceLength(spec: Readonly>): number { + const parsed = readSpec(spec); + if (parsed.around) return parsed.around.pattern.bytes.length; + return parsed.target === 'reference' ? LEA_SIZE : 0; +} + +function withPattern(image: PeImage, references: readonly number[], around: NonNullable): number[] { + const starts: number[] = []; + for (const reference of references) { + const start = reference - around.leaAt; + if (patternMatches(around.pattern, image.read(start, around.pattern.bytes.length))) starts.push(start); + } + return starts.sort((left, right) => left - right); +} + +function readSpec(spec: Readonly>): StringRefSpec { + if (typeof spec.string !== 'string' || spec.string === '') throw new DefinitionError('string_ref needs a non-empty "string"'); + const target = (spec.target ?? 'reference') as (typeof TARGETS)[number]; + if (!TARGETS.includes(target)) throw new DefinitionError(`string_ref "target" must be one of ${TARGETS.join(', ')}`); + const section = typeof spec.section === 'string' ? spec.section : DEFAULT_SECTION; + if (spec.pattern === undefined) { + if (spec.lea_at !== undefined) throw new DefinitionError('string_ref "lea_at" needs a "pattern"'); + return { text: spec.string, section, target }; + } + if (target !== 'reference') throw new DefinitionError('string_ref with a "pattern" locates the pattern, so "target" must be "reference"'); + const pattern = parseBytePattern(spec.pattern, 'string_ref pattern'); + const leaAt = spec.lea_at; + if (typeof leaAt !== 'number' || !Number.isInteger(leaAt) || leaAt < 0 || leaAt + LEA_SIZE > pattern.bytes.length) { + throw new DefinitionError('string_ref "lea_at" must be the position of a 7-byte lea inside the pattern'); + } + return { text: spec.string, section, target, around: { pattern, leaAt } }; +} + +/** + * RVAs where `text` followed by a zero byte is stored. The linker merges a string into the tail of + * a longer one that ends the same way, so a match need not start a string; only the code that + * loads one of these addresses decides which is meant. + */ +function stringAddresses(image: PeImage, text: string, sectionName: string): number[] { + const data = Buffer.from(image.sectionBytes(sectionName)); + const needle = Buffer.concat([Buffer.from(text, 'utf8'), Buffer.of(0)]); + const base = image.section(sectionName).rva; + const found: number[] = []; + for (let at = data.indexOf(needle); at >= 0; at = data.indexOf(needle, at + 1)) found.push(base + at); + return found; +} + +/** Every rip-relative lea in .text, by the address it loads. */ +function leaIndex(image: PeImage): ReadonlyMap { + return image.cached('string_ref:lea', () => { + const text = image.sectionBytes('.text'); + const base = image.section('.text').rva; + const view = new DataView(text.buffer, text.byteOffset, text.byteLength); + const index = new Map(); + for (let at = 0; at + LEA_SIZE <= text.length; at++) { + // REX.W (48) or REX.WR (4c), opcode 8d, ModRM with mod 00 and r/m 101 (rip-relative). + if ((text[at] !== 0x48 && text[at] !== 0x4c) || text[at + 1] !== 0x8d || (text[at + 2]! & 0xc7) !== 0x05) continue; + const address = base + at + LEA_SIZE + view.getInt32(at + 3, true); + const list = index.get(address); + if (list) list.push(base + at); + else index.set(address, [base + at]); + } + return index; + }); +} diff --git a/packages/exepatch/src/locate/within.ts b/packages/exepatch/src/locate/within.ts new file mode 100644 index 0000000..dea307b --- /dev/null +++ b/packages/exepatch/src/locate/within.ts @@ -0,0 +1,36 @@ +/** + * Find a byte pattern inside the function that contains an already located site. The function + * range comes from the exception directory. Searching one function instead of the whole code + * section lets a short pattern, such as the one instruction that reads a structure field, be + * unique, and ties it to the function it was written for. + * + * { "method": "within", "in": "mplayer_add_score", "pattern": "f3 0f 2a 84 81 ?? ?? ?? ??" } + * + * "in" names a site resolved earlier in the same definition set. + */ +import { parseBytePattern, patternMatches } from '../byte-pattern.ts'; +import { DefinitionError, LocateError } from '../errors.ts'; +import type { PeImage } from '../pe-image.ts'; +import type { LocateContext } from './index.ts'; + +export const METHOD = 'within'; +export const KEYS: readonly string[] = ['in', 'pattern']; + +export function locateWithin(image: PeImage, spec: Readonly>, context: LocateContext): number[] { + if (typeof spec.in !== 'string') throw new DefinitionError('within needs the name of a located site in "in"'); + const anchor = context.sites.get(spec.in); + if (anchor === undefined) throw new LocateError(`site "${spec.in}" that this one is searched in is unavailable`); + const range = image.functionContaining(anchor); + if (!range) throw new LocateError(`site "${spec.in}" at 0x${anchor.toString(16)} is in no known function`); + const pattern = parseBytePattern(spec.pattern, 'within pattern'); + const code = image.read(range.begin, range.end - range.begin); + const hits: number[] = []; + for (let at = 0; at + pattern.bytes.length <= code.length; at++) { + if (patternMatches(pattern, code, at)) hits.push(range.begin + at); + } + return hits; +} + +export function withinLength(spec: Readonly>): number { + return parseBytePattern(spec.pattern, 'within pattern').bytes.length; +} diff --git a/packages/exepatch/src/pe-image.ts b/packages/exepatch/src/pe-image.ts index 0642796..d5c199f 100644 --- a/packages/exepatch/src/pe-image.ts +++ b/packages/exepatch/src/pe-image.ts @@ -1,6 +1,7 @@ /** - * Read-only view of a PE executable: its sections, and the mapping between RVAs (addresses - * relative to the image base) and file offsets. Only what locating and writing patches needs. + * Read-only view of a PE executable: its sections, the mapping between RVAs (addresses relative + * to the image base) and file offsets, and the function ranges of its exception directory. Only + * what locating and writing patches needs. */ import { PeFormatError } from './errors.ts'; @@ -12,17 +13,51 @@ export interface Section { readonly rawSize: number; } +/** A function, or one part of a function, from the exception directory: [begin, end). */ +export interface FunctionRange { + readonly begin: number; + readonly end: number; +} + const SECTION_HEADER_SIZE = 40; +const PE32_PLUS_MAGIC = 0x20b; +/** Offset of the data directories in a PE32+ optional header. */ +const DATA_DIRECTORIES = 112; +const EXCEPTION_DIRECTORY = 3; +const RUNTIME_FUNCTION_SIZE = 12; export class PeImage { readonly data: Uint8Array; readonly sections: readonly Section[]; + #functions: readonly FunctionRange[] | undefined; + readonly #cache = new Map(); constructor(data: Uint8Array) { this.data = data; this.sections = readSections(data); } + /** The function range containing `rva`, or null when the exception directory has none. */ + functionContaining(rva: number): FunctionRange | null { + const functions = (this.#functions ??= readFunctions(this)); + let low = 0; + let high = functions.length - 1; + while (low <= high) { + const middle = (low + high) >> 1; + const range = functions[middle]!; + if (rva < range.begin) high = middle - 1; + else if (rva >= range.end) low = middle + 1; + else return range; + } + return null; + } + + /** A value derived from this image, computed once (indexes the locate methods build). */ + cached(key: string, compute: () => T): T { + if (!this.#cache.has(key)) this.#cache.set(key, compute()); + return this.#cache.get(key) as T; + } + section(name: string): Section { const section = this.sections.find((item) => item.name === name); if (!section) throw new PeFormatError(`no section ${name}`); @@ -71,3 +106,19 @@ function readSections(data: Uint8Array): Section[] { }; }); } + +function readFunctions(image: PeImage): FunctionRange[] { + const view = new DataView(image.data.buffer, image.data.byteOffset, image.data.byteLength); + const optionalHeader = view.getUint32(0x3c, true) + 24; + if (view.getUint16(optionalHeader, true) !== PE32_PLUS_MAGIC) throw new PeFormatError('not a PE32+ executable'); + const directory = optionalHeader + DATA_DIRECTORIES + EXCEPTION_DIRECTORY * 8; + const rva = view.getUint32(directory, true); + const size = view.getUint32(directory + 4, true); + const table = image.read(rva, size); + const entries = new DataView(table.buffer, table.byteOffset, table.byteLength); + const functions: FunctionRange[] = []; + for (let at = 0; at + RUNTIME_FUNCTION_SIZE <= size; at += RUNTIME_FUNCTION_SIZE) { + functions.push({ begin: entries.getUint32(at, true), end: entries.getUint32(at + 4, true) }); + } + return functions.sort((left, right) => left.begin - right.begin); +} diff --git a/packages/exepatch/src/site.ts b/packages/exepatch/src/site.ts index 7494d36..041f4c6 100644 --- a/packages/exepatch/src/site.ts +++ b/packages/exepatch/src/site.ts @@ -6,7 +6,7 @@ import { readCaptures, readCaptureSpecs, type Captures, type CaptureSpec } from './captures.ts'; import { DefinitionError, LocateError } from './errors.ts'; import { asObject, rejectUnknownKeys } from './json-fields.ts'; -import { locateMethod, type LocateMethod } from './locate/index.ts'; +import { locateMethod, NO_CONTEXT, type LocateContext, type LocateMethod } from './locate/index.ts'; import type { PeImage } from './pe-image.ts'; export interface SiteSpec { @@ -35,8 +35,8 @@ export function readSiteSpec(raw: unknown, where: string): SiteSpec { } /** The single place the spec matches, with its captures; anything else is a LocateError. */ -export function findSite(image: PeImage, site: SiteSpec): FoundSite { - const hits = site.method.locate(image, site.spec); +export function findSite(image: PeImage, site: SiteSpec, context: LocateContext = NO_CONTEXT): FoundSite { + const hits = site.method.locate(image, site.spec, context); if (!hits.length) throw new LocateError('site not found: this game build differs from the verified ones, or the executable is already patched'); if (hits.length > 1) throw new LocateError(`site found in ${hits.length} places, so it is ambiguous: ${hits.map(hex).join(', ')}`); return { rva: hits[0]!, captures: readCaptures(image, hits[0]!, site.captures) }; diff --git a/packages/patcher/src/build-game-copy.ts b/packages/patcher/src/build-game-copy.ts index 614702c..6e5c5e4 100644 --- a/packages/patcher/src/build-game-copy.ts +++ b/packages/patcher/src/build-game-copy.ts @@ -3,13 +3,13 @@ * the patched executable, the network hook library and its settings. Nothing is written here * (write-game-copy.ts does that), so a caller can show the report first and let the player decide. * - * Everything the build needs from outside comes in as an input: the stock files, the patch - * folders, the hook library, and the multi-vehicle pack ids the local server will sell from its + * Everything the build needs from outside comes in as an input: the stock files, the patch set + * (patch-set.ts), the hook library, and the multi-vehicle pack ids the local server will sell from its * data folder. */ import { readFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; -import type { PatchFailure } from '@wto/exepatch'; +import { PeImage, type PatchFailure } from '@wto/exepatch'; import { rebuildCharPack, type CharPackResult } from './char-pack.ts'; import { blockingFailures } from './essential-features.ts'; import { patchExecutable } from './executable.ts'; @@ -19,6 +19,9 @@ import { rebuildMainPack } from './main-pack.ts'; import type { AddressChange } from './network/address-rewrite.ts'; import { localEndpoint, type LocalEndpoint } from './network/local-endpoint.ts'; import { NETWORK_HOOK_LIBRARY, networkHookSettings } from './network/network-hook.ts'; +import { loadNativeModules } from './native/native-definition.ts'; +import { resolveNativeModules } from './native/native-resolve.ts'; +import { patchSetFolders } from './patch-set.ts'; import { offlinePackBundleGuids } from './store/offline-bundles.ts'; /** The stock files the build changes. */ @@ -33,10 +36,8 @@ export interface GameCopyInputs { readonly stock: StockGameFiles; /** The local server's port, written into the data packs and the hook settings. */ readonly port: number; - /** Folder of the exe patch definitions. */ - readonly exePatches: string; - /** Folder of the GUI script patch definitions. */ - readonly guiPatches: string; + /** Root of the patch set: exe, GUI and native definitions (patch-set.ts). */ + readonly patches: string; /** wto_ws.dll, built from native/wto-net. */ readonly networkHookLibrary: Uint8Array; /** Ids of the multi-vehicle packs the local server sells (@wto/server multiVehiclePackIds). */ @@ -57,6 +58,8 @@ export interface GameCopyBuild { readonly endpoint: LocalEndpoint; readonly exePatches: { readonly applied: readonly { readonly patchId: string; readonly rva: number }[]; readonly failures: readonly PatchFailure[] }; readonly guiPatches: { readonly applied: readonly string[]; readonly failures: readonly PatchFailure[] }; + /** Native modules the hook library can run on this executable, and the ones it cannot. */ + readonly nativeModules: { readonly available: readonly string[]; readonly failures: readonly PatchFailure[] }; /** Unavailable patches that must stop an installation (essential-features.ts). */ readonly blocking: readonly PatchFailure[]; readonly charPack: Omit; @@ -77,14 +80,17 @@ export function readStockGameFiles(folder: string): StockGameFiles { export function buildGameCopy(inputs: GameCopyInputs): GameCopyBuild { const endpoint = localEndpoint(inputs.port); - const executable = patchExecutable(inputs.stock.executable, inputs.exePatches); + const folders = patchSetFolders(inputs.patches); + const executable = patchExecutable(inputs.stock.executable, folders.exe); + const stockImage = new PeImage(inputs.stock.executable); + const native = resolveNativeModules(stockImage, loadNativeModules(folders.native)); const { pack: charPack, ...charReport } = rebuildCharPack(inputs.stock.charPack, endpoint, { placeholderDecals: inputs.placeholderDecals }); const bundles = offlinePackBundleGuids(inputs.stock.charPack, inputs.multiVehiclePackIds); const mainPack = rebuildMainPack(inputs.stock.mainPack, endpoint, bundles); - const guiPack = rebuildGuiPack(inputs.stock.guiPack, endpoint, inputs.guiPatches); + const guiPack = rebuildGuiPack(inputs.stock.guiPack, endpoint, folders.gui); const executableFolder = dirname(GAME_FILES.executable); - const hookSettings = networkHookSettings(endpoint); + const hookSettings = networkHookSettings(endpoint, stockImage, native.values); const files: GameCopyFile[] = [ { path: GAME_FILES.charPack, content: charPack }, { path: GAME_FILES.mainPack, content: mainPack.pack }, @@ -94,12 +100,13 @@ export function buildGameCopy(inputs: GameCopyInputs): GameCopyBuild { { path: join(executableFolder, hookSettings.name), content: hookSettings.content }, ]; - const failures = [...executable.plan.failures, ...guiPack.failures]; + const failures = [...executable.plan.failures, ...guiPack.failures, ...native.failures]; return { files, endpoint, exePatches: { applied: executable.plan.writes.map((write) => ({ patchId: write.patchId, rva: write.rva })), failures: executable.plan.failures }, guiPatches: { applied: guiPack.applied.map((item) => item.patch.id), failures: guiPack.failures }, + nativeModules: { available: [...native.available.keys()], failures: native.failures }, blocking: blockingFailures(failures), charPack: charReport, engineAddresses: mainPack.addresses, diff --git a/packages/patcher/src/index.ts b/packages/patcher/src/index.ts index 3455ab2..d2bd6ea 100644 --- a/packages/patcher/src/index.ts +++ b/packages/patcher/src/index.ts @@ -25,7 +25,10 @@ export { redirectAddresses, type AddressChange } from './network/address-rewrite export { hostPort, localEndpoint, localUrl, type LocalEndpoint } from './network/local-endpoint.ts'; export { NETWORK_HOOK_LIBRARY, networkHookSettings } from './network/network-hook.ts'; export { redirectNetworkConfig, type NetworkRedirectReport } from './network/redirect-network-config.ts'; +export { loadNativeModules, type NativeModule, type NativeSite, type NativeSiteVariant } from './native/native-definition.ts'; +export { resolveNativeModules, type NativeResolution } from './native/native-resolve.ts'; export { patchFeatures, type PatchFeature } from './patch-features.ts'; +export { patchSetFolders, type PatchSetFolders } from './patch-set.ts'; export { offlinePackBundleGuids } from './store/offline-bundles.ts'; export { checkGameBuild, diff --git a/packages/patcher/src/native/native-definition.ts b/packages/patcher/src/native/native-definition.ts new file mode 100644 index 0000000..6fc1374 --- /dev/null +++ b/packages/patcher/src/native/native-definition.ts @@ -0,0 +1,118 @@ +/** + * Native module definitions: what the network hook library's LocalMP modules + * (native/wto-net/src/local_mp_*.c) need from aces.exe, one file per module under + * patches/native/.jsonc: + * + * module the C module's name, equal to the file name + * features the feature inventory rows the module provides + * requires modules that must be available for this one to work + * sites named places in the executable: functions to call or hook, and code whose + * captures give global addresses and structure offsets; each site has variants + * written for game builds, exactly one of which must locate it + * + * The launcher resolves every site against the player's executable when it builds the game copy + * (native-resolve.ts) and hands the values to the library, so the library holds no address or + * offset of its own. Comments explain what each site is and how it was derived. + */ +import { readdirSync } from 'node:fs'; +import { basename, join } from 'node:path'; +import { + asObject, + DefinitionError, + readJsonObject, + readSiteSpec, + rejectUnknownKeys, + requiredString, + stringList, + variantObjects, + type SiteSpec, +} from '@wto/exepatch'; + +const SUFFIX = '.jsonc'; +const MODULE_KEYS = new Set(['module', 'features', 'requires', 'sites']); +const SITE_KEYS = new Set(['variants']); +const VARIANT_KEYS = new Set(['written_for', 'locate']); +const NAME = /^[a-z][a-z0-9_]*$/; + +export interface NativeSiteVariant { + readonly writtenFor: string; + readonly locate: SiteSpec; +} + +export interface NativeSite { + readonly name: string; + readonly variants: readonly NativeSiteVariant[]; + /** Capture names every variant provides. */ + readonly captures: readonly string[]; +} + +export interface NativeModule { + readonly module: string; + readonly features: readonly string[]; + readonly requires: readonly string[]; + readonly sites: readonly NativeSite[]; +} + +/** Every module in `folder`, in an order where each module comes after the ones it requires. */ +export function loadNativeModules(folder: string): NativeModule[] { + const modules = readdirSync(folder).filter((name) => name.endsWith(SUFFIX)).sort().map((name) => readModule(join(folder, name))); + rejectDuplicateSites(modules); + return dependencyOrder(modules); +} + +function readModule(path: string): NativeModule { + const raw = readJsonObject(path); + rejectUnknownKeys(raw, MODULE_KEYS, path); + const module = requiredString(raw.module, `${path} module`); + if (`${module}${SUFFIX}` !== basename(path)) throw new DefinitionError(`${path}: module "${module}" must be in ${module}${SUFFIX}`); + const sites = Object.entries(asObject(raw.sites, `${path} sites`)).map(([name, site]) => readSite(name, site, `${path} site ${name}`)); + return { module, features: stringList(raw.features, `${path} features`), requires: stringList(raw.requires, `${path} requires`), sites }; +} + +function readSite(name: string, raw: unknown, where: string): NativeSite { + if (!NAME.test(name)) throw new DefinitionError(`${where}: site names are lower case letters, digits and "_"`); + const site = asObject(raw, where); + rejectUnknownKeys(site, SITE_KEYS, where); + const variants = variantObjects(site.variants, where).map((variant) => { + const label = `${where} variant ${String(variant.written_for)}`; + rejectUnknownKeys(variant, VARIANT_KEYS, label); + return { writtenFor: variant.written_for as string, locate: readSiteSpec(variant.locate, `${label} locate`) }; + }); + const captures = variants[0]!.locate.captures.map((capture) => capture.name).sort(); + for (const variant of variants) { + const names = variant.locate.captures.map((capture) => capture.name).sort(); + if (names.join() !== captures.join()) throw new DefinitionError(`${where}: every variant must capture the same values (${captures.join(', ')})`); + } + return { name, variants, captures }; +} + +function rejectDuplicateSites(modules: readonly NativeModule[]): void { + const seen = new Map(); + for (const module of modules) { + for (const site of module.sites) { + const previous = seen.get(site.name); + if (previous) throw new DefinitionError(`site "${site.name}" is defined in both ${previous} and ${module.module}`); + seen.set(site.name, module.module); + } + } +} + +function dependencyOrder(modules: readonly NativeModule[]): NativeModule[] { + const byName = new Map(modules.map((module) => [module.module, module])); + const ordered: NativeModule[] = []; + const visiting = new Set(); + const visit = (module: NativeModule): void => { + if (ordered.includes(module)) return; + if (visiting.has(module.module)) throw new DefinitionError(`native modules require each other in a cycle through ${module.module}`); + visiting.add(module.module); + for (const name of module.requires) { + const required = byName.get(name); + if (!required) throw new DefinitionError(`${module.module} requires unknown native module ${name}`); + visit(required); + } + visiting.delete(module.module); + ordered.push(module); + }; + modules.forEach(visit); + return ordered; +} diff --git a/packages/patcher/src/native/native-resolve.ts b/packages/patcher/src/native/native-resolve.ts new file mode 100644 index 0000000..9c7f88c --- /dev/null +++ b/packages/patcher/src/native/native-resolve.ts @@ -0,0 +1,70 @@ +/** + * Resolve the native module definitions (native-definition.ts) against a stock executable. + * + * Modules are resolved in dependency order and their sites in definition order, so a site can be + * searched inside a function located before it. Every site of a module must be located for the + * module to be available; a module that is not, and every module requiring it, is listed with its + * features the same way an unavailable patch is, and the library leaves that module off. + * + * The values handed to the library are, per site of an available module, `` (its RVA) and + * `.` for each capture. + */ +import { chooseVariant, findSite, PatchError, type PatchFailure, type PeImage } from '@wto/exepatch'; +import type { NativeModule } from './native-definition.ts'; + +export interface NativeResolution { + /** Values by name, from the available modules only. */ + readonly values: ReadonlyMap; + /** Module name -> the variant used for each of its sites. */ + readonly available: ReadonlyMap>; + /** Unavailable modules, with patchId `native/`. */ + readonly failures: readonly PatchFailure[]; +} + +export function resolveNativeModules(image: PeImage, modules: readonly NativeModule[]): NativeResolution { + const values = new Map(); + const sites = new Map(); + const available = new Map>(); + const failures: PatchFailure[] = []; + + for (const module of modules) { + const missing = module.requires.filter((name) => !available.has(name)); + try { + if (missing.length) throw new PatchError(`depends on unavailable native module(s): ${missing.join(', ')}`); + const resolved = resolveModule(image, module, sites); + for (const [name, value] of resolved.values) values.set(name, value); + for (const [name, rva] of resolved.sites) sites.set(name, rva); + available.set(module.module, resolved.variants); + } catch (error) { + if (!(error instanceof PatchError)) throw error; + failures.push({ patchId: `native/${module.module}`, features: module.features, reason: error.message }); + } + } + return { values, available, failures }; +} + +interface ResolvedModule { + readonly values: Map; + readonly sites: Map; + readonly variants: Map; +} + +/** Every site of `module`, or a PatchError naming the first one that cannot be located. */ +function resolveModule(image: PeImage, module: NativeModule, located: ReadonlyMap): ResolvedModule { + const result: ResolvedModule = { values: new Map(), sites: new Map(), variants: new Map() }; + for (const site of module.sites) { + const context = { sites: new Map([...located, ...result.sites]) }; + let chosen; + try { + chosen = chooseVariant(site.variants, (variant) => findSite(image, variant.locate, context)); + } catch (error) { + if (error instanceof PatchError) throw new PatchError(`site ${site.name}: ${error.message}`); + throw error; + } + result.sites.set(site.name, chosen.value.rva); + result.variants.set(site.name, chosen.variant.writtenFor); + result.values.set(site.name, chosen.value.rva); + for (const [capture, value] of chosen.value.captures) result.values.set(`${site.name}.${capture}`, value); + } + return result; +} diff --git a/packages/patcher/src/native/native-settings.ts b/packages/patcher/src/native/native-settings.ts new file mode 100644 index 0000000..9cc022e --- /dev/null +++ b/packages/patcher/src/native/native-settings.ts @@ -0,0 +1,23 @@ +/** + * The lines of the hook library's settings file that carry the resolved native values. + * + * exe.time_date_stamp=0x... the executable the values were resolved for (PE file header); + * exe.size_of_image=0x... the library compares both with the running executable and + * leaves every LocalMP module off when they differ + * native.=0x... one line per value (native-resolve.ts), signed values as -0x... + */ +import type { PeImage } from '@wto/exepatch'; + +export function nativeSettingsLines(image: PeImage, values: ReadonlyMap): string[] { + const view = new DataView(image.data.buffer, image.data.byteOffset, image.data.byteLength); + const peHeader = view.getUint32(0x3c, true); + const timeDateStamp = view.getUint32(peHeader + 8, true); + const sizeOfImage = view.getUint32(peHeader + 24 + 56, true); + const lines = [`exe.time_date_stamp=${hex(timeDateStamp)}`, `exe.size_of_image=${hex(sizeOfImage)}`]; + for (const [name, value] of [...values].sort(([left], [right]) => left.localeCompare(right))) lines.push(`native.${name}=${hex(value)}`); + return lines; +} + +function hex(value: number): string { + return value < 0 ? `-0x${(-value).toString(16)}` : `0x${value.toString(16)}`; +} diff --git a/packages/patcher/src/network/network-hook.ts b/packages/patcher/src/network/network-hook.ts index 724bbf5..abe2b14 100644 --- a/packages/patcher/src/network/network-hook.ts +++ b/packages/patcher/src/network/network-hook.ts @@ -1,14 +1,23 @@ /** * The network hook library in the game copy: the exe patch - * online/network-hook-library makes aces.exe load win64/wto_ws.dll, which reads the local - * server port from win64/wto_ws.cfg. Both files are written next to the executable; the DLL is - * built from native/wto-net (build.ps1). + * online/network-hook-library makes aces.exe load win64/wto_ws.dll, which reads its settings + * from win64/wto_ws.cfg: the local server port, and the values its LocalMP modules need from the + * executable (native/native-settings.ts). Both files are written next to the executable; the DLL + * is built from native/wto-net (build.ps1). */ +import type { PeImage } from '@wto/exepatch'; +import { nativeSettingsLines } from '../native/native-settings.ts'; import type { LocalEndpoint } from './local-endpoint.ts'; export const NETWORK_HOOK_LIBRARY = 'wto_ws.dll'; const SETTINGS = 'wto_ws.cfg'; -export function networkHookSettings(endpoint: LocalEndpoint): { name: string; content: Uint8Array } { - return { name: SETTINGS, content: new TextEncoder().encode(`port=${endpoint.port}\n`) }; +/** `stock` is the unpatched executable the native values were resolved against. */ +export function networkHookSettings( + endpoint: LocalEndpoint, + stock: PeImage, + nativeValues: ReadonlyMap, +): { name: string; content: Uint8Array } { + const lines = [`port=${endpoint.port}`, ...nativeSettingsLines(stock, nativeValues)]; + return { name: SETTINGS, content: new TextEncoder().encode(`${lines.join('\n')}\n`) }; } diff --git a/packages/patcher/src/patch-features.ts b/packages/patcher/src/patch-features.ts index 938d4c0..b54f0fc 100644 --- a/packages/patcher/src/patch-features.ts +++ b/packages/patcher/src/patch-features.ts @@ -1,23 +1,28 @@ /** - * The features the patch definitions cover (feature inventory rows named in `features`), each - * once, with the patches behind it. The launcher lists them to show which features a copy has. + * The features the patch set covers (feature inventory rows named in `features` of the exe, GUI + * and native definitions), each once, with the patches and native modules behind it. The + * launcher lists them to show which features a copy has. */ import { loadPatches } from '@wto/exepatch'; import { ESSENTIAL_FEATURES } from './essential-features.ts'; import { loadGuiPatches } from './gui-patch-definition.ts'; +import { loadNativeModules } from './native/native-definition.ts'; +import { patchSetFolders } from './patch-set.ts'; export interface PatchFeature { /** Feature tag with a prefix identifying its feature group. */ readonly tag: string; /** A copy cannot run, or cannot stay apart from the online game, without it. */ readonly essential: boolean; - /** Ids of the exe and GUI patches tagged with it. */ + /** Ids of the exe and GUI patches, and `native/` of native modules, tagged with it. */ readonly patchIds: readonly string[]; } -export function patchFeatures(exePatches: string, guiPatches: string): PatchFeature[] { +export function patchFeatures(patches: string): PatchFeature[] { + const folders = patchSetFolders(patches); + const natives = loadNativeModules(folders.native).map((module) => ({ id: `native/${module.module}`, features: module.features })); const byTag = new Map(); - for (const patch of [...loadPatches(exePatches), ...loadGuiPatches(guiPatches)]) { + for (const patch of [...loadPatches(folders.exe), ...loadGuiPatches(folders.gui), ...natives]) { for (const tag of patch.features) { const ids = byTag.get(tag) ?? []; ids.push(patch.id); diff --git a/packages/patcher/src/patch-set.ts b/packages/patcher/src/patch-set.ts new file mode 100644 index 0000000..feafe83 --- /dev/null +++ b/packages/patcher/src/patch-set.ts @@ -0,0 +1,22 @@ +/** + * A patch set: everything that adapts the game files to the offline version, as one folder. + * The repository's patches/ is one; the adaptation pack the launcher downloads is another with + * the same layout. + * + * exe/ exe patch definitions (@wto/exepatch) + * gui/ GUI script patch definitions (gui-patch-definition.ts) + * native/ native module definitions (native/native-definition.ts) + * versions/ version records (version-record.ts) + */ +import { join } from 'node:path'; + +export interface PatchSetFolders { + readonly exe: string; + readonly gui: string; + readonly native: string; + readonly versions: string; +} + +export function patchSetFolders(root: string): PatchSetFolders { + return { exe: join(root, 'exe'), gui: join(root, 'gui'), native: join(root, 'native'), versions: join(root, 'versions') }; +} diff --git a/packages/patcher/src/version-record.ts b/packages/patcher/src/version-record.ts index 34a6882..87a1553 100644 --- a/packages/patcher/src/version-record.ts +++ b/packages/patcher/src/version-record.ts @@ -1,7 +1,7 @@ /** * Version records: one file per game build the patches were checked on, under patches/versions/ - * (`.jsonc`). A record says which variant of every patch applies to that build and - * where, and which patches are unavailable on it. The developer writes it with + * (`.jsonc`). A record says which variant of every patch and native site applies to + * that build and where, the native values resolved on it, and what is unavailable on it. The developer writes it with * scripts/record-game-version.ts once the build has been checked, and commits it after the * build was played in the game, so a record is what makes a game version "adapted". * @@ -14,7 +14,10 @@ import { join } from 'node:path'; import { asObject, DefinitionError, loadPatches, PeImage, planPatches, readJsonObject, requiredString } from '@wto/exepatch'; import { executableVersion } from './game-version.ts'; import { rebuildGuiPack } from './gui-pack.ts'; +import { loadNativeModules } from './native/native-definition.ts'; +import { resolveNativeModules } from './native/native-resolve.ts'; import { localEndpoint } from './network/local-endpoint.ts'; +import { patchSetFolders } from './patch-set.ts'; const RECORD_SUFFIX = '.jsonc'; /** Any port: the record only says whether each GUI edit matches, not what it writes. */ @@ -28,30 +31,39 @@ export interface VersionRecord { readonly exePatches: Readonly>; /** Patch id -> the variant that applies. */ readonly guiPatches: Readonly>; - /** Patch id -> why it is unavailable on this build. */ + /** Native module -> site -> the variant that locates it. */ + readonly nativeModules: Readonly>>>; + /** Value name -> value, as the hook library receives them (native-settings.ts). */ + readonly nativeValues: Readonly>; + /** Patch id (`native/` for native modules) -> why it is unavailable on this build. */ readonly unavailable: Readonly>; } export interface RecordInputs { readonly executable: Uint8Array; readonly guiPack: Uint8Array; - readonly exePatches: string; - readonly guiPatches: string; + /** Root of the patch set (patch-set.ts). */ + readonly patches: string; } /** Check every patch against the stock files of one build. */ export function checkGameBuild(inputs: RecordInputs): VersionRecord { const gameVersion = executableVersion(inputs.executable); if (!gameVersion) throw new DefinitionError('the executable has no version resource'); - const exePlan = planPatches(new PeImage(inputs.executable), loadPatches(inputs.exePatches)); - const gui = rebuildGuiPack(inputs.guiPack, localEndpoint(CHECK_PORT), inputs.guiPatches); + const folders = patchSetFolders(inputs.patches); + const image = new PeImage(inputs.executable); + const exePlan = planPatches(image, loadPatches(folders.exe)); + const gui = rebuildGuiPack(inputs.guiPack, localEndpoint(CHECK_PORT), folders.gui); + const native = resolveNativeModules(image, loadNativeModules(folders.native)); return { gameVersion, executableSha256: sha256(inputs.executable), guiPackSha256: sha256(inputs.guiPack), exePatches: Object.fromEntries(exePlan.writes.map((write) => [write.patchId, { variant: write.variant, rva: `0x${write.rva.toString(16)}` }])), guiPatches: Object.fromEntries(gui.applied.map((item) => [item.patch.id, { variant: item.variant.writtenFor }])), - unavailable: Object.fromEntries([...exePlan.failures, ...gui.failures].map((failure) => [failure.patchId, failure.reason])), + nativeModules: Object.fromEntries([...native.available].map(([module, sites]) => [module, Object.fromEntries(sites)])), + nativeValues: Object.fromEntries([...native.values].sort(([a], [b]) => a.localeCompare(b)).map(([name, value]) => [name, hexValue(value)])), + unavailable: Object.fromEntries([...exePlan.failures, ...gui.failures, ...native.failures].map((failure) => [failure.patchId, failure.reason])), }; } @@ -62,6 +74,8 @@ export function formatVersionRecord(record: VersionRecord): string { gui_pack_sha256: record.guiPackSha256, exe_patches: record.exePatches, gui_patches: record.guiPatches, + native_modules: record.nativeModules, + native_values: record.nativeValues, unavailable: record.unavailable, }; return `// Patch check results for this game build; written by scripts/record-game-version.ts.\n${JSON.stringify(body, null, 2)}\n`; @@ -79,9 +93,9 @@ export function loadVersionRecords(folder: string): VersionRecord[] { .sort((left, right) => compareVersions(left.gameVersion, right.gameVersion)); } -/** The game versions that have a record. */ -export function recordedGameVersions(folder: string): string[] { - return loadVersionRecords(folder).map((record) => record.gameVersion); +/** The game versions the patch set `patches` has a record for. */ +export function recordedGameVersions(patches: string): string[] { + return loadVersionRecords(patchSetFolders(patches).versions).map((record) => record.gameVersion); } function readRecord(path: string): VersionRecord { @@ -94,6 +108,8 @@ function readRecord(path: string): VersionRecord { guiPackSha256: requiredString(raw.gui_pack_sha256, `${path} gui_pack_sha256`), exePatches: asObject(raw.exe_patches, `${path} exe_patches`) as VersionRecord['exePatches'], guiPatches: asObject(raw.gui_patches, `${path} gui_patches`) as VersionRecord['guiPatches'], + nativeModules: asObject(raw.native_modules ?? {}, `${path} native_modules`) as VersionRecord['nativeModules'], + nativeValues: asObject(raw.native_values ?? {}, `${path} native_values`) as VersionRecord['nativeValues'], unavailable: asObject(raw.unavailable ?? {}, `${path} unavailable`) as VersionRecord['unavailable'], }; } @@ -108,6 +124,10 @@ export function compareVersions(left: string, right: string): number { return 0; } +function hexValue(value: number): string { + return value < 0 ? `-0x${(-value).toString(16)}` : `0x${value.toString(16)}`; +} + function sha256(data: Uint8Array): string { return createHash('sha256').update(data).digest('hex'); } diff --git a/patches/native/local_mp_actions.jsonc b/patches/native/local_mp_actions.jsonc new file mode 100644 index 0000000..265b521 --- /dev/null +++ b/patches/native/local_mp_actions.jsonc @@ -0,0 +1,86 @@ +// LocalMP construction and chat host (native/wto-net/src/local_mp_actions.c): both teams' countries +// and the AI vehicle pool, and an MPChat host that delivers the player's messages. +// Without it: each side has a single country, and chat messages are not delivered. +{ + "module": "local_mp_actions", + "features": [ + "K-AI opponents and teammates", + "K-Chat and radio" + ], + "requires": [ + "local_mp_core" + ], + "sites": { + // Multiplayer::initMPChat. + // 2.61.0.37: 0x5bd6a0 + "mp_init_chat": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 54 56 57 53 48 83 ec 48 48 89 d7 48 89 ce 48 8b 05 ?? ?? ?? ?? 48 85 c0 74 ?? c6 00 01 48 8b 9e 00 02 00 00" + } + } + ] + }, + // Multiplayer MPChat pointer. + // 2.61.0.37: 0x5bd732 (mov rbx, qword ptr [rsi + 0x1f0]; test rbx, rbx; je 0x5bd7e0) + "mp_chat": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "mp_init_chat", + "pattern": "48 8b 9e ?? ?? ?? ?? 48 85 db 0f 84 ?? ?? ?? ??", + "captures": { + "mp_chat": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + }, + // BotSystem setup (refers to "botDeviationLimits"). + // 2.61.0.37: 0x11af3f0 + "bot_system_setup": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "botDeviationLimits", + "target": "function" + } + } + ] + }, + // Multiplayer country vectors of both teams. + // 2.61.0.37: 0x11afd9f (mov rbx, qword ptr [r10 + 0x150]; mov r14, qword ptr [r10 + 0x170]) + "mp_team_countries": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "bot_system_setup", + "pattern": "49 8b 9a ?? ?? ?? ?? 4d 8b b2 ?? ?? ?? ??", + "captures": { + "team1_countries": { + "offset": 3, + "type": "u32" + }, + "team2_countries": { + "offset": 10, + "type": "u32" + } + } + } + } + ] + } + } +} diff --git a/patches/native/local_mp_awards.jsonc b/patches/native/local_mp_awards.jsonc new file mode 100644 index 0000000..a117e48 --- /dev/null +++ b/patches/native/local_mp_awards.jsonc @@ -0,0 +1,195 @@ +// In-battle award events (native/wto-net/src/local_mp_awards.c): the stock InBattleReward HUD event +// and the facts sent to the local server for awards. +// Without it: no reward banners and no battle awards in LocalMP battles. +{ + "module": "local_mp_awards", + "features": [ + "L-Battle awards" + ], + "requires": [ + "local_mp_core" + ], + "sites": { + // GameSaveData::addScoreMessage. + // 2.61.0.37: 0x189a8e0 + "add_score_message": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 38 01 00 00 45 89 c5 41 8d 45 fd" + } + } + ] + }, + // DataBlock::DataBlock. + // 2.61.0.37: 0x189b99c (call 0x3093000; cmp dword ptr [rsp + 0x68], 0; mov ebx, dword ptr [rsp + 0x104]) + "score_msg_blk_ctor": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "add_score_message", + "pattern": "e8 ?? ?? ?? ?? 83 7c 24 68 00 8b 9c 24 04 01 00 00", + "captures": { + "call": { + "offset": 1, + "type": "rel32" + } + } + } + } + ] + }, + // DataBlock set string. + // 2.61.0.37: 0x189ba34 (call 0x3094950; mov dword ptr [rsp + 0x78], ebp; cmp dword ptr [rsp + 0xa4], -1) + "score_msg_blk_set_str": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "add_score_message", + "pattern": "e8 ?? ?? ?? ?? 89 6c 24 78 83 bc 24 a4 00 00 00 ff", + "captures": { + "call": { + "offset": 1, + "type": "rel32" + } + } + } + } + ] + }, + // DataBlock make owned. + // 2.61.0.37: 0x189ba4f (call 0x30998c0; lea rdx, [rip + 0x5fc2664]; lea rcx, [rsp + 0x90]; ...) + "score_msg_blk_to_owned": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "add_score_message", + "pattern": "e8 ?? ?? ?? ?? 48 8d 15 ?? ?? ?? ?? 48 8d 8c 24 90 00 00 00 4c 8d 44 24 78 e8 ?? ?? ?? ?? 44 89 74 24 78", + "captures": { + "call": { + "offset": 1, + "type": "rel32" + } + } + } + } + ] + }, + // DataBlock set int. + // 2.61.0.37: 0x189ba68 (call 0x3095130; mov dword ptr [rsp + 0x78], r14d; cmp dword ptr [rsp + 0xa4], -1) + "score_msg_blk_set_int": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "add_score_message", + "pattern": "e8 ?? ?? ?? ?? 44 89 74 24 78 83 bc 24 a4 00 00 00 ff", + "captures": { + "call": { + "offset": 1, + "type": "rel32" + } + } + } + } + ] + }, + // The HUD script event queue in GameSaveData and its queue function. + // 2.61.0.37: 0x189be3b (add rcx, 0xae8; lea rdx, [rip + 0x5fcb75d]; lea r8, [rsp + 0x90]; ...) + "score_msg_hud_queue": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "add_score_message", + "pattern": "48 81 c1 ?? ?? ?? ?? 48 8d 15 ?? ?? ?? ?? 4c 8d 84 24 90 00 00 00 e8 ?? ?? ?? ??", + "captures": { + "queue": { + "offset": 3, + "type": "u32" + }, + "call": { + "offset": 23, + "type": "rel32" + } + } + } + } + ] + }, + // DataBlock::~DataBlock. + // 2.61.0.37: 0x189be90 (call 0x3093a60; cmp ebp, 0xe; setne al; ...) + "score_msg_blk_dtor": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "add_score_message", + "pattern": "e8 ?? ?? ?? ?? 83 fd 0e 0f 95 c0 0f b6 4c 24 52", + "captures": { + "call": { + "offset": 1, + "type": "rel32" + } + } + } + } + ] + }, + // Unit info expClass string. + // 2.61.0.37: 0x189bb19 (mov rax, qword ptr [r15 + 0x1020]; mov rax, qword ptr [rax + 0x38]; test rax, rax) + "score_msg_exp_class": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "add_score_message", + "pattern": "49 8b 87 ?? ?? ?? ?? 48 8b 40 ?? 48 85 c0", + "captures": { + "unit_info": { + "offset": 3, + "type": "u32" + }, + "exp_class": { + "offset": 10, + "type": "u8" + } + } + } + } + ] + }, + // The global GameSaveData. + // 2.61.0.37: 0x427e19 (mov rcx, qword ptr [rip + 0x77ccb38]; test rcx, rcx; je 0x427f77; ...) + "game_save_data": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "iground_on_dead", + "pattern": "48 8b 0d ?? ?? ?? ?? 48 85 c9 0f 84 ?? ?? ?? ?? 48 8b 05 ?? ?? ?? ??", + "captures": { + "game_save_data": { + "offset": 3, + "type": "rel32" + } + } + } + } + ] + } + } +} diff --git a/patches/native/local_mp_core.jsonc b/patches/native/local_mp_core.jsonc new file mode 100644 index 0000000..b21c634 --- /dev/null +++ b/patches/native/local_mp_core.jsonc @@ -0,0 +1,434 @@ +// Core of the LocalMP host bridge (native/wto-net/src/local_mp_core.c): the engine globals, the +// MPlayer table, the allocator and the helpers every other LocalMP module uses. +// Without it: no LocalMP module runs, the battle host misses everything the dedicated server did. +{ + "module": "local_mp_core", + "features": [], + "requires": [], + "sites": { + // getDisabledSlotsMask: reads g_multiplayer, the App and the local MPlayer, and the MPlayer broken + // slots mask (+0x4a0 | broken slots). + // 2.61.0.37: 0x6bb480 + "disabled_slots_mask": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "31 c0 48 83 3d ?? ?? ?? ?? 00 74 ?? 48 8b 0d ?? ?? ?? ?? 0f b6 89 f3 00 00 00 f6 c1 01 74 ?? 48 8b 0d ?? ?? ?? ?? 48 85 c9 74 ?? 8b 81 a0 04 00 00 0b 81 d0 04 00 00 c3", + "captures": { + "multiplayer": { + "offset": 5, + "type": "rel32", + "end": 10 + }, + "app": { + "offset": 15, + "type": "rel32" + }, + "local_mplayer": { + "offset": 34, + "type": "rel32" + }, + "mplayer_broken_slots": { + "offset": 51, + "type": "u32" + } + } + } + } + ] + }, + // doRespawnPlayer (App method): App score rules pointer, and the global hero unit. + // 2.61.0.37: 0xc6c010 + "do_respawn_player": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 57 53 48 81 ec 40 01 00 00 44 0f 29 84 24 30 01 00 00 0f 29 bc 24 20 01 00 00 0f 29 b4 24 10 01 00 00 48 8b 91 e0 03 00 00 48 c7 c0 ff ff ff ff 48 85 d2 0f 84 ?? ?? ?? ?? 8b 92 f0 00 00 00 83 fa 01 0f 85 ?? ?? ?? ?? f3 0f 10 81 e4 06 00 00 0f 57 c9 0f 2e c1 0f 83 ?? ?? ?? ?? 4c 8b 05 ?? ?? ?? ?? 40 b6 01 4d 85 c0 0f 84 ?? ?? ?? ?? f6 05 ?? ?? ?? ?? 04 0f 84 ?? ?? ?? ?? 48 8b 15 ?? ?? ?? ?? 48 85 d2 0f 84 ?? ?? ?? ??", + "captures": { + "app_score_rules": { + "offset": 38, + "type": "u32" + }, + "hero": { + "offset": 128, + "type": "rel32" + } + } + } + } + ] + }, + // MissionSettings::getPlayerCountry: Multiplayer isLocalMP flag, and the MPlayer table and its count. + // 2.61.0.37: 0x12773b0 + "get_player_country": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 48 83 ec 40 4c 89 c0 4c 8b 05 ?? ?? ?? ?? 4d 85 c0 0f 84 ?? ?? ?? ?? 45 31 d2 41 80 78 61 00 44 0f 44 d2 81 fa fa 00 00 00 44 0f 45 d2 44 3b 15 ?? ?? ?? ?? 73 ?? 4c 8b 1d ?? ?? ?? ??", + "captures": { + "mp_is_local_mp": { + "offset": 30, + "type": "u8" + }, + "player_count": { + "offset": 49, + "type": "rel32" + }, + "player_table": { + "offset": 58, + "type": "rel32" + } + } + } + } + ] + }, + // Script binding get_local_player_country: the global MissionSettings. + // 2.61.0.37: 0x179f400 + "sq_local_country": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 56 56 57 53 48 83 ec 68 48 89 ce 48 8b 05 ?? ?? ?? ?? 48 85 c0 74 ?? 0f b6 50 08 48 8d 0d ?? ?? ?? ?? 4c 8d 44 24 20 41 b9 40 00 00 00 e8 ?? ?? ?? ?? 48 89 c7", + "captures": { + "mission_settings": { + "offset": 31, + "type": "rel32" + } + } + } + } + ] + }, + // ChangeUnitReflection destructor. + // 2.61.0.37: 0x548f20 + "refl_dtor": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 57 53 48 83 ec 40 48 89 ce 48 8d 05 ?? ?? ?? ?? 48 89 01 48 8b 89 b0 01 00 00 48 85 c9 74 ?? e8 ?? ?? ?? ?? 48 8b be 90 01 00 00 48 8b 9e 98 01 00 00 48 39 df" + } + } + ] + }, + // GameSaveData::aircraftChangeResultFromHost: the change request inside the economic state. + // 2.61.0.37: 0xebc490 + "aircraft_change_result": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 56 57 53 48 83 ec 50 41 89 d0 48 89 ce 48 81 c1 78 f5 00 00 48 89 f2 e8 ?? ?? ?? ?? 84 c0 0f 84 ?? ?? ?? ?? 48 8b 9e 78 f5 00 00 48 85 db 48 8d 3d ?? ?? ?? ?? 48 0f 44 df", + "captures": { + "econ_change_req": { + "offset": 20, + "type": "u32" + } + } + } + } + ] + }, + // setPlayerGuiState(player id, state). + // 2.61.0.37: 0x155f5f0 + "set_player_gui_state": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 54 56 57 55 53 48 83 ec 40 89 d6 48 8b 15 ?? ?? ?? ?? 48 85 d2 74 ?? 80 7a 60 00 0f 84 ?? ?? ?? ?? 85 c9 78 ?? 31 c0 80 7a 61 00 0f 44 c1 81 f9 fa 00 00 00 0f 45 c1 eb ?? 89 c8" + } + } + ] + }, + // getUnitByEid (a leaf function without unwind info). + // 2.61.0.37: 0x110b960 + "get_unit_by_eid": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "39 0d ?? ?? ?? ?? 74 2f 89 ca c1 ea 0a 3b 15 ?? ?? ?? ??" + } + } + ] + }, + // Unit::setOwningMPlayer(unit, mplayer, ...): its start reads the MPlayer player id. + // 2.61.0.37: 0xfce410 (push r15; push r14; push r13; ...) + "set_owning_mplayer": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 00 00 00 44 89 c3 48 89 d7 48 89 ce 48 85 d2 74 ?? 0f b6 6f ??", + "captures": { + "mp_pid": { + "offset": 36, + "type": "u8" + } + } + } + } + ] + }, + // IGroundModel::onBecameDead. + // 2.61.0.37: 0x427400 + "iground_on_dead": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 01 00 00 44 0f 29 8c 24 90 01 00 00 44 0f 29 84 24 80 01 00 00 0f 29 bc 24 70 01 00 00 0f 29 b4 24 60 01 00 00 89 d3" + } + } + ] + }, + // DataBlock::getStr wrapper. + // 2.61.0.37: 0x3094400 + "datablock_get_str": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "48 83 ec 28 4c 89 44 24 20 4c 8d 44 24 20 e8 ?? ?? ?? ?? 90 48 83 c4 28 c3 cc cc cc cc cc cc cc 41 57" + } + } + ] + }, + // DataBlock::setFrom; its first call is the Dagor allocator. + // 2.61.0.37: 0x3093210 + "datablock_set_from": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 48 48 89 d7 48 89 ce 66 2e 0f 1f 84 00 00 00 00 00 b9 90 00 00 00 e8 ?? ?? ?? ?? 48 85 c0 75 ?? 48 8b 05 ?? ?? ?? ??", + "captures": { + "dagmem_alloc": { + "offset": 38, + "type": "rel32" + } + } + } + } + ] + }, + // Multiplayer::constructLocalMP: builds the chat host at +0x1f8 and sets isHost and isLocalMP (one word). + // 2.61.0.37: 0x5bd960 + "mp_construct_local": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 57 53 48 83 ec 60 48 89 ce 48 81 c1 f8 00 00 00 e8 ?? ?? ?? ?? 66 c7 46 60 01 01", + "captures": { + "mp_chat_host": { + "offset": 13, + "type": "u32" + }, + "mp_is_host": { + "offset": 25, + "type": "u8" + } + } + } + } + ] + }, + // GuiState::update. + // 2.61.0.37: 0x155f490 + "gui_state_update": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 57 48 83 ec 48 48 89 ce f3 0f 10 41 08 f3 0f 58 c1 f3 0f 11 41 08 f3 0f 10 51 10 0f 57 c0 0f 2e c2 73 ?? f3 0f 5c d1 f3 0f 11 56 10 48 8b 0d ?? ?? ?? ?? b0 01 0f 2e 81 e4 06 00 00 76 ??" + } + } + ] + }, + // App -> economic state holder -> GameEconomicState. + // 2.61.0.37: 0x155f5b7 (mov rax, qword ptr [rax + 0x3f0]; mov rax, qword ptr [rax + 0x9a8]) + "app_econ_state": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "gui_state_update", + "pattern": "48 8b 80 ?? ?? ?? ?? 48 8b 80 ?? ?? ?? ??", + "captures": { + "econ_holder": { + "offset": 3, + "type": "u32" + }, + "econ_state": { + "offset": 10, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer::initFromMatching: team of the matching info, the MPlayer team, and the user id it logs. + // 2.61.0.37: 0x59e95f (mov edx, dword ptr [rdi + 4]; test rdx, rdx; je 0x59ea61; ...) + "mplayer_matching": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "MPlayer::setMatchingPlayerInfo", + "pattern": "8b 57 ?? 48 85 d2 0f 84 ?? ?? ?? ?? 83 fa 02 0f 87 ?? ?? ?? ?? 8b 86 80 07 00 00 83 f8 08 0f 85 ?? ?? ?? ?? 0f b6 86 ?? ?? ?? ?? 85 c0 0f 94 c1 39 c2 41 0f 94 c0 41 08 c8 75 ?? 48 8b 8e ?? ?? ?? ?? 4c 8d 05 ?? ?? ?? ??", + "lea_at": 66, + "captures": { + "match_team": { + "offset": 2, + "type": "u8" + }, + "mp_team": { + "offset": 39, + "type": "u32" + }, + "mp_user_id": { + "offset": 62, + "type": "u32" + } + } + } + } + ] + }, + // Unit::changeAircraft(unit, reflection). + // 2.61.0.37: 0xff1020 + "unit_change_aircraft": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 56 57 55 53 48 81 ec 88 00 00 00 48 89 ce 8b 81 90 00 00 00 a8 10 75 ?? 80 be 1a 0f 00 00 00 75 ?? 48 8b 05 ?? ?? ?? ?? 0f b6 80 f3 00 00 00 0f b6 0d ?? ?? ?? ?? 08 c8 a8 01 74 ??" + } + } + ] + }, + // Unit type (word) compared with helicopter. + // 2.61.0.37: 0xff120f (cmp word ptr [rsi + 0x8c], 0xd; jne 0xff1369) + "unit_type": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "unit_change_aircraft", + "pattern": "66 83 be ?? ?? ?? ?? 0d 0f 85 ?? ?? ?? ??", + "captures": { + "unit_type": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + }, + // Unit -> unit info -> unit name. + // 2.61.0.37: 0xff12a5 (mov rax, qword ptr [rsi + 0x1020]; mov rax, qword ptr [rax + 0x10]; test rax, rax; ...) + "unit_info_name": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "unit_change_aircraft", + "pattern": "48 8b 86 ?? ?? ?? ?? 48 8b 40 ?? 48 85 c0 48 8d 0d ?? ?? ?? ?? 48 0f 44 c1 48 8b 52 50 48 89 44 24 48 c7 44 24 40 01 00 00 00 48 85 d2 48 0f 44 d1 48 89 54 24 58 c7 44 24 50 01 00 00 00 48 8d 15 ?? ?? ?? ?? eb ??", + "captures": { + "unit_info": { + "offset": 3, + "type": "u32" + }, + "info_name": { + "offset": 10, + "type": "u8" + } + } + } + } + ] + }, + // Unit owning MPlayer. + // 2.61.0.37: 0xfce718 (cmp qword ptr [rsi + 0xf98], rdi; je 0xfce7ed) + "unit_mplayer": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "set_owning_mplayer", + "pattern": "48 39 be ?? ?? ?? ?? 0f 84 ?? ?? ?? ??", + "captures": { + "unit_mplayer": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + }, + // The Dagor default allocator global. + // 2.61.0.37: 0x548fab (mov rcx, qword ptr [rip + 0x7adc2e6]; mov rax, qword ptr [rcx]; call qword ptr [rax + 0x40]; ...) + "refl_stdmem": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "refl_dtor", + "pattern": "48 8b 0d ?? ?? ?? ?? 48 8b 01 ff 50 40 48 8b 56 60", + "captures": { + "stdmem": { + "offset": 3, + "type": "rel32" + } + } + } + } + ] + }, + // The mission settings loader (refers to "customScoreParams"). + // 2.61.0.37: 0x12657a0 + "mission_settings_load": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "customScoreParams", + "target": "function" + } + } + ] + } + } +} diff --git a/patches/native/local_mp_events.jsonc b/patches/native/local_mp_events.jsonc new file mode 100644 index 0000000..ad104da --- /dev/null +++ b/patches/native/local_mp_events.jsonc @@ -0,0 +1,126 @@ +// Combat events on the LocalMP host (native/wto-net/src/local_mp_events.c): assists, captures, hits, +// critical and severe damage, counted and reported as award facts. +// Without it: assists, captures and damage events score nothing in LocalMP battles. +{ + "module": "local_mp_events", + "features": [ + "K-Kill, assist and capture scoring", + "L-Battle awards" + ], + "requires": [ + "local_mp_core", + "local_mp_awards", + "local_mp_kills" + ], + "sites": { + // dispatchAssist. + // 2.61.0.37: 0x35beb0 + "dispatch_assist": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 78 0f 29 7c 24 60 0f 29 74 24 50 0f 28 f3 4c 89 c6 48 89 d7 48 89 cb 48 8b 05 ?? ?? ?? ?? 48 85 c9 7e ?? 48 85 c0" + } + } + ] + }, + // A caller of the capture zone dispatch; captures the callee. + // 2.61.0.37: 0x3db0e0 + "caller_capture_zone": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 38 44 0f b7 72 02 44 8b 7a 04 4c 8b 62 08 4c 8b 6a 18 49 8d 85 88 06 00 00 48 89 44 24 30 49 8d 85 50 06 00 00 48 89 44 24 28 eb ?? 48 8b 90 08 0e 00 00 89 d1 83 e1 01 0b 0d ?? ?? ?? ?? 3b 88 14 0e 00 00 0f 85 ?? ?? ?? ?? 48 83 e2 fe 48 8b 82 98 0f 00 00 48 8b 88 b8 00 00 00 e8 ?? ?? ?? ??", + "captures": { + "call": { + "offset": 108, + "type": "rel32" + } + } + } + } + ] + }, + // A caller of the hit / critical hit dispatch. + // 2.61.0.37: 0xff85ea + "caller_hit_crit": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "8b 0d ?? ?? ?? ?? f7 c1 00 00 08 00 75 ?? f7 c1 00 00 00 01 75 ?? 0f b6 8f 10 10 00 00 39 4e 1c 74 ?? 41 20 c0 0f b6 86 49 01 00 00 0f 57 db f3 0f 5f 9e 30 01 00 00 48 8b 4e 58 85 ed f3 0f 5d 1d ?? ?? ?? ?? 88 44 24 30 0f 9f 44 24 28 44 88 44 24 20 48 89 fa 49 89 f0 e8 ?? ?? ?? ??", + "captures": { + "call": { + "offset": 90, + "type": "rel32" + } + } + } + } + ] + }, + // A caller of the severe damage dispatch. + // 2.61.0.37: 0xe55afa + "caller_severe_damage": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "66 83 be b0 06 00 00 ff 0f 85 ?? ?? ?? ?? 48 89 f1 e8 ?? ?? ?? ?? 84 c0 0f 84 ?? ?? ?? ?? 48 8d 9e b0 06 00 00 48 8b 4f 58 48 89 f2 49 89 f8 e8 ?? ?? ?? ?? 48 89 f1 48 89 fa e8 ?? ?? ?? ?? 0f b6 ae d4 06 00 00", + "captures": { + "call": { + "offset": 48, + "type": "rel32" + } + } + } + } + ] + }, + // A caller of the naval damage dispatch. + // 2.61.0.37: 0xd048ea + "caller_naval_damage": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "66 83 b9 90 0f 00 00 01 77 ?? 66 83 ff ff 74 ?? 0f b7 c7 0f 57 d2 f3 0f 2a d0 f3 0f 59 15 ?? ?? ?? ?? eb ?? f3 0f 10 15 ?? ?? ?? ?? 48 8b 94 24 c0 03 00 00 0f b6 7c 24 5b 41 89 f9 e8 ?? ?? ?? ?? 0f 57 c0 0f 2e f0 0f 96 c0 40 08 f8 a8 01 75 ?? 48 8b 96 e8 0a 00 00 4c 8b 84 24 c0 03 00 00 49 8b 48 58 0f 28 de e8 ?? ?? ?? ??", + "captures": { + "call": { + "offset": 104, + "type": "rel32" + } + } + } + } + ] + }, + // Offender assist already reported. + // 2.61.0.37: 0x465896 (cmp byte ptr [r14 + 0x148], 0; jne 0x465620) + "offender_assist": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "iground_award_assists", + "pattern": "41 80 be ?? ?? ?? ?? 00 0f 85 ?? ?? ?? ??", + "captures": { + "assist_sent": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + } + } +} diff --git a/patches/native/local_mp_kills.jsonc b/patches/native/local_mp_kills.jsonc new file mode 100644 index 0000000..1f7b081 --- /dev/null +++ b/patches/native/local_mp_kills.jsonc @@ -0,0 +1,592 @@ +// Unit deaths and kill attribution on the LocalMP host (native/wto-net/src/local_mp_kills.c): +// scoreboard counters and battle score for every MPlayer, the local player's kills as award facts. +// Without it: kills and deaths are not counted in LocalMP battles. +{ + "module": "local_mp_kills", + "features": [ + "K-Kill, assist and capture scoring", + "K-Scoreboard" + ], + "requires": [ + "local_mp_core", + "local_mp_awards", + "local_mp_scores" + ], + "sites": { + // MPlayer::addScore. + // 2.61.0.37: 0x59f2d0 + "mplayer_add_score": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 56 57 55 53 48 81 ec 88 00 00 00 0f 29 7c 24 70 0f 29 74 24 60 48 89 ce 44 89 c0 f3 0f 2a 84 81 fc 08 00 00 0f 28 f9 f3 0f 58 c1 f3 0f 2c c8 89 8c 86 fc 08 00 00" + } + } + ] + }, + // MPlayer battle score. + // 2.61.0.37: 0x59f30d (cvtsi2ss xmm0, dword ptr [rsi + 0x8f8]; addss xmm0, xmm1) + "mplayer_score": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "mplayer_add_score", + "pattern": "f3 0f 2a 86 ?? ?? ?? ?? f3 0f 58 c1", + "captures": { + "score": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer stats replication field and payload. + // 2.61.0.37: 0x59f5f8 (lea rcx, [rsi + 0xa10]; lea r8, [rsi + 0xa30]; mov rdx, rsi; ...) + "mplayer_stat_sync": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "mplayer_add_score", + "pattern": "48 8d 8e ?? ?? ?? ?? 4c 8d 86 ?? ?? ?? ?? 48 89 f2 e8 ?? ?? ?? ?? 0f 57 c0", + "captures": { + "dirty": { + "offset": 3, + "type": "u32" + }, + "payload": { + "offset": 10, + "type": "u32" + } + } + } + } + ] + }, + // Replicated field setter that marks it dirty. + // 2.61.0.37: 0x31030a0 + "net_mark_dirty": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 57 53 48 83 ec 40 81 7a 20 44 4e 45 54 0f 85 ?? ?? ?? ?? 48 89 ce 0f b7 41 02 a8 02 75 ?? f6 42 48 02 75 ?? a8 01 75 ?? 4c 89 c7 83 c8 01 66 89 46 02" + } + } + ] + }, + // onUnitDeadOnce; skips units flagged at +0x3058. + // 2.61.0.37: 0xe5b200 + "on_unit_dead_once": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 01 00 00 44 0f 29 84 24 80 01 00 00 0f 29 bc 24 70 01 00 00 0f 29 b4 24 60 01 00 00 80 b9 58 30 00 00 00 0f 85 ?? ?? ?? ?? 48 89 ce 48 8d 54 24 38 e8 ?? ?? ?? ?? 66 83 7c 24 38 ff", + "captures": { + "skip_kill": { + "offset": 46, + "type": "u32" + } + } + } + } + ] + }, + // Unit severe damage offender: index, user id, player id. + // 2.61.0.37: 0xe5b2c7 (movzx r8d, word ptr [rsi + 0x6b0]; cmp r8w, -1; je 0xe5b340; ...) + "unit_severe": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "on_unit_dead_once", + "pattern": "44 0f b7 86 ?? ?? ?? ?? 66 41 83 f8 ff 74 ?? 4c 8b 8e ?? ?? ?? ?? 49 83 f9 ff 0f 95 c1 44 0f b6 96 ?? ?? ?? ??", + "captures": { + "severe_idx": { + "offset": 4, + "type": "u32" + }, + "severe_uid": { + "offset": 18, + "type": "u32" + }, + "severe_pid": { + "offset": 33, + "type": "u32" + } + } + } + } + ] + }, + // IGroundModel death guards. + // 2.61.0.37: 0x427490 (cmp byte ptr [rsi + 0x2101], 0; jne 0x42846f; cmp byte ptr [rsi + 0x1c19], 0) + "ground_death_flags": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "iground_on_dead", + "pattern": "80 be ?? ?? ?? ?? 00 0f 85 ?? ?? ?? ?? 80 be ?? ?? ?? ?? 00", + "captures": { + "already_dead": { + "offset": 2, + "type": "u32" + }, + "dead_silent": { + "offset": 15, + "type": "u32" + } + } + } + } + ] + }, + // IGroundModel crew bailed out. + // 2.61.0.37: 0x427a61 (cmp byte ptr [rsi + 0x3888], 0; jne 0x427d8c; mov rcx, qword ptr [rsp + 0x130]) + "ground_bailout": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "iground_on_dead", + "pattern": "80 be ?? ?? ?? ?? 00 0f 85 ?? ?? ?? ?? 48 8b 8c 24 30 01 00 00", + "captures": { + "bailout_dead": { + "offset": 2, + "type": "u32" + } + } + } + } + ] + }, + // IGroundModel offender list and the embedded killer record. + // 2.61.0.37: 0x427aad (cmp word ptr [rsi + 0x8c], 5; jne 0x427bc0; mov ecx, dword ptr [rsi + 0x17d0]; ...) + "ground_offenders": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "iground_on_dead", + "pattern": "66 83 be ?? ?? ?? ?? 05 0f 85 ?? ?? ?? ?? 8b 8e ?? ?? ?? ?? 48 85 c9 0f 84 ?? ?? ?? ?? 48 8b 86 ?? ?? ?? ?? 48 69 c9 ?? ?? ?? ?? 48 8b 96 ?? ?? ?? ?? 48 83 fa ff 41 0f 95 c3 44 0f b7 86 ?? ?? ?? ?? 44 0f b6 8e ?? ?? ?? ??", + "captures": { + "unit_type": { + "offset": 3, + "type": "u32" + }, + "offenders_count": { + "offset": 16, + "type": "u32" + }, + "offenders": { + "offset": 32, + "type": "u32" + }, + "offender_size": { + "offset": 39, + "type": "u32" + }, + "killer_uid": { + "offset": 46, + "type": "u32" + }, + "killer": { + "offset": 62, + "type": "u32" + }, + "killer_pid": { + "offset": 70, + "type": "u32" + } + } + } + } + ] + }, + // IGroundModel::awardAssists; calls the unit chooseOffender virtual first. + // 2.61.0.37: 0x465540 + "iground_award_assists": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 01 00 00 44 0f 29 94 24 90 01 00 00 44 0f 29 8c 24 80 01 00 00 44 0f 29 84 24 70 01 00 00 0f 29 bc 24 60 01 00 00 0f 29 b4 24 50 01 00 00 48 89 ce 48 8b 01 48 8d 54 24 28 41 b0 01 ff 90 98 04 00 00", + "captures": { + "choose_offender": { + "offset": 78, + "type": "u32" + } + } + } + } + ] + }, + // Offender army, user id and player id. + // 2.61.0.37: 0x465832 (movzx eax, byte ptr [rsi + 0x1010]; cmp dword ptr [r14 + 0x1c], eax; je 0x465620; ...) + "offender_fields": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "iground_award_assists", + "pattern": "0f b6 86 ?? ?? ?? ?? 41 39 46 ?? 0f 84 ?? ?? ?? ?? 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 49 8b 56 ?? 48 83 fa ff 41 0f 95 c0 41 0f b6 46 ??", + "captures": { + "unit_army": { + "offset": 3, + "type": "u32" + }, + "army": { + "offset": 10, + "type": "u8" + }, + "uid": { + "offset": 33, + "type": "u8" + }, + "pid": { + "offset": 46, + "type": "u8" + } + } + } + } + ] + }, + // MPlayer "kills" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f0e4 (movsx r8d, word ptr [rsi + 0x9d8]; mov rcx, r14; lea rdx, [rip + 0x6614963]) + "stat_kills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "kills", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "groundKills" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f0fb (movsx r8d, word ptr [rsi + 0x9de]; mov rcx, r14; lea rdx, [rip + 0x6614b0a]) + "stat_ground_kills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "groundKills", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "humanKills" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f112 (movsx r8d, word ptr [rsi + 0x9e0]; mov rcx, r14; lea rdx, [rip + 0x66149da]) + "stat_human_kills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "humanKills", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "navalKills" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f129 (movsx r8d, word ptr [rsi + 0x9e2]; mov rcx, r14; lea rdx, [rip + 0x6614a3b]) + "stat_naval_kills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "navalKills", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "teamKills" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f140 (movsx r8d, word ptr [rsi + 0x9da]; mov rcx, r14; lea rdx, [rip + 0x6614a01]) + "stat_team_kills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "teamKills", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "aiKills" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f157 (movsx r8d, word ptr [rsi + 0x9e4]; mov rcx, r14; lea rdx, [rip + 0x6614a84]) + "stat_ai_kills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "aiKills", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "aiGroundKills" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f16e (movsx r8d, word ptr [rsi + 0x9e6]; mov rcx, r14; lea rdx, [rip + 0x6614ade]) + "stat_ai_ground_kills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "aiGroundKills", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "aiNavalKills" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f185 (movsx r8d, word ptr [rsi + 0x9e8]; mov rcx, r14; lea rdx, [rip + 0x6614a21]) + "stat_ai_naval_kills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "aiNavalKills", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "assists" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f19c (movsx r8d, word ptr [rsi + 0x9ec]; mov rcx, r14; lea rdx, [rip + 0x65fb6b2]) + "stat_assists": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "assists", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "deaths" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f1b3 (movsx r8d, word ptr [rsi + 0x9dc]; mov rcx, r14; lea rdx, [rip + 0x6618733]) + "stat_deaths": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "deaths", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "captureZone" counter, read where the scoreboard row writes it. + // 2.61.0.37: 0x111f1ca (movsx r8d, word ptr [rsi + 0x9ee]; mov rcx, r14; lea rdx, [rip + 0x67096a5]) + "stat_capture_zone": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "captureZone", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 11, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer scoreboard score: the larger of the short score and the battle score. + // 2.61.0.37: 0x111f1f7 (movsx r8d, word ptr [rsi + 0x2d8]; mov eax, dword ptr [rsi + 0x8f8]; cmp eax, r8d; ...) + "stat_score": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "score", + "pattern": "44 0f bf 86 ?? ?? ?? ?? 8b 86 ?? ?? ?? ?? 44 39 c0 44 0f 4f c0 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 24, + "captures": { + "fallback": { + "offset": 4, + "type": "u32" + }, + "score": { + "offset": 10, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "awardDamage" counter. + // 2.61.0.37: 0x111f21b (mov r8d, dword ptr [rsi + 0xa00]; mov rcx, r14; lea rdx, [rip + 0x67392d6]) + "stat_award_damage": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "awardDamage", + "pattern": "44 8b 86 ?? ?? ?? ?? 4c 89 f1 48 8d 15 ?? ?? ?? ??", + "lea_at": 10, + "captures": { + "field": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "airSevereDamage" counter. + // 2.61.0.37: 0x129349c (movsx rax, word ptr [rdi + 0xa06]; mov qword ptr [rsp + 0x30], rax; mov byte ptr [rsp + 0x20], 0; ...) + "stat_air_severe": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "airSevereDamage", + "pattern": "48 0f bf 87 ?? ?? ?? ?? 48 89 44 24 30 c6 44 24 20 00 48 8d 15 ?? ?? ?? ??", + "lea_at": 18, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer "shipSevereDamage" counter. + // 2.61.0.37: 0x12934c8 (movsx rax, word ptr [rdi + 0xa08]; mov qword ptr [rsp + 0x30], rax; mov byte ptr [rsp + 0x20], 0; ...) + "stat_ship_severe": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "shipSevereDamage", + "pattern": "48 0f bf 87 ?? ?? ?? ?? 48 89 44 24 30 c6 44 24 20 00 48 8d 15 ?? ?? ?? ??", + "lea_at": 18, + "captures": { + "field": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + } + } +} diff --git a/patches/native/local_mp_loadout.jsonc b/patches/native/local_mp_loadout.jsonc new file mode 100644 index 0000000..f55158b --- /dev/null +++ b/patches/native/local_mp_loadout.jsonc @@ -0,0 +1,429 @@ +// Vehicle selection on the LocalMP host (native/wto-net/src/local_mp_loadout.c): the client build has +// no receiver for SemChangeAircraftRequest, so the host builds the ChangeUnitReflection itself. +// Request fields with no reader in the client (respawn base, spare type) and the fuel member are +// kept in the module; see the module header. +// Without it: pressing "To battle!" in a LocalMP battle does nothing. +{ + "module": "local_mp_loadout", + "features": [ + "K-Spawn score and respawns" + ], + "requires": [ + "local_mp_core", + "local_mp_players" + ], + "sites": { + // SemChangeAircraftRequest::send. + // 2.61.0.37: 0xccba20 + "sem_change_aircraft_send": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec f8 01 00 00 44 0f 29 84 24 e0 01 00 00 0f 29 bc 24 d0 01 00 00 0f 29 b4 24 c0 01 00 00 4c 89 cf 4c 89 c3 49 89 d7 48 89 ce 8b 05 ?? ?? ?? ?? 65 48 8b 0c 25 58 00 00 00" + } + } + ] + }, + // ChangeUnitReflection constructor. + // 2.61.0.37: 0xcccdc0 + "refl_ctor": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 48 83 ec 50 0f 29 74 24 40 48 89 ce 66 c7 41 08 ff ff c7 41 0c ff ff ff ff 0f 57 f6 0f 11 71 10 c7 41 20 44 4e 45 54 0f 11 71 28 0f 11 71 38" + } + } + ] + }, + // DataBlock destructor. + // 2.61.0.37: 0x3093a60 + "datablock_dtor": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 54 56 57 53 48 83 ec 38 0f 29 74 24 20 48 8b 41 18" + } + } + ] + }, + // BulletSetVec::assign. + // 2.61.0.37: 0x4f1410 + "bullet_vec_assign": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 58 4c 89 c5 49 89 d7 48 89 ce 4c 89 c3 48 29 d3 4c 8b 01 48 8b 41 10 4c 29 c0 48 39 c3 0f 86 ?? ?? ?? ?? 48 89 d9" + } + } + ] + }, + // GameSaveData::getDecalsBlk. + // 2.61.0.37: 0x2df9a0 + "get_decals_blk": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 88 00 00 00 44 0f 29 44 24 70 0f 29 7c 24 60 0f 29 74 24 50 4d 89 cf" + } + } + ] + }, + // GameSaveData::getAttachablesBlk. + // 2.61.0.37: 0x2e08f0 + "get_attachables_blk": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 38 48 89 d7 4d 85 c0" + } + } + ] + }, + // str_hash_fnv1. + // 2.61.0.37: 0x21b670 + "str_hash_fnv1": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 56 56 57 53 49 89 d0 49 ba db 28 b4 a0 d1 7e 03 e7 48 83 fa 10 77 76" + } + } + ] + }, + // OAHashNameMap::addNameId. + // 2.61.0.37: 0xed4b0 + "namemap_add_name_id": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 38 44 89 cf 48 89 ce 80 79 4b 00" + } + } + ] + }, + // UnitCrewSkills::initFromSave. + // 2.61.0.37: 0x1032130 + "crew_skills_init": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 56 56 57 55 53 48 81 ec 90 00 00 00 0f 29 b4 24 80 00 00 00 0f 28 f3" + } + } + ] + }, + // ChangeUnitReflection members the destructor frees: bullet sets, modification name maps, blocks. + // 2.61.0.37: 0x548f45 (mov rdi, qword ptr [rsi + 0x190]; mov rbx, qword ptr [rsi + 0x198]; cmp rdi, rbx; ...) + "refl_objects": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "refl_dtor", + "pattern": "48 8b be ?? ?? ?? ?? 48 8b 9e 98 01 00 00 48 39 df 0f 85 ?? ?? ?? ?? 48 85 ff 74 ?? 48 89 f9 e8 ?? ?? ?? ?? 48 8d 8e ?? ?? ?? ?? e8 ?? ?? ?? ?? 48 8d 8e ?? ?? ?? ?? e8 ?? ?? ?? ?? 48 8d 8e ?? ?? ?? ?? e8 ?? ?? ?? ?? 48 8d 8e ?? ?? ?? ?? e8 ?? ?? ?? ?? 48 8d 4e ??", + "captures": { + "bullets": { + "offset": 3, + "type": "u32" + }, + "disabled_mods": { + "offset": 39, + "type": "u32" + }, + "enabled_mods": { + "offset": 51, + "type": "u32" + }, + "custom_preset": { + "offset": 63, + "type": "u32" + }, + "attachables": { + "offset": 75, + "type": "u32" + }, + "decals": { + "offset": 87, + "type": "u8" + } + } + } + } + ] + }, + // ChangeUnitReflection name strings the destructor frees. + // 2.61.0.37: 0x548fa2 (mov rdx, qword ptr [rsi + 0x68]; test rdx, rdx; je 0x548fb8; ...) + "refl_names": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "refl_dtor", + "pattern": "48 8b 56 ?? 48 85 d2 74 ?? 48 8b 0d ?? ?? ?? ?? 48 8b 01 ff 50 40 48 8b 56 ?? 48 85 d2 74 ?? 48 8b 0d ?? ?? ?? ?? 48 8b 01 ff 50 40 48 8b 56 ?? 48 85 d2 74 ?? 48 8b 0d ?? ?? ?? ?? 48 8b 01 ff 50 40 48 8b 56 ??", + "captures": { + "custom_skin": { + "offset": 3, + "type": "u8" + }, + "skin": { + "offset": 25, + "type": "u8" + }, + "weapon": { + "offset": 47, + "type": "u8" + }, + "unit": { + "offset": 69, + "type": "u8" + } + } + } + } + ] + }, + // ChangeUnitReflection flags. + // 2.61.0.37: 0xff139a (mov eax, dword ptr [rdx + 0xd0]; test al, 0x20; jne 0xff13ad; ...) + "refl_flags": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "unit_change_aircraft", + "pattern": "8b 82 ?? ?? ?? ?? a8 20 75 ?? 83 c8 10", + "captures": { + "flags": { + "offset": 2, + "type": "u32" + } + } + } + } + ] + }, + // ChangeUnitReflection gun convergence. + // 2.61.0.37: 0xff13ce (movss xmm0, dword ptr [rdx + 0xdc]; movss dword ptr [rsp + 0x40], xmm0; movss xmm1, dword ptr [rsi + 0xb20]) + "refl_targeting": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "unit_change_aircraft", + "pattern": "f3 0f 10 82 ?? ?? ?? ?? f3 0f 11 44 24 40 f3 0f 10 8e 20 0b 00 00", + "captures": { + "gun_convergence": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // ChangeUnitReflection vertical targeting. + // 2.61.0.37: 0xff140e (movzx eax, byte ptr [rdx + 0xe0]; mov byte ptr [rsp + 0x40], al; cmp byte ptr [rsi + 0xb48], al) + "refl_vertical_targeting": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "unit_change_aircraft", + "pattern": "0f b6 82 ?? ?? ?? ?? 88 44 24 40 38 86 48 0b 00 00", + "captures": { + "vertical_targeting": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + }, + // ChangeUnitReflection bomb activation time. + // 2.61.0.37: 0xff1443 (movss xmm0, dword ptr [rdx + 0xe4]; movss dword ptr [rsp + 0x40], xmm0; movss xmm1, dword ptr [rsi + 0xb70]) + "refl_bomb_fuse": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "unit_change_aircraft", + "pattern": "f3 0f 10 82 ?? ?? ?? ?? f3 0f 11 44 24 40 f3 0f 10 8e 70 0b 00 00", + "captures": { + "bomb_fuse": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // Local MPlayer spawn point, delay and position read before respawning. + // 2.61.0.37: 0xc6c48a (mov edi, dword ptr [rax + 0xbd8]; mov esi, dword ptr [rax + 0xbf4]; movss xmm6, dword ptr [rax + 0xbfc]; ...) + "respawn_spawn": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "do_respawn_player", + "pattern": "8b b8 ?? ?? ?? ?? 8b b0 ?? ?? ?? ?? f3 0f 10 b0 ?? ?? ?? ?? f3 0f 10 b8 ?? ?? ?? ?? f3 44 0f 10 80 ?? ?? ?? ??", + "captures": { + "resp_base_id": { + "offset": 2, + "type": "u32" + }, + "spawn_delay_a": { + "offset": 8, + "type": "u32" + }, + "spawn_pos_x": { + "offset": 16, + "type": "u32" + }, + "spawn_pos_y": { + "offset": 24, + "type": "u32" + }, + "spawn_pos_z": { + "offset": 33, + "type": "u32" + } + } + } + } + ] + }, + // Unit::onEvent reading the owner MPlayer spawn state (base, both delays, position). + // 2.61.0.37: 0x1044ff1 (mov rax, qword ptr [r13 + 0xf98]; mov ebp, dword ptr [rax + 0xbd8]; mov r15d, dword ptr [rax + 0xbf4]; ...) + "unit_spawn_state": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "49 8b 85 ?? ?? ?? ?? 8b a8 ?? ?? ?? ?? 44 8b b8 ?? ?? ?? ?? 44 89 bc 24 80 00 00 00 8b b8 ?? ?? ?? ??", + "captures": { + "unit_mplayer": { + "offset": 3, + "type": "u32" + }, + "resp_base_id": { + "offset": 9, + "type": "u32" + }, + "spawn_delay_a": { + "offset": 16, + "type": "u32" + }, + "spawn_delay_b": { + "offset": 30, + "type": "u32" + } + } + } + } + ] + }, + // Change request crew slot, as an offset in the economic state. + // 2.61.0.37: 0xebc657 (mov r8d, dword ptr [rsi + 0xf65c]; mov dword ptr [rsi + 0x2c4], r8d) + "change_req_slot": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "aircraft_change_result", + "pattern": "44 8b 86 ?? ?? ?? ?? 44 89 86 c4 02 00 00", + "captures": { + "slot_id": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + }, + // GameEconomicState member cleanup, which frees the change request. + // 2.61.0.37: 0x2dd300 (push r14; push rsi; push rdi; ...) + "econ_clear": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 56 56 57 53 48 83 ec 28 48 89 ce 48 8d 05 ?? ?? ?? ?? 48 89 01 48 8d 05 ?? ?? ?? ?? 48 89 81 c8 02 00 00" + } + } + ] + }, + // Change request bullet set vector, as offsets in the economic state. + // 2.61.0.37: 0x2dd45f (mov rdi, qword ptr [rsi + 0xf608]; mov rbx, qword ptr [rsi + 0xf610]; cmp rdi, rbx; ...) + "change_req_bullets": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "econ_clear", + "pattern": "48 8b be ?? ?? ?? ?? 48 8b 9e ?? ?? ?? ?? 48 39 df 0f 85 ?? ?? ?? ?? 48 85 ff 74 ?? 48 89 f9 e8 ?? ?? ?? ?? 48 8d 8e e0 f5 00 00", + "captures": { + "bullets_begin": { + "offset": 3, + "type": "u32" + }, + "bullets_end": { + "offset": 10, + "type": "u32" + } + } + } + } + ] + }, + // A Unit method that starts by reading the unit crew skills. + // 2.61.0.37: 0x485850 (push r15; push r14; push r12; ...) + "unit_crew_skills": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 54 56 57 53 48 81 ec b8 00 00 00 44 0f 29 b4 24 a0 00 00 00 44 0f 29 ac 24 90 00 00 00 44 0f 29 a4 24 80 00 00 00 44 0f 29 5c 24 70 44 0f 29 54 24 60 44 0f 29 4c 24 50 44 0f 29 44 24 40 0f 29 7c 24 30 0f 29 74 24 20 48 89 ce 48 8b b9 ?? ?? ?? ??", + "captures": { + "crew_skills": { + "offset": 83, + "type": "u32" + } + } + } + } + ] + } + } +} diff --git a/patches/native/local_mp_nuke.jsonc b/patches/native/local_mp_nuke.jsonc new file mode 100644 index 0000000..377e57d --- /dev/null +++ b/patches/native/local_mp_nuke.jsonc @@ -0,0 +1,166 @@ +// Nuclear strike ends the battle on the LocalMP host (native/wto-net/src/local_mp_nuke.c). +// Without it: a nuclear explosion does not win a LocalMP battle. +{ + "module": "local_mp_nuke", + "features": [ + "K-Nuclear bomb" + ], + "requires": [ + "local_mp_core", + "local_mp_awards" + ], + "sites": { + // Bomb / shell launch. + // 2.61.0.37: 0x1431c10 + "shell_launch": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 54 56 57 55 53 48 81 ec 30 02 00 00 44 0f 29 bc 24 20 02 00 00" + } + } + ] + }, + // The launch record (+0x18 of the launch) gets the instant-win flag. + // 2.61.0.37: 0x14332fd (mov rax, qword ptr [rsi + 0x18]; test rax, rax; jne 0x143330d; ...) + "shell_instant_win": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "shell_launch", + "pattern": "48 8b 46 ?? 48 85 c0 75 ?? 48 8b 06 48 89 46 18 c6 40 ?? 01", + "captures": { + "record": { + "offset": 3, + "type": "u8" + }, + "instant_win": { + "offset": 18, + "type": "u8" + } + } + } + } + ] + }, + // Projectile explosion. + // 2.61.0.37: 0xbe7c00 + "shell_explode": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 02 00 00 44 0f 29 bc 24 90 02 00 00 44 0f 29 b4 24 80 02 00 00 44 0f 29 ac 24 70 02 00 00 44 0f 29 a4 24 60 02 00 00 44 0f 29 9c 24 50 02 00 00 44 0f 29 94 24 40 02 00 00 44 0f 29 8c 24 30 02 00 00 44 0f 29 84 24 20 02 00 00 0f 29 bc 24 10 02 00 00 0f 29 b4 24 00 02 00 00 41 89 d3" + } + } + ] + }, + // cta_logic_action (domination logic). + // 2.61.0.37: 0x11bc400 + "cta_logic_action": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 02 00 00 44 0f 29 bc 24 90 02 00 00 44 0f 29 b4 24 80 02 00 00 44 0f 29 ac 24 70 02 00 00 44 0f 29 a4 24 60 02 00 00 44 0f 29 9c 24 50 02 00 00 44 0f 29 94 24 40 02 00 00 44 0f 29 8c 24 30 02 00 00 44 0f 29 84 24 20 02 00 00 0f 29 bc 24 10 02 00 00 0f 29 b4 24 00 02 00 00 48 89 cf" + } + } + ] + }, + // Mission variables array of the logic context. + // 2.61.0.37: 0x11bc4f6 (lea rax, [rdi + 0x40]; mov r14d, dword ptr [rdi + 0x50]; test r14, r14; ...) + "mission_vars_data": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "cta_logic_action", + "pattern": "48 8d 47 ?? 44 8b 77 50 4d 85 f6 48 89 44 24 38", + "captures": { + "data": { + "offset": 3, + "type": "u8" + } + } + } + } + ] + }, + // Mission variables count; the walk keeps a pointer 8 bytes into each entry. + // 2.61.0.37: 0x11bd150 (mov ebx, dword ptr [rdi + 0x50]; test rbx, rbx; je 0x11bd250; ...) + "mission_vars_walk": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "mpTi0", + "pattern": "8b 5f ?? 48 85 db 0f 84 ?? ?? ?? ?? 48 8b 44 24 38 48 8b 30 4c 8d 7e ?? 4c 8d 35 ?? ?? ?? ??", + "lea_at": 24, + "captures": { + "count": { + "offset": 2, + "type": "u8" + }, + "entry_bias": { + "offset": 23, + "type": "u8" + } + } + } + } + ] + }, + // Entry name and size. + // 2.61.0.37: 0x11bd180 (mov rcx, qword ptr [r15 - 8]; mov rdx, r14; call 0x6bdf490; ...) + "mission_vars_step": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "cta_logic_action", + "pattern": "49 8b 4f ?? 4c 89 f2 e8 ?? ?? ?? ?? 85 c0 74 ?? 49 83 c7 ?? 49 ff cc 75 ?? 45 31 ff c7 05 ?? ?? ?? ?? 00 00 00 00 49 8d 4f 08", + "captures": { + "name": { + "offset": 3, + "type": "i8" + }, + "stride": { + "offset": 19, + "type": "u8" + } + } + } + } + ] + }, + // Entry value. + // 2.61.0.37: 0x11bd1a6 (lea rcx, [r15 + 8]; test r15, r15; lea rax, [rip + 0x69f6e0c]; ...) + "mission_vars_value": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "cta_logic_action", + "pattern": "49 8d 4f ?? 4d 85 ff 48 8d 05 ?? ?? ?? ?? 48 0f 44 c8 48 89 cd", + "captures": { + "value": { + "offset": 3, + "type": "u8" + } + } + } + } + ] + } + } +} diff --git a/patches/native/local_mp_players.jsonc b/patches/native/local_mp_players.jsonc new file mode 100644 index 0000000..bf6742c --- /dev/null +++ b/patches/native/local_mp_players.jsonc @@ -0,0 +1,211 @@ +// Player state on the LocalMP host (native/wto-net/src/local_mp_players.c): team from the hangar +// country, GUI states, crew slots used, spare vehicles. +// Without it: the player cannot pick a vehicle or spawn in a LocalMP battle. +{ + "module": "local_mp_players", + "features": [ + "K-Spawn score and respawns" + ], + "requires": [ + "local_mp_core" + ], + "sites": { + // MPlayer::initFromMatching. + // 2.61.0.37: 0x59e660 + "mplayer_init_matching": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 56 56 57 55 53 48 81 ec e0 00 00 00 48 89 d7 48 89 ce 48 89 91 90 0c 00 00 48 8d 8c 24 88 00 00 00 0f 57 c0 0f 11 84 24 b8 00 00 00 0f 11 84 24 a8 00 00 00 0f 11 84 24 98 00 00 00" + } + } + ] + }, + // is_crew_slot_was_ready_at_host. + // 2.61.0.37: 0x17a31d0 + "is_slot_ready_at_host": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 56 56 57 55 53 48 81 ec a0 00 00 00 0f 29 b4 24 90 00 00 00 44 89 c3 48 89 d6 48 83 3d" + } + } + ] + }, + // MPlayer GUI state byte. + // 2.61.0.37: 0x155f6f1 (movzx r15d, byte ptr [rdi + 0x640]; movsxd r12, esi; lea rax, [rip + 0x5d757fd]) + "mplayer_gui_state": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "set_player_gui_state", + "pattern": "44 0f b6 bf ?? ?? ?? ?? 4c 63 e6 48 8d 05 ?? ?? ?? ??", + "captures": { + "gui_state": { + "offset": 4, + "type": "u32" + } + } + } + } + ] + }, + // MPlayer::clearBeforeLobby. + // 2.61.0.37: 0x599680 (push r15; push r14; push r13; ...) + "mplayer_clear_before_lobby": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 00 00 00 0f 29 b4 24 80 00 00 00 48 89 ce 83 b9 0c 0c 00 00 00" + } + } + ] + }, + // MPlayer used spare vehicles mask, reset after the broken slots mask. + // 2.61.0.37: 0x59a102 (cmp dword ptr [rsi + 0x520], 0; je 0x59a129; lea rcx, [rsi + 0x500]) + "mplayer_used_spares": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "mplayer_clear_before_lobby", + "pattern": "83 be ?? ?? ?? ?? 00 74 ?? 48 8d 8e 00 05 00 00", + "captures": { + "used_spares": { + "offset": 2, + "type": "u32" + } + } + } + } + ] + }, + // Scoreboard row writer (refers to "airSevereDamage"). + // 2.61.0.37: 0x12929f0 + "scoreboard_rows": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "string_ref", + "string": "airSevereDamage", + "target": "function" + } + } + ] + }, + // The controlled unit eid, falling back to the player's own unit eid. + // 2.61.0.37: 0x1292bfb (mov edx, dword ptr [rdi + 0x880]; lea r8, [rdi + 0x854]; test edx, edx; ...) + "mplayer_unit_eid": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "scoreboard_rows", + "pattern": "8b 97 ?? ?? ?? ?? 4c 8d 87 54 08 00 00 85 d2 4c 0f 45 c1 48 8d 8f 48 08 00 00 0f 44 97 ?? ?? ?? ??", + "captures": { + "controlled_eid": { + "offset": 2, + "type": "u32" + }, + "unit_eid": { + "offset": 29, + "type": "u32" + } + } + } + } + ] + }, + // MissionSettings allies country. + // 2.61.0.37: 0x1277500 (mov rcx, qword ptr [rcx + 0xd0]; jmp 0x127751f; xor r10d, r10d) + "mission_allies_country": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "get_player_country", + "pattern": "48 8b 89 ?? ?? ?? ?? eb ?? 45 31 d2", + "captures": { + "allies_country": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + }, + // MissionSettings axis country. + // 2.61.0.37: 0x1277518 (mov rcx, qword ptr [rcx + 0xc8]; test rcx, rcx; lea r10, [rip + 0x67c23d8]) + "mission_axis_country": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "get_player_country", + "pattern": "48 8b 89 ?? ?? ?? ?? 48 85 c9 4c 8d 15 ?? ?? ?? ??", + "captures": { + "axis_country": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + }, + // MissionSettings arcade country mode. + // 2.61.0.37: 0x127748a (cmp byte ptr [rcx + 0x1d0], 1; jne 0x12774ee; movzx ecx, byte ptr [r10 + 0x250]) + "mission_arcade_country": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "get_player_country", + "pattern": "80 b9 ?? ?? ?? ?? 01 75 ?? 41 0f b6 8a 50 02 00 00", + "captures": { + "arcade_country": { + "offset": 2, + "type": "u32" + } + } + } + } + ] + }, + // MissionSettings customBots. + // 2.61.0.37: 0x126ef8d (lea rdi, [rsi + 0x718]; mov rcx, rdi; call 0x3093970) + "mission_custom_bots": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "mission_settings_load", + "pattern": "48 8d be ?? ?? ?? ?? 48 89 f9 e8 ?? ?? ?? ??", + "captures": { + "custom_bots": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + } + } +} diff --git a/patches/native/local_mp_scores.jsonc b/patches/native/local_mp_scores.jsonc new file mode 100644 index 0000000..748dac5 --- /dev/null +++ b/patches/native/local_mp_scores.jsonc @@ -0,0 +1,47 @@ +// Score table of a LocalMP battle (native/wto-net/src/local_mp_scores.c): the local server puts it +// in the mission's customScoreParams; the host reads it there. +// Without it: kills, assists and captures score nothing. +{ + "module": "local_mp_scores", + "features": [ + "K-Kill, assist and capture scoring" + ], + "requires": [ + "local_mp_core" + ], + "sites": { + // DataBlock::getReal wrapper. + // 2.61.0.37: 0x5445270 + "datablock_get_real": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "48 83 ec 28 f3 0f 11 54 24 24 4c 8d 44 24 24 e8 ?? ?? ?? ?? 90 48 83 c4 28 c3 cc cc cc cc cc cc 56 57 53 48 83 ec 30 48 89 d7 48 89 ce 48 8d 15" + } + } + ] + }, + // MissionSettings customScoreParams copy. + // 2.61.0.37: 0x126d762 (lea rcx, [rax + 0x6d8]; mov eax, dword ptr [r13 + 0x10]; cmp eax, -1; ...) + "mission_score_params": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "mission_settings_load", + "pattern": "48 8d 88 ?? ?? ?? ?? 41 8b 45 10 83 f8 ff 74 ?? 45 0f b7 45 0e 46 8d 0c 00 31 d2 44 39 c8 0f 8d ?? ?? ?? ?? ff c7 4d 8b 4d 00 45 8b 51 5c 4d 01 d1 49 81 c1 90 00 00 00 41 bb ff ff ff 3f 45 31 d2 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 42 8d 34 10 48 c1 e6 05 41 8b 5c 31 08 44 21 db 39 fb 74 ?? 41 ff c2 45 39 d0 75 ?? eb ?? 41 0f b7 45 0e 31 d2 85 c0 74 ?? ff c7 4d 8b 4d 18 4d 8b 01 45 8b 49 08 44 8d 14 c5 00 00 00 00 45 29 d1 41 ba ff ff ff 3f 45 31 db 66 0f 1f 44 00 00 4b 8b 34 08 8b 76 08 44 21 d6 39 fe 74 ?? 41 ff c3 49 83 c1 08 44 39 d8 75 ?? eb ?? 49 01 f1 31 d2 45 39 c2 49 0f 42 d1 eb ?? 41 39 c3 73 ?? 44 89 c8 49 8b 14 00 eb ?? 31 d2 48 85 d2 49 0f 44 d6 31 f6 45 31 c0 e8 ?? ?? ?? ?? 49 8b 5d 00 bf ff ff ff ff 48 85 db 74 ?? 48 8d 0d ?? ?? ?? ?? ba 16 00 00 00", + "captures": { + "custom_score_params": { + "offset": 3, + "type": "u32" + } + } + } + } + ] + } + } +} diff --git a/patches/native/local_mp_support.jsonc b/patches/native/local_mp_support.jsonc new file mode 100644 index 0000000..841da6e --- /dev/null +++ b/patches/native/local_mp_support.jsonc @@ -0,0 +1,63 @@ +// Mission support unit (the nuclear carrier) after it is destroyed (native/wto-net/src/local_mp_support.c). +// Without it: a second nuclear carrier spawns where the first died and nobody flies it. +{ + "module": "local_mp_support", + "features": [ + "K-Nuclear bomb" + ], + "requires": [ + "local_mp_core" + ], + "sites": { + // setControlledUnit(mplayer, eid). + // 2.61.0.37: 0x598a70 + "set_controlled_unit": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "56 57 53 48 83 ec 40 89 d7 48 89 ce 89 d0 48 89 44 24 28 c7 44 24 20 03 00 00 00" + } + } + ] + }, + // MPlayer per-frame update. + // 2.61.0.37: 0x59d270 (push r15; push r14; push r13; ...) + "mplayer_update": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 00 00 00 0f 29 bc 24 80 00 00 00 0f 29 74 24 70 0f 28 f1" + } + } + ] + }, + // MPlayer missionSupportUnitRef. + // 2.61.0.37: 0x59da3c (mov dword ptr [rsi + 0xb58], eax; mov rcx, qword ptr [rsp + 0x38]; mov qword ptr [rsi + 0xb50], rcx) + "mplayer_support_unit": { + "variants": [ + { + "written_for": "2.61.0.37", + "locate": { + "method": "within", + "in": "mplayer_update", + "pattern": "89 86 ?? ?? ?? ?? 48 8b 4c 24 38 48 89 8e ?? ?? ?? ??", + "captures": { + "eid": { + "offset": 2, + "type": "u32" + }, + "unit": { + "offset": 14, + "type": "u32" + } + } + } + } + ] + } + } +} diff --git a/patches/versions/2.61.0.37.jsonc b/patches/versions/2.61.0.37.jsonc index d891a84..a51d8c3 100644 --- a/patches/versions/2.61.0.37.jsonc +++ b/patches/versions/2.61.0.37.jsonc @@ -160,5 +160,380 @@ "variant": "2.61.0.37" } }, + "native_modules": { + "local_mp_core": { + "disabled_slots_mask": "2.61.0.37", + "do_respawn_player": "2.61.0.37", + "get_player_country": "2.61.0.37", + "sq_local_country": "2.61.0.37", + "refl_dtor": "2.61.0.37", + "aircraft_change_result": "2.61.0.37", + "set_player_gui_state": "2.61.0.37", + "get_unit_by_eid": "2.61.0.37", + "set_owning_mplayer": "2.61.0.37", + "iground_on_dead": "2.61.0.37", + "datablock_get_str": "2.61.0.37", + "datablock_set_from": "2.61.0.37", + "mp_construct_local": "2.61.0.37", + "gui_state_update": "2.61.0.37", + "app_econ_state": "2.61.0.37", + "mplayer_matching": "2.61.0.37", + "unit_change_aircraft": "2.61.0.37", + "unit_type": "2.61.0.37", + "unit_info_name": "2.61.0.37", + "unit_mplayer": "2.61.0.37", + "refl_stdmem": "2.61.0.37", + "mission_settings_load": "2.61.0.37" + }, + "local_mp_actions": { + "mp_init_chat": "2.61.0.37", + "mp_chat": "2.61.0.37", + "bot_system_setup": "2.61.0.37", + "mp_team_countries": "2.61.0.37" + }, + "local_mp_awards": { + "add_score_message": "2.61.0.37", + "score_msg_blk_ctor": "2.61.0.37", + "score_msg_blk_set_str": "2.61.0.37", + "score_msg_blk_to_owned": "2.61.0.37", + "score_msg_blk_set_int": "2.61.0.37", + "score_msg_hud_queue": "2.61.0.37", + "score_msg_blk_dtor": "2.61.0.37", + "score_msg_exp_class": "2.61.0.37", + "game_save_data": "2.61.0.37" + }, + "local_mp_scores": { + "datablock_get_real": "2.61.0.37", + "mission_score_params": "2.61.0.37" + }, + "local_mp_kills": { + "mplayer_add_score": "2.61.0.37", + "mplayer_score": "2.61.0.37", + "mplayer_stat_sync": "2.61.0.37", + "net_mark_dirty": "2.61.0.37", + "on_unit_dead_once": "2.61.0.37", + "unit_severe": "2.61.0.37", + "ground_death_flags": "2.61.0.37", + "ground_bailout": "2.61.0.37", + "ground_offenders": "2.61.0.37", + "iground_award_assists": "2.61.0.37", + "offender_fields": "2.61.0.37", + "stat_kills": "2.61.0.37", + "stat_ground_kills": "2.61.0.37", + "stat_human_kills": "2.61.0.37", + "stat_naval_kills": "2.61.0.37", + "stat_team_kills": "2.61.0.37", + "stat_ai_kills": "2.61.0.37", + "stat_ai_ground_kills": "2.61.0.37", + "stat_ai_naval_kills": "2.61.0.37", + "stat_assists": "2.61.0.37", + "stat_deaths": "2.61.0.37", + "stat_capture_zone": "2.61.0.37", + "stat_score": "2.61.0.37", + "stat_award_damage": "2.61.0.37", + "stat_air_severe": "2.61.0.37", + "stat_ship_severe": "2.61.0.37" + }, + "local_mp_events": { + "dispatch_assist": "2.61.0.37", + "caller_capture_zone": "2.61.0.37", + "caller_hit_crit": "2.61.0.37", + "caller_severe_damage": "2.61.0.37", + "caller_naval_damage": "2.61.0.37", + "offender_assist": "2.61.0.37" + }, + "local_mp_players": { + "mplayer_init_matching": "2.61.0.37", + "is_slot_ready_at_host": "2.61.0.37", + "mplayer_gui_state": "2.61.0.37", + "mplayer_clear_before_lobby": "2.61.0.37", + "mplayer_used_spares": "2.61.0.37", + "scoreboard_rows": "2.61.0.37", + "mplayer_unit_eid": "2.61.0.37", + "mission_allies_country": "2.61.0.37", + "mission_axis_country": "2.61.0.37", + "mission_arcade_country": "2.61.0.37", + "mission_custom_bots": "2.61.0.37" + }, + "local_mp_loadout": { + "sem_change_aircraft_send": "2.61.0.37", + "refl_ctor": "2.61.0.37", + "datablock_dtor": "2.61.0.37", + "bullet_vec_assign": "2.61.0.37", + "get_decals_blk": "2.61.0.37", + "get_attachables_blk": "2.61.0.37", + "str_hash_fnv1": "2.61.0.37", + "namemap_add_name_id": "2.61.0.37", + "crew_skills_init": "2.61.0.37", + "refl_objects": "2.61.0.37", + "refl_names": "2.61.0.37", + "refl_flags": "2.61.0.37", + "refl_targeting": "2.61.0.37", + "refl_vertical_targeting": "2.61.0.37", + "refl_bomb_fuse": "2.61.0.37", + "respawn_spawn": "2.61.0.37", + "unit_spawn_state": "2.61.0.37", + "change_req_slot": "2.61.0.37", + "econ_clear": "2.61.0.37", + "change_req_bullets": "2.61.0.37", + "unit_crew_skills": "2.61.0.37" + }, + "local_mp_nuke": { + "shell_launch": "2.61.0.37", + "shell_instant_win": "2.61.0.37", + "shell_explode": "2.61.0.37", + "cta_logic_action": "2.61.0.37", + "mission_vars_data": "2.61.0.37", + "mission_vars_walk": "2.61.0.37", + "mission_vars_step": "2.61.0.37", + "mission_vars_value": "2.61.0.37" + }, + "local_mp_support": { + "set_controlled_unit": "2.61.0.37", + "mplayer_update": "2.61.0.37", + "mplayer_support_unit": "2.61.0.37" + } + }, + "native_values": { + "add_score_message": "0x189a8e0", + "aircraft_change_result": "0xebc490", + "aircraft_change_result.econ_change_req": "0xf578", + "app_econ_state": "0x155f5b7", + "app_econ_state.econ_holder": "0x3f0", + "app_econ_state.econ_state": "0x9a8", + "bot_system_setup": "0x11af3f0", + "bullet_vec_assign": "0x4f1410", + "caller_capture_zone": "0x3db0e0", + "caller_capture_zone.call": "0x357310", + "caller_hit_crit": "0xff85ea", + "caller_hit_crit.call": "0x35bc20", + "caller_naval_damage": "0xd048ea", + "caller_naval_damage.call": "0x35a5f0", + "caller_severe_damage": "0xe55afa", + "caller_severe_damage.call": "0x35c310", + "change_req_bullets": "0x2dd45f", + "change_req_bullets.bullets_begin": "0xf608", + "change_req_bullets.bullets_end": "0xf610", + "change_req_slot": "0xebc657", + "change_req_slot.slot_id": "0xf65c", + "crew_skills_init": "0x1032130", + "cta_logic_action": "0x11bc400", + "datablock_dtor": "0x3093a60", + "datablock_get_real": "0x5445270", + "datablock_get_str": "0x3094400", + "datablock_set_from": "0x3093210", + "datablock_set_from.dagmem_alloc": "0x6bf5a2c", + "disabled_slots_mask": "0x6bb480", + "disabled_slots_mask.app": "0x7bab428", + "disabled_slots_mask.local_mplayer": "0x7b817c0", + "disabled_slots_mask.mplayer_broken_slots": "0x4d0", + "disabled_slots_mask.multiplayer": "0x7b83cb0", + "dispatch_assist": "0x35beb0", + "do_respawn_player": "0xc6c010", + "do_respawn_player.app_score_rules": "0x3e0", + "do_respawn_player.hero": "0x7bad418", + "econ_clear": "0x2dd300", + "game_save_data": "0x427e19", + "game_save_data.game_save_data": "0x7bf4958", + "get_attachables_blk": "0x2e08f0", + "get_decals_blk": "0x2df9a0", + "get_player_country": "0x12773b0", + "get_player_country.mp_is_local_mp": "0x61", + "get_player_country.player_count": "0x7b817e0", + "get_player_country.player_table": "0x7b817d0", + "get_unit_by_eid": "0x110b960", + "ground_bailout": "0x427a61", + "ground_bailout.bailout_dead": "0x3888", + "ground_death_flags": "0x427490", + "ground_death_flags.already_dead": "0x2101", + "ground_death_flags.dead_silent": "0x1c19", + "ground_offenders": "0x427aad", + "ground_offenders.killer": "0x19e8", + "ground_offenders.killer_pid": "0x1a08", + "ground_offenders.killer_uid": "0x1a40", + "ground_offenders.offender_size": "0x160", + "ground_offenders.offenders": "0x17c0", + "ground_offenders.offenders_count": "0x17d0", + "ground_offenders.unit_type": "0x8c", + "gui_state_update": "0x155f490", + "iground_award_assists": "0x465540", + "iground_award_assists.choose_offender": "0x498", + "iground_on_dead": "0x427400", + "is_slot_ready_at_host": "0x17a31d0", + "mission_allies_country": "0x1277500", + "mission_allies_country.allies_country": "0xd0", + "mission_arcade_country": "0x127748a", + "mission_arcade_country.arcade_country": "0x1d0", + "mission_axis_country": "0x1277518", + "mission_axis_country.axis_country": "0xc8", + "mission_custom_bots": "0x126ef8d", + "mission_custom_bots.custom_bots": "0x718", + "mission_score_params": "0x126d762", + "mission_score_params.custom_score_params": "0x6d8", + "mission_settings_load": "0x12657a0", + "mission_vars_data": "0x11bc4f6", + "mission_vars_data.data": "0x40", + "mission_vars_step": "0x11bd180", + "mission_vars_step.name": "-0x8", + "mission_vars_step.stride": "0x20", + "mission_vars_value": "0x11bd1a6", + "mission_vars_value.value": "0x8", + "mission_vars_walk": "0x11bd150", + "mission_vars_walk.count": "0x50", + "mission_vars_walk.entry_bias": "0x8", + "mp_chat": "0x5bd732", + "mp_chat.mp_chat": "0x1f0", + "mp_construct_local": "0x5bd960", + "mp_construct_local.mp_chat_host": "0xf8", + "mp_construct_local.mp_is_host": "0x60", + "mp_init_chat": "0x5bd6a0", + "mp_team_countries": "0x11afd9f", + "mp_team_countries.team1_countries": "0x150", + "mp_team_countries.team2_countries": "0x170", + "mplayer_add_score": "0x59f2d0", + "mplayer_clear_before_lobby": "0x599680", + "mplayer_gui_state": "0x155f6f1", + "mplayer_gui_state.gui_state": "0x640", + "mplayer_init_matching": "0x59e660", + "mplayer_matching": "0x59e95f", + "mplayer_matching.match_team": "0x4", + "mplayer_matching.mp_team": "0x228", + "mplayer_matching.mp_user_id": "0xb8", + "mplayer_score": "0x59f30d", + "mplayer_score.score": "0x8f8", + "mplayer_stat_sync": "0x59f5f8", + "mplayer_stat_sync.dirty": "0xa10", + "mplayer_stat_sync.payload": "0xa30", + "mplayer_support_unit": "0x59da3c", + "mplayer_support_unit.eid": "0xb58", + "mplayer_support_unit.unit": "0xb50", + "mplayer_unit_eid": "0x1292bfb", + "mplayer_unit_eid.controlled_eid": "0x880", + "mplayer_unit_eid.unit_eid": "0x850", + "mplayer_update": "0x59d270", + "mplayer_used_spares": "0x59a102", + "mplayer_used_spares.used_spares": "0x520", + "namemap_add_name_id": "0xed4b0", + "net_mark_dirty": "0x31030a0", + "offender_assist": "0x465896", + "offender_assist.assist_sent": "0x148", + "offender_fields": "0x465832", + "offender_fields.army": "0x1c", + "offender_fields.pid": "0x20", + "offender_fields.uid": "0x58", + "offender_fields.unit_army": "0x1010", + "on_unit_dead_once": "0xe5b200", + "on_unit_dead_once.skip_kill": "0x3058", + "refl_bomb_fuse": "0xff1443", + "refl_bomb_fuse.bomb_fuse": "0xe4", + "refl_ctor": "0xcccdc0", + "refl_dtor": "0x548f20", + "refl_flags": "0xff139a", + "refl_flags.flags": "0xd0", + "refl_names": "0x548fa2", + "refl_names.custom_skin": "0x68", + "refl_names.skin": "0x60", + "refl_names.unit": "0x50", + "refl_names.weapon": "0x58", + "refl_objects": "0x548f45", + "refl_objects.attachables": "0x90", + "refl_objects.bullets": "0x190", + "refl_objects.custom_preset": "0xb0", + "refl_objects.decals": "0x70", + "refl_objects.disabled_mods": "0x140", + "refl_objects.enabled_mods": "0xf0", + "refl_stdmem": "0x548fab", + "refl_stdmem.stdmem": "0x8025298", + "refl_targeting": "0xff13ce", + "refl_targeting.gun_convergence": "0xdc", + "refl_vertical_targeting": "0xff140e", + "refl_vertical_targeting.vertical_targeting": "0xe0", + "respawn_spawn": "0xc6c48a", + "respawn_spawn.resp_base_id": "0xbd8", + "respawn_spawn.spawn_delay_a": "0xbf4", + "respawn_spawn.spawn_pos_x": "0xbfc", + "respawn_spawn.spawn_pos_y": "0xc00", + "respawn_spawn.spawn_pos_z": "0xc04", + "score_msg_blk_ctor": "0x189b99c", + "score_msg_blk_ctor.call": "0x3093000", + "score_msg_blk_dtor": "0x189be90", + "score_msg_blk_dtor.call": "0x3093a60", + "score_msg_blk_set_int": "0x189ba68", + "score_msg_blk_set_int.call": "0x3095130", + "score_msg_blk_set_str": "0x189ba34", + "score_msg_blk_set_str.call": "0x3094950", + "score_msg_blk_to_owned": "0x189ba4f", + "score_msg_blk_to_owned.call": "0x30998c0", + "score_msg_exp_class": "0x189bb19", + "score_msg_exp_class.exp_class": "0x38", + "score_msg_exp_class.unit_info": "0x1020", + "score_msg_hud_queue": "0x189be3b", + "score_msg_hud_queue.call": "0x1804900", + "score_msg_hud_queue.queue": "0xae8", + "scoreboard_rows": "0x12929f0", + "sem_change_aircraft_send": "0xccba20", + "set_controlled_unit": "0x598a70", + "set_owning_mplayer": "0xfce410", + "set_owning_mplayer.mp_pid": "0x8", + "set_player_gui_state": "0x155f5f0", + "shell_explode": "0xbe7c00", + "shell_instant_win": "0x14332fd", + "shell_instant_win.instant_win": "0x70", + "shell_instant_win.record": "0x18", + "shell_launch": "0x1431c10", + "sq_local_country": "0x179f400", + "sq_local_country.mission_settings": "0x7bb5058", + "stat_ai_ground_kills": "0x111f16e", + "stat_ai_ground_kills.field": "0x9e6", + "stat_ai_kills": "0x111f157", + "stat_ai_kills.field": "0x9e4", + "stat_ai_naval_kills": "0x111f185", + "stat_ai_naval_kills.field": "0x9e8", + "stat_air_severe": "0x129349c", + "stat_air_severe.field": "0xa06", + "stat_assists": "0x111f19c", + "stat_assists.field": "0x9ec", + "stat_award_damage": "0x111f21b", + "stat_award_damage.field": "0xa00", + "stat_capture_zone": "0x111f1ca", + "stat_capture_zone.field": "0x9ee", + "stat_deaths": "0x111f1b3", + "stat_deaths.field": "0x9dc", + "stat_ground_kills": "0x111f0fb", + "stat_ground_kills.field": "0x9de", + "stat_human_kills": "0x111f112", + "stat_human_kills.field": "0x9e0", + "stat_kills": "0x111f0e4", + "stat_kills.field": "0x9d8", + "stat_naval_kills": "0x111f129", + "stat_naval_kills.field": "0x9e2", + "stat_score": "0x111f1f7", + "stat_score.fallback": "0x2d8", + "stat_score.score": "0x8f8", + "stat_ship_severe": "0x12934c8", + "stat_ship_severe.field": "0xa08", + "stat_team_kills": "0x111f140", + "stat_team_kills.field": "0x9da", + "str_hash_fnv1": "0x21b670", + "unit_change_aircraft": "0xff1020", + "unit_crew_skills": "0x485850", + "unit_crew_skills.crew_skills": "0x10a8", + "unit_info_name": "0xff12a5", + "unit_info_name.info_name": "0x10", + "unit_info_name.unit_info": "0x1020", + "unit_mplayer": "0xfce718", + "unit_mplayer.unit_mplayer": "0xf98", + "unit_severe": "0xe5b2c7", + "unit_severe.severe_idx": "0x6b0", + "unit_severe.severe_pid": "0x6d0", + "unit_severe.severe_uid": "0x708", + "unit_spawn_state": "0x1044ff1", + "unit_spawn_state.resp_base_id": "0xbd8", + "unit_spawn_state.spawn_delay_a": "0xbf4", + "unit_spawn_state.spawn_delay_b": "0xbf8", + "unit_spawn_state.unit_mplayer": "0xf98", + "unit_type": "0xff120f", + "unit_type.unit_type": "0x8c" + }, "unavailable": {} } diff --git a/scripts/build-game-copy.ts b/scripts/build-game-copy.ts index 68305ce..f76f373 100644 --- a/scripts/build-game-copy.ts +++ b/scripts/build-game-copy.ts @@ -3,7 +3,7 @@ * * node scripts/build-game-copy.ts --game --out --port * --data - * [--patches ] [--gui-patches ] + * [--patches ] * [--native ] [--decal-cache ] * [--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 --out --port --data ' - + '[--patches ] [--gui-patches ] [--native ] [--decal-cache ] ' + + '[--patches ] [--native ] [--decal-cache ] ' + '[--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 { diff --git a/scripts/record-game-version.ts b/scripts/record-game-version.ts index 23df60f..cb7588f 100644 --- a/scripts/record-game-version.ts +++ b/scripts/record-game-version.ts @@ -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 [--out ] - * [--patches ] [--gui-patches ] + * node scripts/record-game-version.ts --game [--patches ] * - * The game folder is only read. The record goes to /.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 /versions/.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 [--out ] [--patches ] [--gui-patches ]'; +const USAGE = 'usage: record-game-version.ts --game [--patches ]'; 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>, 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(); + 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();