The LocalMP modules of wto_ws.dll scanned for 42 functions at start-up and used about a hundred structure offsets compiled in as constants, so a game update could move a field without anything noticing. Their needs are now definitions under patches/native/<module>.jsonc, resolved by the patcher when it builds the game copy, the same way exe patches are located: - Locate methods: "string_ref" finds code by the string it loads (optionally with a pattern around the lea, to read the field a scoreboard row stores under that name), and "within" searches a short pattern inside the function of a site located before it (function ranges from the exception directory). - Each module lists its sites (functions, globals, call targets and the instructions whose captures give structure offsets), its features and the modules it requires. A module whose sites are not all found is reported like an unavailable patch, with the modules depending on it. - The resolved values go into wto_ws.cfg as native.<site>[.<capture>] lines, with the executable's PE time stamp and image size so the library can refuse values resolved for another build. - Version records include the native module variants and values. - Patch-set folders: the patcher, the scripts and the launcher take the root of a patch set (exe, gui, native, versions) instead of separate folders. - New feature tags K-Chat and radio and K-Nuclear bomb in both language packs. The library still scans by itself; reading these values is the next change. Checked: root and launcher type checks; all 10 modules resolve on 2.61.0.37, where the 239 values equal what the drafting tool read with a disassembler, and on 2.61.0.43, where every structure offset is unchanged except the GameSaveData HUD event queue (0xae8 -> 0xb18); build-game-copy from 2.61.0.37 into a temporary folder writes the values into wto_ws.cfg.
41 lines
1.9 KiB
TypeScript
41 lines
1.9 KiB
TypeScript
/**
|
|
* 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<string, number>;
|
|
}
|
|
|
|
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<Record<string, unknown>>, context: LocateContext): number[];
|
|
/** Number of bytes from the site that the method checked; captures must lie inside them. */
|
|
length(spec: Readonly<Record<string, unknown>>): number;
|
|
}
|
|
|
|
const METHODS: ReadonlyMap<string, LocateMethod> = 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 {
|
|
const found = typeof method === 'string' ? METHODS.get(method) : undefined;
|
|
if (!found) throw new DefinitionError(`unknown locate method "${String(method)}"; known: ${[...METHODS.keys()].join(', ')}`);
|
|
return found;
|
|
}
|