Show / Hide Table of Contents

Class CodeMatch

A CodeInstruction match

Inheritance
object
CodeInstruction
CodeMatch
Inherited Members
CodeInstruction.opcode
CodeInstruction.operand
CodeInstruction.labels
CodeInstruction.blocks
CodeInstruction.Clone()
CodeInstruction.Clone(OpCode)
CodeInstruction.Clone(object)
CodeInstruction.Call(Type, string, Type[], Type[])
CodeInstruction.Call(string, Type[], Type[])
CodeInstruction.Call(Expression<Action>)
CodeInstruction.Call<T>(Expression<Action<T>>)
CodeInstruction.Call<T, TResult>(Expression<Func<T, TResult>>)
CodeInstruction.Call(LambdaExpression)
CodeInstruction.CallClosure<T>(T)
CodeInstruction.LoadField(Type, string, bool)
CodeInstruction.StoreField(Type, string)
CodeInstruction.LoadLocal(int, bool)
CodeInstruction.StoreLocal(int)
CodeInstruction.LoadArgument(int, bool)
CodeInstruction.StoreArgument(int)
CodeInstruction.HasBlock(ExceptionBlockType)
Namespace: HarmonyLib
Assembly: 0Harmony.dll
Syntax
public class CodeMatch : CodeInstruction

Constructors

CodeMatch(CodeInstruction, string)

Creates a code match

Declaration
public CodeMatch(CodeInstruction instruction, string name = null)
Parameters
Type Name Description
CodeInstruction instruction

The CodeInstruction

string name

An optional name

CodeMatch(Func<CodeInstruction, bool>, string)

Creates a code match

Declaration
public CodeMatch(Func<CodeInstruction, bool> predicate, string name = null)
Parameters
Type Name Description
Func<CodeInstruction, bool> predicate

The predicate

string name

An optional name

CodeMatch(Expression<Action>, string)

Creates a code match that calls a method

Declaration
public CodeMatch(Expression<Action> expression, string name = null)
Parameters
Type Name Description
Expression<Action> expression

The lambda expression using the method

string name

The optional name

CodeMatch(LambdaExpression, string)

Creates a code match that calls a method

Declaration
public CodeMatch(LambdaExpression expression, string name = null)
Parameters
Type Name Description
LambdaExpression expression

The lambda expression using the method

string name

The optional name

CodeMatch(OpCode?, object, string)

Creates a code match

Declaration
public CodeMatch(OpCode? opcode = null, object operand = null, string name = null)
Parameters
Type Name Description
OpCode? opcode

The optional opcode

object operand

The optional operand

string name

The optional name

Fields

jumpsFrom

The jumps from the match

Declaration
public List<int> jumpsFrom
Field Value
Type Description
List<int>

jumpsTo

The jumps to the match

Declaration
public List<int> jumpsTo
Field Value
Type Description
List<int>

name

The name of the match

Declaration
public string name
Field Value
Type Description
string

opcodeSet

The matched opcodes

Declaration
public HashSet<OpCode> opcodeSet
Field Value
Type Description
HashSet<OpCode>

operands

The matched operands

Declaration
public List<object> operands
Field Value
Type Description
List<object>

predicate

The match predicate

Declaration
public Func<CodeInstruction, bool> predicate
Field Value
Type Description
Func<CodeInstruction, bool>

Methods

Branches(string)

Creates a code match for branching

Declaration
public static CodeMatch Branches(string name = null)
Parameters
Type Name Description
string name

An optional name

Returns
Type Description
CodeMatch

A new code match

Calls(Expression<Action>)

Creates a code match that calls a method

Declaration
public static CodeMatch Calls(Expression<Action> expression)
Parameters
Type Name Description
Expression<Action> expression

The lambda expression using the method

Returns
Type Description
CodeMatch

A new code match

Calls(LambdaExpression)

Creates a code match that calls a method

Declaration
public static CodeMatch Calls(LambdaExpression expression)
Parameters
Type Name Description
LambdaExpression expression

The lambda expression using the method

Returns
Type Description
CodeMatch

A new code match

Calls(MethodInfo)

Tests if the code instruction calls the method/constructor

Declaration
public static CodeMatch Calls(MethodInfo method)
Parameters
Type Name Description
MethodInfo method

The method

Returns
Type Description
CodeMatch

A new code match

IsLdarg(int?)

Tests for any form of Ldarg*

Declaration
public static CodeMatch IsLdarg(int? n = null)
Parameters
Type Name Description
int? n

The (optional) index

Returns
Type Description
CodeMatch

A new code match

IsLdarga(int?)

Tests for Ldarga/Ldarga_S

Declaration
public static CodeMatch IsLdarga(int? n = null)
Parameters
Type Name Description
int? n

The (optional) index

Returns
Type Description
CodeMatch

A new code match

IsLdloc(LocalBuilder)

Tests for any form of Ldloc*

Declaration
public static CodeMatch IsLdloc(LocalBuilder variable = null)
Parameters
Type Name Description
LocalBuilder variable

The optional local variable

Returns
Type Description
CodeMatch

A new code match

IsStarg(int?)

Tests for Starg/Starg_S

Declaration
public static CodeMatch IsStarg(int? n = null)
Parameters
Type Name Description
int? n

The (optional) index

Returns
Type Description
CodeMatch

A new code match

IsStloc(LocalBuilder)

Tests for any form of Stloc*

Declaration
public static CodeMatch IsStloc(LocalBuilder variable = null)
Parameters
Type Name Description
LocalBuilder variable

The optional local variable

Returns
Type Description
CodeMatch

A new code match

LoadsArgument(bool, string)

Creates a code match for argument loads

Declaration
public static CodeMatch LoadsArgument(bool useAddress = false, string name = null)
Parameters
Type Name Description
bool useAddress

Whether to match for address loads

string name

An optional name

Returns
Type Description
CodeMatch

A new code match

LoadsConstant()

Tests if the code instruction loads a constant

Declaration
public static CodeMatch LoadsConstant()
Returns
Type Description
CodeMatch

A new code match

LoadsConstant(double)

Tests if the code instruction loads a floating point constant

Declaration
public static CodeMatch LoadsConstant(double number)
Parameters
Type Name Description
double number

The floating point constant

Returns
Type Description
CodeMatch

A new code match

LoadsConstant(Enum)

Tests if the code instruction loads an enum constant

Declaration
public static CodeMatch LoadsConstant(Enum e)
Parameters
Type Name Description
Enum e

The enum

Returns
Type Description
CodeMatch

A new code match

LoadsConstant(long)

Tests if the code instruction loads an integer constant

Declaration
public static CodeMatch LoadsConstant(long number)
Parameters
Type Name Description
long number

The integer constant

Returns
Type Description
CodeMatch

A new code match

LoadsConstant(string)

Tests if the code instruction loads a string constant

Declaration
public static CodeMatch LoadsConstant(string str)
Parameters
Type Name Description
string str

The string

Returns
Type Description
CodeMatch

A new code match

LoadsField(FieldInfo, bool)

Tests if the code instruction loads a field

Declaration
public static CodeMatch LoadsField(FieldInfo field, bool byAddress = false)
Parameters
Type Name Description
FieldInfo field

The field

bool byAddress

Set to true if the address of the field is loaded

Returns
Type Description
CodeMatch

A new code match

LoadsLocal(bool, string)

Creates a code match for local loads

Declaration
public static CodeMatch LoadsLocal(bool useAddress = false, string name = null)
Parameters
Type Name Description
bool useAddress

Whether to match for address loads

string name

An optional name

Returns
Type Description
CodeMatch

A new code match

StoresArgument(string)

Creates a code match for argument stores

Declaration
public static CodeMatch StoresArgument(string name = null)
Parameters
Type Name Description
string name

An optional name

Returns
Type Description
CodeMatch

A new code match

StoresField(FieldInfo)

Tests if the code instruction stores a field

Declaration
public static CodeMatch StoresField(FieldInfo field)
Parameters
Type Name Description
FieldInfo field

The field

Returns
Type Description
CodeMatch

A new code match

StoresLocal(string)

Creates a code match for local stores

Declaration
public static CodeMatch StoresLocal(string name = null)
Parameters
Type Name Description
string name

An optional name

Returns
Type Description
CodeMatch

A new code match

ToString()

Returns a string that represents the match

Declaration
public override string ToString()
Returns
Type Description
string

A string representation

Overrides
CodeInstruction.ToString()

WithOpcodes(HashSet<OpCode>, object, string)

Creates a code match

Declaration
public static CodeMatch WithOpcodes(HashSet<OpCode> opcodes, object operand = null, string name = null)
Parameters
Type Name Description
HashSet<OpCode> opcodes

The opcodes

object operand

The optional operand

string name

The optional name

Returns
Type Description
CodeMatch

Extension Methods

CodeInstructionExtensions.ArgumentIndex(CodeInstruction)
CodeInstructionExtensions.Branches(CodeInstruction, out Label?)
CodeInstructionExtensions.Calls(CodeInstruction, MethodInfo)
CodeInstructionExtensions.ExtractBlocks(CodeInstruction)
CodeInstructionExtensions.ExtractLabels(CodeInstruction)
CodeInstructionExtensions.Is(CodeInstruction, OpCode, object)
CodeInstructionExtensions.IsLdarg(CodeInstruction, int?)
CodeInstructionExtensions.IsLdarga(CodeInstruction, int?)
CodeInstructionExtensions.IsLdloc(CodeInstruction, LocalBuilder)
CodeInstructionExtensions.IsStarg(CodeInstruction, int?)
CodeInstructionExtensions.IsStloc(CodeInstruction, LocalBuilder)
CodeInstructionExtensions.LoadsConstant(CodeInstruction)
CodeInstructionExtensions.LoadsConstant(CodeInstruction, double)
CodeInstructionExtensions.LoadsConstant(CodeInstruction, Enum)
CodeInstructionExtensions.LoadsConstant(CodeInstruction, long)
CodeInstructionExtensions.LoadsConstant(CodeInstruction, string)
CodeInstructionExtensions.LoadsField(CodeInstruction, FieldInfo, bool)
CodeInstructionExtensions.LocalIndex(CodeInstruction)
CodeInstructionExtensions.MoveBlocksFrom(CodeInstruction, CodeInstruction)
CodeInstructionExtensions.MoveBlocksTo(CodeInstruction, CodeInstruction)
CodeInstructionExtensions.MoveLabelsFrom(CodeInstruction, CodeInstruction)
CodeInstructionExtensions.MoveLabelsTo(CodeInstruction, CodeInstruction)
CodeInstructionExtensions.OperandIs(CodeInstruction, object)
CodeInstructionExtensions.StoresField(CodeInstruction, FieldInfo)
CodeInstructionExtensions.WithBlocks(CodeInstruction, params ExceptionBlock[])
CodeInstructionExtensions.WithBlocks(CodeInstruction, IEnumerable<ExceptionBlock>)
CodeInstructionExtensions.WithLabels(CodeInstruction, IEnumerable<Label>)
CodeInstructionExtensions.WithLabels(CodeInstruction, params Label[])
In this article
Back to top Generated by DocFX