docs/api/HarmonyLib.CodeInstructionExtensions.html
Extensions for CodeInstruction
System.Object
CodeInstructionExtensions
public static class CodeInstructionExtensions
Returns the index targeted by this ldarg, ldarga, or starg
public static int ArgumentIndex(this CodeInstruction code)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
|
| Type | Description |
|---|---|
| System.Int32 |
The index it targets
|
LoadArgument(System.Int32, System.Boolean)
StoreArgument(System.Int32)
Tests if the code instruction branches
public static bool Branches(this CodeInstruction code, out Label? label)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Nullable\ | label |
The label if the instruction is a branch operation or null if not
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction branches
|
Tests if the code instruction calls the method/constructor
public static bool Calls(this CodeInstruction code, MethodInfo method)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.MethodInfo | method |
The method
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction calls the method or constructor
|
Extracts all ExceptionBlocks from the code instruction and returns them
public static List<ExceptionBlock> ExtractBlocks(this CodeInstruction code)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
|
| Type | Description |
|---|---|
| System.Collections.Generic.List<ExceptionBlock> |
A list of ExceptionBlock
|
Extracts all labels from the code instruction and returns them
public static List<Label> ExtractLabels(this CodeInstruction code)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
|
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of System.Reflection.Emit.Label
|
Shortcut for
code.opcode == opcode && code.OperandIs(operand)
public static bool Is(this CodeInstruction code, OpCode opcode, object operand)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.Emit.OpCode | opcode |
The System.Reflection.Emit.OpCode
| | System.Object | operand |
The operand value
|
| Type | Description |
|---|---|
| System.Boolean |
True if the opcode is equal to the given opcode and the operand has the same type and is equal to the given operand
|
Shortcut for
code.opcode == opcode && code.OperandIs(operand)
public static bool Is(this CodeInstruction code, OpCode opcode, MemberInfo operand)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.Emit.OpCode | opcode |
The System.Reflection.Emit.OpCode
| | System.Reflection.MemberInfo | operand |
The System.Reflection.MemberInfo operand value
|
| Type | Description |
|---|---|
| System.Boolean |
True if the opcode is equal to the given opcode and the operand is equal to the given operand
|
This is an optimized version of Is(CodeInstruction, OpCode, Object) for System.Reflection.MemberInfo
Tests for any form of Ldarg*
public static bool IsLdarg(this CodeInstruction code, int? n = default(int? ))
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Nullable\ | n |
The (optional) index
|
| Type | Description |
|---|---|
| System.Boolean |
True if it matches one of the variations
|
Tests for Ldarga/Ldarga_S
public static bool IsLdarga(this CodeInstruction code, int? n = default(int? ))
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Nullable\ | n |
The (optional) index
|
| Type | Description |
|---|---|
| System.Boolean |
True if it matches one of the variations
|
Tests for any form of Ldloc*
public static bool IsLdloc(this CodeInstruction code, LocalBuilder variable = null)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.Emit.LocalBuilder | variable |
The optional local variable
|
| Type | Description |
|---|---|
| System.Boolean |
True if it matches one of the variations
|
Tests for Starg/Starg_S
public static bool IsStarg(this CodeInstruction code, int? n = default(int? ))
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Nullable\ | n |
The (optional) index
|
| Type | Description |
|---|---|
| System.Boolean |
True if it matches one of the variations
|
Tests for any form of Stloc*
public static bool IsStloc(this CodeInstruction code, LocalBuilder variable = null)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.Emit.LocalBuilder | variable |
The optional local variable
|
| Type | Description |
|---|---|
| System.Boolean |
True if it matches one of the variations
|
Returns if an System.Reflection.Emit.OpCode is initialized and valid
public static bool IsValid(this OpCode code)
| Type | Name | Description |
|---|---|---|
| System.Reflection.Emit.OpCode | code |
The System.Reflection.Emit.OpCode
|
| Type | Description |
|---|---|
| System.Boolean |
Tests if the code instruction loads a constant
public static bool LoadsConstant(this CodeInstruction code)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction loads a constant
|
Tests if the code instruction loads a floating point constant
public static bool LoadsConstant(this CodeInstruction code, double number)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Double | number |
The floating point constant
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction loads the constant
|
Tests if the code instruction loads an enum constant
public static bool LoadsConstant(this CodeInstruction code, Enum e)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Enum | e |
The enum
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction loads the constant
|
Tests if the code instruction loads an integer constant
public static bool LoadsConstant(this CodeInstruction code, long number)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Int64 | number |
The integer constant
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction loads the constant
|
Tests if the code instruction loads a string constant
public static bool LoadsConstant(this CodeInstruction code, string str)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.String | str |
The string
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction loads the constant
|
Tests if the code instruction loads a field
public static bool LoadsField(this CodeInstruction code, FieldInfo field, bool byAddress = false)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.FieldInfo | field |
The field
| | System.Boolean | byAddress |
Set to true if the address of the field is loaded
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction loads the field
|
Returns the index targeted by this ldloc, ldloca, or stloc
public static int LocalIndex(this CodeInstruction code)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
|
| Type | Description |
|---|---|
| System.Int32 |
The index it targets
|
LoadLocal(System.Int32, System.Boolean)
StoreLocal(System.Int32)
Moves all ExceptionBlocks from another code instruction to the current one
public static CodeInstruction MoveBlocksFrom(this CodeInstruction code, CodeInstruction other)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction to move the ExceptionBlocks to
| | CodeInstruction | other |
The other CodeInstruction to move the ExceptionBlocks from
|
| Type | Description |
|---|---|
| CodeInstruction |
The code instruction that received the blocks
|
Moves all ExceptionBlocks from the code instruction to another one
public static CodeInstruction MoveBlocksTo(this CodeInstruction code, CodeInstruction other)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction to move the ExceptionBlocks from
| | CodeInstruction | other |
The other CodeInstruction to move the ExceptionBlocks to
|
| Type | Description |
|---|---|
| CodeInstruction |
The code instruction blocks were moved from (now empty)
|
Moves all labels from another code instruction to the current one
public static CodeInstruction MoveLabelsFrom(this CodeInstruction code, CodeInstruction other)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction to move the labels to
| | CodeInstruction | other |
The other CodeInstruction to move the labels from
|
| Type | Description |
|---|---|
| CodeInstruction |
The code instruction that received the labels
|
Moves all labels from the code instruction to another one
public static CodeInstruction MoveLabelsTo(this CodeInstruction code, CodeInstruction other)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction to move the labels from
| | CodeInstruction | other |
The other CodeInstruction to move the labels to
|
| Type | Description |
|---|---|
| CodeInstruction |
The code instruction labels were moved from (now empty)
|
Shortcut for testing whether the operand is equal to a non-null value
public static bool OperandIs(this CodeInstruction code, object value)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Object | value |
The value
|
| Type | Description |
|---|---|
| System.Boolean |
True if the operand has the same type and is equal to the value
|
Shortcut for testing whether the operand is equal to a non-null value
public static bool OperandIs(this CodeInstruction code, MemberInfo value)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.MemberInfo | value |
The System.Reflection.MemberInfo value
|
| Type | Description |
|---|---|
| System.Boolean |
True if the operand is equal to the value
|
This is an optimized version of OperandIs(CodeInstruction, Object) for System.Reflection.MemberInfo
Tests if the code instruction stores a field
public static bool StoresField(this CodeInstruction code, FieldInfo field)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.FieldInfo | field |
The field
|
| Type | Description |
|---|---|
| System.Boolean |
True if the instruction stores this field
|
Adds ExceptionBlocks to the code instruction and return it
public static CodeInstruction WithBlocks(this CodeInstruction code, params ExceptionBlock[] blocks)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | ExceptionBlock[] | blocks |
One or several ExceptionBlock to add
|
| Type | Description |
|---|---|
| CodeInstruction |
The same code instruction
|
Adds ExceptionBlocks to the code instruction and return it
public static CodeInstruction WithBlocks(this CodeInstruction code, IEnumerable<ExceptionBlock> blocks)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Collections.Generic.IEnumerable<ExceptionBlock> | blocks |
An enumeration of ExceptionBlock
|
| Type | Description |
|---|---|
| CodeInstruction |
The same code instruction
|
Adds labels to the code instruction and return it
public static CodeInstruction WithLabels(this CodeInstruction code, IEnumerable<Label> labels)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Collections.Generic.IEnumerable\ | labels |
An enumeration of System.Reflection.Emit.Label
|
| Type | Description |
|---|---|
| CodeInstruction |
The same code instruction
|
Adds labels to the code instruction and return it
public static CodeInstruction WithLabels(this CodeInstruction code, params Label[] labels)
| Type | Name | Description |
|---|---|---|
| CodeInstruction | code |
The CodeInstruction
| | System.Reflection.Emit.Label[] | labels |
One or several System.Reflection.Emit.Label to add
|
| Type | Description |
|---|---|
| CodeInstruction |
The same code instruction
|