Table of Contents

Class CallPatch

Namespace
SkyrimForge
Assembly
SkyrimForge.dll

Replaces whole instructions with a call to Target, after which the code following the expected bytes runs.

public sealed class CallPatch : CodePatch
Inheritance
CallPatch
Inherited Members

Remarks

The call occupies the first five expected bytes, and the rest of them become nops. The expected bytes therefore end on an instruction, and no branch elsewhere in the function lands inside them. Apply(params ReadOnlySpan<CodePatch>) detects a direct branch in the function part the exception directory lists, not a branch through a jump table or a register. The target begins an instruction where its module's exception directory lists the function containing it, and lies inside no recorded patch or hook past its first byte.

The target lies within a 32-bit displacement of the address, as the game's own code and memory from AllocateCode(nint, int) do. Code in allocated memory is complete before the call reaching it is applied.

Constructors

CallPatch(nint, BytePattern, nint)

Creates a patch replacing the expected bytes at address with a call to target.

public CallPatch(nint address, BytePattern expected, nint target)

Parameters

address nint

The address of the first expected byte.

expected BytePattern

The bytes the code at address must match: the whole instructions replaced, at least five bytes.

target nint

The address the call reaches.

Exceptions

ArgumentOutOfRangeException

address or target is 0, expected is shorter than five bytes, or target lies farther from address than a 32-bit displacement reaches.

ArgumentNullException

expected is null.

Properties

Target

The address the call reaches.

public nint Target { get; }

Property Value

nint