Browse documentation

Class CodeInstruction

Namespace
HarmonyLib
Assembly
0Harmony.dll

An abstract wrapper around OpCode and their operands. Used by transpilers

public class CodeInstruction
Inheritance
object
CodeInstruction
Derived
Extension Methods

Constructors

CodeInstruction(CodeInstruction)

Create a full copy (including labels and exception blocks) of a CodeInstruction

public CodeInstruction(CodeInstruction instruction)

Parameters

instruction CodeInstruction

The CodeInstruction to copy

CodeInstruction(OpCode, object)

Creates a new CodeInstruction with a given opcode and optional operand

public CodeInstruction(OpCode opcode, object operand = null)

Parameters

opcode OpCode

The opcode

operand object

The operand

Fields

blocks

All exception block boundaries defined on this instruction

public List<ExceptionBlock> blocks

Field Value

List<ExceptionBlock>

labels

All labels defined on this instruction

public List<Label> labels

Field Value

List<Label>

opcode

The opcode

public OpCode opcode

Field Value

OpCode

operand

The operand

public object operand

Field Value

object

Methods

Call(Expression<Action>)

Creates a CodeInstruction calling a method (CALL)

public static CodeInstruction Call(Expression<Action> expression)

Parameters

expression Expression<Action>

The lambda expression using the method

Returns

CodeInstruction

A new Codeinstruction

Call(LambdaExpression)

Creates a CodeInstruction calling a method (CALL)

public static CodeInstruction Call(LambdaExpression expression)

Parameters

expression LambdaExpression

The lambda expression using the method

Returns

CodeInstruction

A new Codeinstruction

Call(string, Type[], Type[])

Creates a CodeInstruction calling a method (CALL)

public static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null)

Parameters

typeColonMethodname string

The target method in the form TypeFullName:MethodName, where the type name matches a form recognized by Type.GetType like Some.Namespace.Type.

parameters Type[]

Optional parameters to target a specific overload of the method

generics Type[]

Optional list of types that define the generic version of the method

Returns

CodeInstruction

A code instruction that calls the method matching the arguments

Call(Type, string, Type[], Type[])

Creates a CodeInstruction calling a method (CALL)

public static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null)

Parameters

type Type

The class/type where the method is declared

name string

The name of the method (case sensitive)

parameters Type[]

Optional parameters to target a specific overload of the method

generics Type[]

Optional list of types that define the generic version of the method

Returns

CodeInstruction

A code instruction that calls the method matching the arguments

CallClosure<T>(T)

Returns an instruction to call the specified closure

public static CodeInstruction CallClosure<T>(T closure) where T : Delegate

Parameters

closure T

The closure that defines the method to call

Returns

CodeInstruction

A CodeInstruction that calls the closure as a method

Type Parameters

T

The delegate type to emit

Call<T>(Expression<Action<T>>)

Creates a CodeInstruction calling a method (CALL)

public static CodeInstruction Call<T>(Expression<Action<T>> expression)

Parameters

expression Expression<Action<T>>

The lambda expression using the method

Returns

CodeInstruction

A new Codeinstruction

Type Parameters

T

Call<T, TResult>(Expression<Func<T, TResult>>)

Creates a CodeInstruction calling a method (CALL)

public static CodeInstruction Call<T, TResult>(Expression<Func<T, TResult>> expression)

Parameters

expression Expression<Func<T, TResult>>

The lambda expression using the method

Returns

CodeInstruction

A new Codeinstruction

Type Parameters

T
TResult

Clone()

Clones a CodeInstruction and resets its labels and exception blocks

public CodeInstruction Clone()

Returns

CodeInstruction

A lightweight copy of this code instruction

Clone(object)

Clones a CodeInstruction, resets labels and exception blocks and sets its operand

public CodeInstruction Clone(object operand)

Parameters

operand object

The operand

Returns

CodeInstruction

A copy of this CodeInstruction with a new operand

Clone(OpCode)

Clones a CodeInstruction, resets labels and exception blocks and sets its opcode

public CodeInstruction Clone(OpCode opcode)

Parameters

opcode OpCode

The opcode

Returns

CodeInstruction

A copy of this CodeInstruction with a new opcode

HasBlock(ExceptionBlockType)

Checks if a CodeInstruction contains a given exception block type

public bool HasBlock(ExceptionBlockType type)

Parameters

type ExceptionBlockType

Type of the exception block to check for

Returns

bool

True if the instruction contains the exception block type, false otherwise

LoadArgument(int, bool)

Creates a CodeInstruction loading an argument with the given index, using the shorter forms when possible

public static CodeInstruction LoadArgument(int index, bool useAddress = false)

Parameters

index int

The index of the argument

useAddress bool

Use address of argument

Returns

CodeInstruction

A new Codeinstruction

See Also

LoadField(Type, string, bool)

Creates a CodeInstruction loading a field (LD[S]FLD[A])

public static CodeInstruction LoadField(Type type, string name, bool useAddress = false)

Parameters

type Type

The class/type where the field is defined

name string

The name of the field (case sensitive)

useAddress bool

Use address of field

Returns

CodeInstruction

A new Codeinstruction

LoadLocal(int, bool)

Creates a CodeInstruction loading a local with the given index, using the shorter forms when possible

public static CodeInstruction LoadLocal(int index, bool useAddress = false)

Parameters

index int

The index where the local is stored

useAddress bool

Use address of local

Returns

CodeInstruction

A new Codeinstruction

See Also

StoreArgument(int)

Creates a CodeInstruction storing to an argument with the given index, using the shorter forms when possible

public static CodeInstruction StoreArgument(int index)

Parameters

index int

The index of the argument

Returns

CodeInstruction

A new Codeinstruction

See Also

StoreField(Type, string)

Creates a CodeInstruction storing to a field (ST[S]FLD)

public static CodeInstruction StoreField(Type type, string name)

Parameters

type Type

The class/type where the field is defined

name string

The name of the field (case sensitive)

Returns

CodeInstruction

A new Codeinstruction

StoreLocal(int)

Creates a CodeInstruction storing to a local with the given index, using the shorter forms when possible

public static CodeInstruction StoreLocal(int index)

Parameters

index int

The index where the local is stored

Returns

CodeInstruction

A new Codeinstruction

See Also

ToString()

Returns a string representation of the code instruction

public override string ToString()

Returns

string

A string representation of the code instruction

Harmony 3 preview

For the stable release, read the 2.x documentation.