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/<module>.jsonc, resolved by the patcher when it builds the game copy, the same way exe patches are located: - Locate methods: "string_ref" finds code by the string it loads (optionally with a pattern around the lea, to read the field a scoreboard row stores under that name), and "within" searches a short pattern inside the function of a site located before it (function ranges from the exception directory). - Each module lists its sites (functions, globals, call targets and the instructions whose captures give structure offsets), its features and the modules it requires. A module whose sites are not all found is reported like an unavailable patch, with the modules depending on it. - The resolved values go into wto_ws.cfg as native.<site>[.<capture>] lines, with the executable's PE time stamp and image size so the library can refuse values resolved for another build. - Version records include the native module variants and values. - Patch-set folders: the patcher, the scripts and the launcher take the root of a patch set (exe, gui, native, versions) instead of separate folders. - New feature tags K-Chat and radio and K-Nuclear bomb in both language packs. The library still scans by itself; reading these values is the next change. Checked: root and launcher type checks; all 10 modules resolve on 2.61.0.37, where the 239 values equal what the drafting tool read with a disassembler, and on 2.61.0.43, where every structure offset is unchanged except the GameSaveData HUD event queue (0xae8 -> 0xb18); build-game-copy from 2.61.0.37 into a temporary folder writes the values into wto_ws.cfg.
This commit is contained in:
1 parent
373b7a037a
commit
dde852e2b1
36 files changed
+3318
-91
No files matched your search
@@ -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';
|
||||
@@ -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<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>>): number[];
|
||||
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 {
|
||||
|
||||
@@ -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<Record<string, unknown>>): 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<Record<string, unknown>>): 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<StringRefSpec['around']>): 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<Record<string, unknown>>): 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<number, number[]> {
|
||||
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<number, number[]>();
|
||||
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;
|
||||
});
|
||||
}
|
||||
@@ -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<Record<string, unknown>>, 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<Record<string, unknown>>): number {
|
||||
return parseBytePattern(spec.pattern, 'within pattern').bytes.length;
|
||||
}
|
||||
@@ -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<string, unknown>();
|
||||
|
||||
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<T>(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);
|
||||
}
|
||||
@@ -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) };
|
||||
|
||||
@@ -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<CharPackResult, 'pack'>;
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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/<module>.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<string, string>();
|
||||
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<string>();
|
||||
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;
|
||||
}
|
||||
@@ -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, `<site>` (its RVA) and
|
||||
* `<site>.<capture>` 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<string, number>;
|
||||
/** Module name -> the variant used for each of its sites. */
|
||||
readonly available: ReadonlyMap<string, ReadonlyMap<string, string>>;
|
||||
/** Unavailable modules, with patchId `native/<module>`. */
|
||||
readonly failures: readonly PatchFailure[];
|
||||
}
|
||||
|
||||
export function resolveNativeModules(image: PeImage, modules: readonly NativeModule[]): NativeResolution {
|
||||
const values = new Map<string, number>();
|
||||
const sites = new Map<string, number>();
|
||||
const available = new Map<string, ReadonlyMap<string, string>>();
|
||||
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<string, number>;
|
||||
readonly sites: Map<string, number>;
|
||||
readonly variants: Map<string, string>;
|
||||
}
|
||||
|
||||
/** Every site of `module`, or a PatchError naming the first one that cannot be located. */
|
||||
function resolveModule(image: PeImage, module: NativeModule, located: ReadonlyMap<string, number>): 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;
|
||||
}
|
||||
@@ -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.<name>=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, number>): 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)}`;
|
||||
}
|
||||
@@ -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<string, number>,
|
||||
): { name: string; content: Uint8Array } {
|
||||
const lines = [`port=${endpoint.port}`, ...nativeSettingsLines(stock, nativeValues)];
|
||||
return { name: SETTINGS, content: new TextEncoder().encode(`${lines.join('\n')}\n`) };
|
||||
}
|
||||
@@ -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/<module>` 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<string, string[]>();
|
||||
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);
|
||||
|
||||
@@ -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') };
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Version records: one file per game build the patches were checked on, under patches/versions/
|
||||
* (`<game version>.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
|
||||
* (`<game version>.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<Record<string, { readonly variant: string; readonly rva: string }>>;
|
||||
/** Patch id -> the variant that applies. */
|
||||
readonly guiPatches: Readonly<Record<string, { readonly variant: string }>>;
|
||||
/** Patch id -> why it is unavailable on this build. */
|
||||
/** Native module -> site -> the variant that locates it. */
|
||||
readonly nativeModules: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
||||
/** Value name -> value, as the hook library receives them (native-settings.ts). */
|
||||
readonly nativeValues: Readonly<Record<string, string>>;
|
||||
/** Patch id (`native/<module>` for native modules) -> why it is unavailable on this build. */
|
||||
readonly unavailable: Readonly<Record<string, string>>;
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
Reference in new issue
Block a user