Class CodeMatch
- Namespace
- HarmonyLib
- Assembly
- 0Harmony.dll
A CodeInstruction match
public class CodeMatch : CodeInstruction
- Inheritance
-
objectCodeMatch
- Inherited Members
- Extension Methods
Constructors
CodeMatch(CodeInstruction, string)
Creates a code match
public CodeMatch(CodeInstruction instruction, string name = null)
Parameters
instructionCodeInstructionThe CodeInstruction
namestringAn optional name
CodeMatch(Func<CodeInstruction, bool>, string)
Creates a code match
public CodeMatch(Func<CodeInstruction, bool> predicate, string name = null)
Parameters
predicateFunc<CodeInstruction, bool>The predicate
namestringAn optional name
CodeMatch(Expression<Action>, string)
Creates a code match that calls a method
public CodeMatch(Expression<Action> expression, string name = null)
Parameters
expressionExpression<Action>The lambda expression using the method
namestringThe optional name
CodeMatch(LambdaExpression, string)
Creates a code match that calls a method
public CodeMatch(LambdaExpression expression, string name = null)
Parameters
expressionLambdaExpressionThe lambda expression using the method
namestringThe optional name
CodeMatch(OpCode?, object, string)
Creates a code match
public CodeMatch(OpCode? opcode = null, object operand = null, string name = null)
Parameters
opcodeOpCode?The optional opcode
operandobjectThe optional operand
namestringThe optional name
Fields
jumpsFrom
The jumps from the match
public List<int> jumpsFrom
Field Value
- List<int>
jumpsTo
The jumps to the match
public List<int> jumpsTo
Field Value
- List<int>
name
The name of the match
public string name
Field Value
- string
opcodeSet
The matched opcodes
public HashSet<OpCode> opcodeSet
Field Value
- HashSet<OpCode>
operands
The matched operands
public List<object> operands
Field Value
- List<object>
predicate
The match predicate
public Func<CodeInstruction, bool> predicate
Field Value
- Func<CodeInstruction, bool>
Methods
Branches(string)
Creates a code match for branching
public static CodeMatch Branches(string name = null)
Parameters
namestringAn optional name
Returns
- CodeMatch
A new code match
Calls(Expression<Action>)
Creates a code match that calls a method
public static CodeMatch Calls(Expression<Action> expression)
Parameters
expressionExpression<Action>The lambda expression using the method
Returns
- CodeMatch
A new code match
Calls(LambdaExpression)
Creates a code match that calls a method
public static CodeMatch Calls(LambdaExpression expression)
Parameters
expressionLambdaExpressionThe lambda expression using the method
Returns
- CodeMatch
A new code match
Calls(ConstructorInfo)
Tests if the code instruction calls the constructor
public static CodeMatch Calls(ConstructorInfo constructor)
Parameters
constructorConstructorInfoThe constructor
Returns
- CodeMatch
A new code match
Calls(MethodInfo)
Tests if the code instruction calls the method
public static CodeMatch Calls(MethodInfo method)
Parameters
methodMethodInfoThe method
Returns
- CodeMatch
A new code match
GetsProperty(PropertyInfo)
Tests if the code instruction calls the getter of a property
public static CodeMatch GetsProperty(PropertyInfo property)
Parameters
propertyPropertyInfoThe property
Returns
- CodeMatch
A new code match
Remarks
The match compares the called method with the getter, like Calls(MethodInfo). C# code calls an overridden property through the getter of its base declaration. To match those calls, pass the base property or use the expression overload.
Exceptions
- ArgumentNullException
The property is null
- ArgumentException
The property has no getter
GetsProperty<T>(Expression<Func<T>>)
Tests if the code instruction calls the getter of a property
public static CodeMatch GetsProperty<T>(Expression<Func<T>> expression)
Parameters
expressionExpression<Func<T>>The lambda expression reading the property, for example
() => default(MyClass).MyProperty
Returns
- CodeMatch
A new code match
Type Parameters
TThe property type
Exceptions
- ArgumentNullException
The expression is null
- ArgumentException
The expression does not read a property, or the property has no getter
IsLdarg(int?)
Tests for any form of Ldarg*
public static CodeMatch IsLdarg(int? n = null)
Parameters
nint?The (optional) index
Returns
- CodeMatch
A new code match
IsLdarga(int?)
Tests for Ldarga/Ldarga_S
public static CodeMatch IsLdarga(int? n = null)
Parameters
nint?The (optional) index
Returns
- CodeMatch
A new code match
IsLdloc(LocalBuilder)
Tests for any form of Ldloc*
public static CodeMatch IsLdloc(LocalBuilder variable = null)
Parameters
variableLocalBuilderThe optional local variable
Returns
- CodeMatch
A new code match
IsStarg(int?)
Tests for Starg/Starg_S
public static CodeMatch IsStarg(int? n = null)
Parameters
nint?The (optional) index
Returns
- CodeMatch
A new code match
IsStloc(LocalBuilder)
Tests for any form of Stloc*
public static CodeMatch IsStloc(LocalBuilder variable = null)
Parameters
variableLocalBuilderThe optional local variable
Returns
- CodeMatch
A new code match
LoadsArgument(bool, string)
Creates a code match for argument loads
public static CodeMatch LoadsArgument(bool useAddress = false, string name = null)
Parameters
useAddressboolWhether to match for address loads
namestringAn optional name
Returns
- CodeMatch
A new code match
LoadsConstant()
Tests if the code instruction loads a constant
public static CodeMatch LoadsConstant()
Returns
- CodeMatch
A new code match
LoadsConstant(double)
Tests if the code instruction loads a floating point constant
public static CodeMatch LoadsConstant(double number)
Parameters
numberdoubleThe floating point constant
Returns
- CodeMatch
A new code match
LoadsConstant(Enum)
Tests if the code instruction loads an enum constant
public static CodeMatch LoadsConstant(Enum e)
Parameters
eEnumThe enum
Returns
- CodeMatch
A new code match
LoadsConstant(long)
Tests if the code instruction loads an integer constant
public static CodeMatch LoadsConstant(long number)
Parameters
numberlongThe integer constant
Returns
- CodeMatch
A new code match
LoadsConstant(string)
Tests if the code instruction loads a string constant
public static CodeMatch LoadsConstant(string str)
Parameters
strstringThe string
Returns
- CodeMatch
A new code match
LoadsField(FieldInfo, bool)
Tests if the code instruction loads a field
public static CodeMatch LoadsField(FieldInfo field, bool byAddress = false)
Parameters
fieldFieldInfoThe field
byAddressboolSet to true if the address of the field is loaded
Returns
- CodeMatch
A new code match
LoadsField<T>(Expression<Func<T>>, bool)
Tests if the code instruction loads a field
public static CodeMatch LoadsField<T>(Expression<Func<T>> expression, bool byAddress = false)
Parameters
expressionExpression<Func<T>>The lambda expression using the field
byAddressboolSet to true if the address of the field is loaded
Returns
- CodeMatch
A new code match
Type Parameters
TThe field type
LoadsLocal(bool, string)
Creates a code match for local loads
public static CodeMatch LoadsLocal(bool useAddress = false, string name = null)
Parameters
useAddressboolWhether to match for address loads
namestringAn optional name
Returns
- CodeMatch
A new code match
SetsProperty(PropertyInfo)
Tests if the code instruction calls the setter of a property
public static CodeMatch SetsProperty(PropertyInfo property)
Parameters
propertyPropertyInfoThe property
Returns
- CodeMatch
A new code match
Remarks
The match compares the called method with the setter, like Calls(MethodInfo). C# code calls an overridden property through the setter of its base declaration. To match those calls, pass the base property or use the expression overload.
Exceptions
- ArgumentNullException
The property is null
- ArgumentException
The property has no setter
SetsProperty<T>(Expression<Func<T>>)
Tests if the code instruction calls the setter of a property
public static CodeMatch SetsProperty<T>(Expression<Func<T>> expression)
Parameters
expressionExpression<Func<T>>The lambda expression reading the property, for example
() => default(MyClass).MyProperty. C# expression trees cannot contain assignments, so the expression only names the property.
Returns
- CodeMatch
A new code match
Type Parameters
TThe property type
Exceptions
- ArgumentNullException
The expression is null
- ArgumentException
The expression does not read a property, or the property has no setter
StoresArgument(string)
Creates a code match for argument stores
public static CodeMatch StoresArgument(string name = null)
Parameters
namestringAn optional name
Returns
- CodeMatch
A new code match
StoresField(FieldInfo)
Tests if the code instruction stores a field
public static CodeMatch StoresField(FieldInfo field)
Parameters
fieldFieldInfoThe field
Returns
- CodeMatch
A new code match
StoresField<T>(Expression<Func<T>>)
Tests if the code instruction stores a field
public static CodeMatch StoresField<T>(Expression<Func<T>> expression)
Parameters
expressionExpression<Func<T>>The lambda expression using the field
Returns
- CodeMatch
A new code match
Type Parameters
TThe field type
StoresLocal(string)
Creates a code match for local stores
public static CodeMatch StoresLocal(string name = null)
Parameters
namestringAn optional name
Returns
- CodeMatch
A new code match
ToString()
Returns a string that represents the match
public override string ToString()
Returns
- string
A string representation
WithOpcodes(HashSet<OpCode>, object, string)
Creates a code match
public static CodeMatch WithOpcodes(HashSet<OpCode> opcodes, object operand = null, string name = null)
Parameters
opcodesHashSet<OpCode>The opcodes
operandobjectThe optional operand
namestringThe optional name
Returns
- CodeMatch
A new code match