ILWeaver Class
Definition
Section titled “Definition”An API for manipulating CIL method bodies. See https://monodetour.github.io/ilhooking/introduction/
public class ILWeaverInheritance object
Constructors
Section titled “Constructors”ILWeaver(ILManipulationInfo)
Section titled “ILWeaver(ILManipulationInfo)”Constructs a new ILWeaver instance for manipulating the target CIL method body. See https://monodetour.github.io/ilhooking/introduction/
public ILWeaver(ILManipulationInfo il)Parameters
Section titled “Parameters”ILWeaver(ILWeaver, bool)
Section titled “ILWeaver(ILWeaver, bool)”Create a new ILWeaver for the current ILManipulationInfo with state copied optionally.
public ILWeaver(ILWeaver weaver, bool copyState = true)Parameters
Section titled “Parameters”weaver ILWeaver
copyState bool
Properties
Section titled “Properties”ManipulationInfo
Section titled “ManipulationInfo”A manipulation info containing the MonoMod.Cil.ILContext intended for manipulation and an untouched MonoMod.Cil.ILContext useful for observing the untouched state, including the original method as a MethodBase if it exists.
public ILManipulationInfo ManipulationInfo { get; }Context
Section titled “Context”An IL manipulation “context” with various helpers and direct access to the MethodBody.
public ILContext Context { get; }The manipulated method’s IL processor.
public ILProcessor IL { get; }The manipulated method body.
public MethodBody Body { get; }Method
Section titled “Method”The manipulated method.
public MethodDefinition Method { get; }Instructions
Section titled “Instructions”The manipulated method instructions.
public Collection<Instruction> Instructions { get; }Current
Section titled “Current”The instruction this weaver currently points to.
public Instruction Current { get; set; }Remarks
Section titled “Remarks”Even if the method body would have no instructions, ILWeaver creates a temporary instruction on the method body to ensure this can always be used as a reference for inserting new instructions.
Setter is CurrentTo(Instruction).
For replacing the current instruction, see ReplaceCurrent(Instruction)
Previous
Section titled “Previous”The instruction before what this weaver currently points to.
public Instruction Previous { get; }The instruction after what this weaver currently points to.
public Instruction Next { get; }Remarks
Section titled “Remarks”This is not equivalent to MonoMod.Cil.ILCursor.Next. The equivalent would be Current.
Gets the first instruction in the method body.
public Instruction First { get; }Gets the last instruction in the method body.
public Instruction Last { get; }The index of the instruction on Current
public int Index { get; set; }Remarks
Section titled “Remarks”A negative index will loop back. Setter uses CurrentTo(int) which can throw.
LogFilter
Section titled “LogFilter”Filter for which channels this log source logs to.
public MonoDetourLogger.LogChannel LogFilter { get; set; }Methods
Section titled “Methods”Create a new ILWeaver for the current ILManipulationInfo using the ILWeaver(ILWeaver, bool) constructor.
Does not copy state.
public ILWeaver New()Returns
Section titled “Returns”ILWeaver
A new ILWeaver for the current ILManipulationInfo.
Clone()
Section titled “Clone()”Create a clone of the ILWeaver using the ILWeaver(ILWeaver, bool) constructor.
State is copied.
public ILWeaver Clone()Returns
Section titled “Returns”ILWeaver
A clone of the ILWeaver.
DeclareVariable(Type)
Section titled “DeclareVariable(Type)”Declare a new local variable on the target method.
A local variable can be assigned with a stloc instruction and loaded using an ldloc instruction. To assign or load this local variable, the returned VariableDefinition or its index should be used as the Operand.
public VariableDefinition DeclareVariable(Type type)Parameters
Section titled “Parameters”type Type
The type of the local variable.
Returns
Section titled “Returns”VariableDefinition
A new local variable.
DeclareVariable(Type, out VariableDefinition)
Section titled “DeclareVariable(Type, out VariableDefinition)”Declare a new local variable on the target method.
A local variable can be assigned with a stloc instruction and loaded using an ldloc instruction. To assign or load this local variable, the returned VariableDefinition or its index should be used as the Operand.
public ILWeaver DeclareVariable(Type type, out VariableDefinition variableDefinition)Parameters
Section titled “Parameters”type Type
The type of the local variable.
variableDefinition VariableDefinition
A new local variable.
Returns
Section titled “Returns”HandlerCreateCatch(Type?, out WeaverExceptionCatchHandler)
Section titled “HandlerCreateCatch(Type?, out WeaverExceptionCatchHandler)”Create a new IWeaverExceptionHandler to be assigned its ranges. Note that certain values can be figured out implicitly such as HandlerStart when TryEnd is defined.
The IWeaverExceptionHandler will automatically be applied to the method body after your manipulator method is finished.
public ILWeaver HandlerCreateCatch(Type? catchType, out WeaverExceptionCatchHandler handler)Parameters
Section titled “Parameters”catchType Type
The types of Exceptions that should be catched. If left null, Exception is used.
handler WeaverExceptionCatchHandler
The created IWeaverExceptionHandler to be configured.
Returns
Section titled “Returns”ILWeaver
The new exception handler instance.
Remarks
Section titled “Remarks”See WeaverExceptionCatchHandler for more information about this handler type.
HandlerCreateFilter(Type?, out WeaverExceptionFilterHandler)
Section titled “HandlerCreateFilter(Type?, out WeaverExceptionFilterHandler)”Create a new IWeaverExceptionHandler to be assigned its ranges. Note that certain values can be figured out implicitly such as HandlerStart when TryEnd is defined.
The IWeaverExceptionHandler will automatically be applied to the method body after your manipulator method is finished.
public ILWeaver HandlerCreateFilter(Type? catchType, out WeaverExceptionFilterHandler handler)Parameters
Section titled “Parameters”catchType Type
The types of Exceptions that should be catched. If left null, Exception is used.
handler WeaverExceptionFilterHandler
The created IWeaverExceptionHandler to be configured.
Returns
Section titled “Returns”ILWeaver
The new exception handler instance.
Remarks
Section titled “Remarks”See WeaverExceptionFilterHandler for more information about this handler type.
HandlerCreateFinally(out WeaverExceptionFinallyHandler)
Section titled “HandlerCreateFinally(out WeaverExceptionFinallyHandler)”Create a new IWeaverExceptionHandler to be assigned its ranges. Note that certain values can be figured out implicitly such as HandlerStart when TryEnd is defined.
The IWeaverExceptionHandler will automatically be applied to the method body after your manipulator method is finished.
public ILWeaver HandlerCreateFinally(out WeaverExceptionFinallyHandler handler)Parameters
Section titled “Parameters”handler WeaverExceptionFinallyHandler
The created IWeaverExceptionHandler to be configured.
Returns
Section titled “Returns”ILWeaver
The new exception handler instance.
Remarks
Section titled “Remarks”See WeaverExceptionFinallyHandler for more information about this handler type.
HandlerCreateFault(out WeaverExceptionFaultHandler)
Section titled “HandlerCreateFault(out WeaverExceptionFaultHandler)”Create a new IWeaverExceptionHandler to be assigned its ranges. Note that certain values can be figured out implicitly such as HandlerStart when TryEnd is defined.
The IWeaverExceptionHandler will automatically be applied to the method body after your manipulator method is finished.
public ILWeaver HandlerCreateFault(out WeaverExceptionFaultHandler handler)Parameters
Section titled “Parameters”handler WeaverExceptionFaultHandler
The created IWeaverExceptionHandler to be configured.
Returns
Section titled “Returns”ILWeaver
The new exception handler instance.
Remarks
Section titled “Remarks”See WeaverExceptionFaultHandler for more information about this handler type.
HandlerSetTryStart(ILLabel, IWeaverExceptionHandler)
Section titled “HandlerSetTryStart(ILLabel, IWeaverExceptionHandler)”Set the TryStart property of the IWeaverExceptionHandler.
public ILWeaver HandlerSetTryStart(ILLabel tryStart, IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”tryStart MonoMod.Cil.ILLabel
The first ILLabel in the try block.
handler IWeaverExceptionHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetTryStart(Instruction, IWeaverExceptionHandler)
Section titled “HandlerSetTryStart(Instruction, IWeaverExceptionHandler)”Set the TryStart property of the IWeaverExceptionHandler.
public ILWeaver HandlerSetTryStart(Instruction tryStart, IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”tryStart Instruction
The first ILLabel in the try block.
handler IWeaverExceptionHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetTryEnd(ILLabel, IWeaverExceptionHandler)
Section titled “HandlerSetTryEnd(ILLabel, IWeaverExceptionHandler)”Set the TryEnd property of the IWeaverExceptionHandler.
public ILWeaver HandlerSetTryEnd(ILLabel tryEnd, IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”tryEnd MonoMod.Cil.ILLabel
The last instruction in the try block.
handler IWeaverExceptionHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetTryEnd(Instruction, IWeaverExceptionHandler)
Section titled “HandlerSetTryEnd(Instruction, IWeaverExceptionHandler)”Set the TryEnd property of the IWeaverExceptionHandler.
public ILWeaver HandlerSetTryEnd(Instruction tryEnd, IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”tryEnd Instruction
The last instruction in the try block.
handler IWeaverExceptionHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetFilterStart(ILLabel, WeaverExceptionFilterHandler)
Section titled “HandlerSetFilterStart(ILLabel, WeaverExceptionFilterHandler)”Set the FilterStart property of the WeaverExceptionFilterHandler.
public ILWeaver HandlerSetFilterStart(ILLabel filterStart, WeaverExceptionFilterHandler handler)Parameters
Section titled “Parameters”filterStart MonoMod.Cil.ILLabel
The first ILLabel in the filter block.
handler WeaverExceptionFilterHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetFilterStart(Instruction, WeaverExceptionFilterHandler)
Section titled “HandlerSetFilterStart(Instruction, WeaverExceptionFilterHandler)”Set the FilterStart property of the WeaverExceptionFilterHandler.
public ILWeaver HandlerSetFilterStart(Instruction filterStart, WeaverExceptionFilterHandler handler)Parameters
Section titled “Parameters”filterStart Instruction
The first ILLabel in the filter block.
handler WeaverExceptionFilterHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetHandlerStart(ILLabel, IWeaverExceptionHandler)
Section titled “HandlerSetHandlerStart(ILLabel, IWeaverExceptionHandler)”Set the HandlerStart property of the IWeaverExceptionHandler.
public ILWeaver HandlerSetHandlerStart(ILLabel handlerStart, IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”handlerStart MonoMod.Cil.ILLabel
The first ILLabel in the catch block.
handler IWeaverExceptionHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetHandlerStart(Instruction, IWeaverExceptionHandler)
Section titled “HandlerSetHandlerStart(Instruction, IWeaverExceptionHandler)”Set the HandlerStart property of the IWeaverExceptionHandler.
public ILWeaver HandlerSetHandlerStart(Instruction handlerStart, IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”handlerStart Instruction
The first ILLabel in the catch block.
handler IWeaverExceptionHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetHandlerEnd(ILLabel, IWeaverExceptionHandler)
Section titled “HandlerSetHandlerEnd(ILLabel, IWeaverExceptionHandler)”Set the HandlerEnd property of the IWeaverExceptionHandler.
public ILWeaver HandlerSetHandlerEnd(ILLabel handlerEnd, IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”handlerEnd MonoMod.Cil.ILLabel
The last ILLabel in the catch block.
handler IWeaverExceptionHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerSetHandlerEnd(Instruction, IWeaverExceptionHandler)
Section titled “HandlerSetHandlerEnd(Instruction, IWeaverExceptionHandler)”Set the HandlerEnd property of the IWeaverExceptionHandler.
public ILWeaver HandlerSetHandlerEnd(Instruction handlerEnd, IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”handlerEnd Instruction
The last ILLabel in the catch block.
handler IWeaverExceptionHandler
The IWeaverExceptionHandler to configure.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”This range is inclusive.
HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type?, params IEnumerable<Instruction>)
Section titled “HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type?, params IEnumerable<Instruction>)”Wraps an area around Current where the stack size is non-zero to a try block, catching exceptions of type catchType. The argument catchInstructions is written as the catch block’s instructions.
After this method, Current will be on the instruction after the catch block.
public ILWeaver HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type? catchType, params IEnumerable<Instruction> catchInstructions)Parameters
Section titled “Parameters”catchType Type
The types of Exceptions that should be catched. If left null, Exception is used.
catchInstructions IEnumerable<Instruction>
The instructions to be written to the catch handler.
Returns
Section titled “Returns”HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type?, params IEnumerable<InstructionOrEnumerable>)
Section titled “HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type?, params IEnumerable<InstructionOrEnumerable>)”Wraps an area around Current where the stack size is non-zero to a try block, catching exceptions of type catchType. The argument catchInstructions is written as the catch block’s instructions.
After this method, Current will be on the instruction after the catch block.
public ILWeaver HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type? catchType, params IEnumerable<InstructionOrEnumerable> catchInstructions)Parameters
Section titled “Parameters”catchType Type
The types of Exceptions that should be catched. If left null, Exception is used.
catchInstructions IEnumerable<InstructionOrEnumerable>
The instructions to be written to the catch handler.
Returns
Section titled “Returns”HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type?, Action)
Section titled “HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type?, Action)”Wraps an area around Current where the stack size is non-zero to a try block, catching exceptions of type catchType. Catching logic can be written in the writeCatch callback, where at the start Current is the inclusive end of the try block, and at the end Current should be the end of the catch block.
After this method, Current will be on the instruction after the catch block.
public ILWeaver HandlerWrapTryCatchStackSizeNonZeroOnCurrent(Type? catchType, Action writeCatch)Parameters
Section titled “Parameters”catchType Type
The types of Exceptions that should be catched. If left null, Exception is used.
writeCatch Action
The callback where catch logic is written.
Returns
Section titled “Returns”HandlerWrapTryCatchStackSizeNonZero(Type?, Instruction, out Instruction, params IEnumerable<Instruction>)
Section titled “HandlerWrapTryCatchStackSizeNonZero(Type?, Instruction, out Instruction, params IEnumerable<Instruction>)”Wraps an area around origin where the stack size is non-zero to a try block, catching exceptions of type catchType. The argument catchInstructions is written as the catch block’s instructions.
public ILWeaver HandlerWrapTryCatchStackSizeNonZero(Type? catchType, Instruction origin, out Instruction afterCatch, params IEnumerable<Instruction> catchInstructions)Parameters
Section titled “Parameters”catchType Type
The types of Exceptions that should be catched. If left null, Exception is used.
origin Instruction
The instruction around which the area where stack size is non-zero is selected.
afterCatch Instruction
The instruction outside the written catch handler.
catchInstructions IEnumerable<Instruction>
The instructions to be written to the catch handler.
Returns
Section titled “Returns”HandlerWrapTryCatchStackSizeNonZero(Type?, Instruction, out Instruction, params IEnumerable<InstructionOrEnumerable>)
Section titled “HandlerWrapTryCatchStackSizeNonZero(Type?, Instruction, out Instruction, params IEnumerable<InstructionOrEnumerable>)”Wraps an area around origin where the stack size is non-zero to a try block, catching exceptions of type catchType. The argument catchInstructions is written as the catch block’s instructions.
public ILWeaver HandlerWrapTryCatchStackSizeNonZero(Type? catchType, Instruction origin, out Instruction afterCatch, params IEnumerable<InstructionOrEnumerable> catchInstructions)Parameters
Section titled “Parameters”catchType Type
The types of Exceptions that should be catched. If left null, Exception is used.
origin Instruction
The instruction around which the area where stack size is non-zero is selected.
afterCatch Instruction
The instruction outside the written catch handler.
catchInstructions IEnumerable<InstructionOrEnumerable>
The instructions to be written to the catch handler.
Returns
Section titled “Returns”HandlerWrapTryCatchStackSizeNonZero(Type?, Instruction, out Instruction, Func<Instruction, Instruction>)
Section titled “HandlerWrapTryCatchStackSizeNonZero(Type?, Instruction, out Instruction, Func<Instruction, Instruction>)”Wraps an area around origin where the stack size is non-zero to a try block, catching exceptions of type catchType. Catching logic can be written in the writeCatch callback, where the Instruction parameter is the inclusive end of the try block, and the return value is the end of the catch block.
public ILWeaver HandlerWrapTryCatchStackSizeNonZero(Type? catchType, Instruction origin, out Instruction afterCatch, Func<Instruction, Instruction> writeCatch)Parameters
Section titled “Parameters”catchType Type
The types of Exceptions that should be catched. If left null, Exception is used.
origin Instruction
The instruction around which the area where stack size is non-zero is selected.
afterCatch Instruction
The instruction outside the written catch handler.
writeCatch Func<Instruction, Instruction>
The callback where catch logic is written.
Returns
Section titled “Returns”HandlerApply(IWeaverExceptionHandler)
Section titled “HandlerApply(IWeaverExceptionHandler)”Note: This method is automatically called for all unapplied handlers after your manipulator method is finished. This wasn’t always the case, but it’s unlikely you’ll ever need to call this anymore.
Writes the leave instructions for try, catch or finally blocks and applies the provided IWeaverExceptionHandler to the method body.
public ILWeaver HandlerApply(IWeaverExceptionHandler handler)Parameters
Section titled “Parameters”handler IWeaverExceptionHandler
The handler to apply.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”Remarks
Section titled “Remarks”Once applied, the leave label of the handler leave instructions will point to the instruction that comes after what was set as HandlerEnd. Make sure that once you have applied the IWeaverExceptionHandler, you are not inserting instructions before the HandlerEnd or you’ll need to retarget the leave label to your first inserted instruction before the EndHandler.
Replace(Instruction, Instruction)
Section titled “Replace(Instruction, Instruction)”Replaces the target instruction.
public ILWeaver Replace(Instruction target, Instruction replacement)Parameters
Section titled “Parameters”target Instruction
The instruction to replace.
replacement Instruction
The replacement instruction.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The target instruction instance is left untouched and instead the actual instance of the instruction that replaces it takes its place, and as such it steals all the labels of target to itself.
If Current points to the instruction being replaced, it is moved to the replacement instruction.
Replace(Instruction, params IEnumerable<Instruction>)
Section titled “Replace(Instruction, params IEnumerable<Instruction>)”Replaces the target instruction with the first instruction of the replacement IEnumerable and inserts the rest of the instructions after.
public ILWeaver Replace(Instruction target, params IEnumerable<Instruction> replacement)Parameters
Section titled “Parameters”target Instruction
The instruction to replace.
replacement IEnumerable<Instruction>
The replacement instructions. The first instruction replaces the target.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The target instruction instance is left untouched and instead the actual instance of the instruction that replaces it takes its place, and as such it steals all the labels of target to itself.
If Current points to the instruction being replaced, it is moved to the replacement instruction.
Replace(Instruction, params IEnumerable<InstructionOrEnumerable>)
Section titled “Replace(Instruction, params IEnumerable<InstructionOrEnumerable>)”Replaces the target instruction with the first instruction of the replacement IEnumerable and inserts the rest of the instructions after.
public ILWeaver Replace(Instruction target, params IEnumerable<InstructionOrEnumerable> replacement)Parameters
Section titled “Parameters”target Instruction
The instruction to replace.
replacement IEnumerable<InstructionOrEnumerable>
The replacement instructions. The first instruction replaces the target.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The target instruction instance is left untouched and instead the actual instance of the instruction that replaces it takes its place, and as such it steals all the labels of target to itself.
If Current points to the instruction being replaced, it is moved to the replacement instruction.
ReplaceCurrent(Instruction)
Section titled “ReplaceCurrent(Instruction)”Replaces the instruction at Current.
public ILWeaver ReplaceCurrent(Instruction replacement)Parameters
Section titled “Parameters”replacement Instruction
The replacement instruction.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The Current instruction instance is left untouched and instead the actual instance of the instruction that replaces it takes its place, and as such it steals all the labels of Current to itself.
ReplaceCurrent(params IEnumerable<Instruction>)
Section titled “ReplaceCurrent(params IEnumerable<Instruction>)”Replaces the Current instruction with the first instruction of the replacement IEnumerable and inserts the rest of the instructions after.
public ILWeaver ReplaceCurrent(params IEnumerable<Instruction> replacement)Parameters
Section titled “Parameters”replacement IEnumerable<Instruction>
The replacement instructions. The first instruction replaces the Current.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The Current instruction instance is left untouched and instead the actual instance of the instruction that replaces it takes its place, and as such it steals all the labels of Current to itself.
ReplaceCurrent(params IEnumerable<InstructionOrEnumerable>)
Section titled “ReplaceCurrent(params IEnumerable<InstructionOrEnumerable>)”Replaces the Current instruction with the first instruction of the replacement IEnumerable and inserts the rest of the instructions after.
public ILWeaver ReplaceCurrent(params IEnumerable<InstructionOrEnumerable> replacement)Parameters
Section titled “Parameters”replacement IEnumerable<InstructionOrEnumerable>
The replacement instructions. The first instruction replaces the Current.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The Current instruction instance is left untouched and instead the actual instance of the instruction that replaces it takes its place, and as such it steals all the labels of Current to itself.
ReplaceOperand(Instruction, object)
Section titled “ReplaceOperand(Instruction, object)”Replaces the target instruction’s Operand.
public ILWeaver ReplaceOperand(Instruction target, object replacementOperand)Parameters
Section titled “Parameters”target Instruction
The instruction whose Operand to replace.
replacementOperand object
The new operand value to replace the old one.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The target instruction instance is left untouched and instead a copy of the instruction with the replacement operand takes its place, and as such it steals all the labels of target to itself.
If Current points to the instruction being replaced, it is moved to the replacement instruction.
ReplaceCurrentOperand(object)
Section titled “ReplaceCurrentOperand(object)”Replaces the Current instruction’s Operand.
public ILWeaver ReplaceCurrentOperand(object replacementOperand)Parameters
Section titled “Parameters”replacementOperand object
The new operand value to replace the old one.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The Current instruction instance is left untouched and instead a copy of the instruction with the replacement operand takes its place, and as such it steals all the labels of Current to itself.
RemoveAndShiftLabels(Instruction)
Section titled “RemoveAndShiftLabels(Instruction)”Removes the provided instruction from the method body and moves all its labels and exception handler range roles to the next instruction.
Important: If you are removing an instruction to replace it, use Replace(Instruction, Instruction) or any of the variants instead.
public ILWeaver RemoveAndShiftLabels(Instruction instruction)Parameters
Section titled “Parameters”instruction Instruction
The instruction to remove.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If there is no next instruction, the previous instruction will be the shift target. If there is no previous instruction either, the next inserted instruction will be the new shift target.
If Current points to an instruction to be removed, it is moved to the next instruction alongside the labels.
Note: Removing instructions have consequences as described by this method. This method does what is necessary to not break the target method in cases where labels would not be shifted. As such, there is no variant which does not shift labels (that is not deprecate anyways).
RemoveCurrentAndShiftLabels()
Section titled “RemoveCurrentAndShiftLabels()”Removes Current from the method body and moves all its labels and exception handler range roles to the next instruction.
Important: If you are removing an instruction to replace it, use ReplaceCurrent(Instruction) or any of the variants instead.
public ILWeaver RemoveCurrentAndShiftLabels()Returns
Section titled “Returns”Remarks
Section titled “Remarks”If there is no next instruction, the previous instruction will be the shift target. If there is no previous instruction either, the next inserted instruction will be the new shift target.
If Current points to an instruction to be removed, it is moved to the next instruction alongside the labels.
Note: Removing instructions have consequences as described by this method. This method does what is necessary to not break the target method in cases where labels would not be shifted. As such, there is no variant which does not shift labels (that is not deprecate anyways).
RemoveRangeAndShiftLabels(Instruction, Instruction)
Section titled “RemoveRangeAndShiftLabels(Instruction, Instruction)”Removes the instructions in the inclusive start to end range from the method body and moves all their labels and exception handler range roles to the next available instruction.
public ILWeaver RemoveRangeAndShiftLabels(Instruction start, Instruction end)Parameters
Section titled “Parameters”start Instruction
The first instruction in the range to remove.
end Instruction
The last instruction in the range to remove.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The order of start and end does not matter.
If there is no next instruction, the previous instruction will be the shift target. If there is no previous instruction either, the next inserted instruction will be the new shift target.
If Current points to an instruction to be removed, it is moved to the next available instruction alongside the labels.
Exception handlers: If the range contains the HandlerStart and previous instruction of HandlerEnd of an exception handler in a single RemoveRangeAndShiftLabels(Instruction, Instruction) call, the exception handler is removed from the method body as leaving it be would cause invalid IL. If you wish to rewrite the handler block instead, don’t remove the previous instruction of the leave target which is HandlerEnd.
Note: Removing instructions have consequences as described by this method. This method does what is necessary to not break the target method in cases where labels would not be shifted. As such, there is no variant which does not shift labels (that is not deprecate anyways).
InsertBeforeStealLabels(int, params IEnumerable<Instruction>)
Section titled “InsertBeforeStealLabels(int, params IEnumerable<Instruction>)”Insert instructions before the provided index, stealing any labels.
public ILWeaver InsertBeforeStealLabels(int index, params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”index int
instructions IEnumerable<Instruction>
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Stealing labels means that if the instruction at the provided instruction or index has incoming MonoMod.Cil.ILLabels or is inside the start of a try, filter, catch, finally, or fault range, then the first inserted instruction will become the new start of that range or label. The same applies to the ends of these handler ranges because they are exclusive, meaning that the inclusive end of a range is before the instruction marked as the end.
InsertBeforeStealLabels(int, params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBeforeStealLabels(int, params IEnumerable<InstructionOrEnumerable>)”Insert instructions before the provided index, stealing any labels.
public ILWeaver InsertBeforeStealLabels(int index, params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”index int
instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Stealing labels means that if the instruction at the provided instruction or index has incoming MonoMod.Cil.ILLabels or is inside the start of a try, filter, catch, finally, or fault range, then the first inserted instruction will become the new start of that range or label. The same applies to the ends of these handler ranges because they are exclusive, meaning that the inclusive end of a range is before the instruction marked as the end.
InsertBeforeStealLabels(Instruction, params IEnumerable<Instruction>)
Section titled “InsertBeforeStealLabels(Instruction, params IEnumerable<Instruction>)”Insert instructions before the provided instruction, stealing any labels.
public ILWeaver InsertBeforeStealLabels(Instruction target, params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”target Instruction
instructions IEnumerable<Instruction>
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Stealing labels means that if the instruction at the provided instruction or index has incoming MonoMod.Cil.ILLabels or is inside the start of a try, filter, catch, finally, or fault range, then the first inserted instruction will become the new start of that range or label. The same applies to the ends of these handler ranges because they are exclusive, meaning that the inclusive end of a range is before the instruction marked as the end.
InsertBeforeStealLabels(Instruction, params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBeforeStealLabels(Instruction, params IEnumerable<InstructionOrEnumerable>)”Insert instructions before the provided instruction, stealing any labels.
public ILWeaver InsertBeforeStealLabels(Instruction target, params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”target Instruction
instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Stealing labels means that if the instruction at the provided instruction or index has incoming MonoMod.Cil.ILLabels or is inside the start of a try, filter, catch, finally, or fault range, then the first inserted instruction will become the new start of that range or label. The same applies to the ends of these handler ranges because they are exclusive, meaning that the inclusive end of a range is before the instruction marked as the end.
InsertBeforeCurrentStealLabels(params IEnumerable<Instruction>)
Section titled “InsertBeforeCurrentStealLabels(params IEnumerable<Instruction>)”Insert instructions before this weaver’s current position, stealing any labels. Current target doesn’t change.
public ILWeaver InsertBeforeCurrentStealLabels(params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”instructions IEnumerable<Instruction>
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Stealing labels means that if the instruction at the provided instruction or index has incoming MonoMod.Cil.ILLabels or is inside the start of a try, filter, catch, finally, or fault range, then the first inserted instruction will become the new start of that range or label. The same applies to the ends of these handler ranges because they are exclusive, meaning that the inclusive end of a range is before the instruction marked as the end.
InsertBeforeCurrentStealLabels(params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBeforeCurrentStealLabels(params IEnumerable<InstructionOrEnumerable>)”Insert instructions before this weaver’s current position, stealing any labels. Current target doesn’t change.
public ILWeaver InsertBeforeCurrentStealLabels(params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Stealing labels means that if the instruction at the provided instruction or index has incoming MonoMod.Cil.ILLabels or is inside the start of a try, filter, catch, finally, or fault range, then the first inserted instruction will become the new start of that range or label. The same applies to the ends of these handler ranges because they are exclusive, meaning that the inclusive end of a range is before the instruction marked as the end.
InsertBefore(int, params IEnumerable<Instruction>)
Section titled “InsertBefore(int, params IEnumerable<Instruction>)”Insert instructions before the provided index.
public ILWeaver InsertBefore(int index, params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”index int
instructions IEnumerable<Instruction>
Returns
Section titled “Returns”InsertBefore(int, params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBefore(int, params IEnumerable<InstructionOrEnumerable>)”Insert instructions before the provided index.
public ILWeaver InsertBefore(int index, params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”index int
instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”InsertBefore(Instruction, params IEnumerable<Instruction>)
Section titled “InsertBefore(Instruction, params IEnumerable<Instruction>)”Insert instructions before the provided instruction.
public ILWeaver InsertBefore(Instruction target, params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”target Instruction
instructions IEnumerable<Instruction>
Returns
Section titled “Returns”InsertBefore(Instruction, params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBefore(Instruction, params IEnumerable<InstructionOrEnumerable>)”Insert instructions before the provided instruction.
public ILWeaver InsertBefore(Instruction target, params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”target Instruction
instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”InsertBeforeCurrent(params IEnumerable<Instruction>)
Section titled “InsertBeforeCurrent(params IEnumerable<Instruction>)”Insert instructions before this weaver’s current position.
public ILWeaver InsertBeforeCurrent(params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”instructions IEnumerable<Instruction>
Returns
Section titled “Returns”InsertBeforeCurrent(params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBeforeCurrent(params IEnumerable<InstructionOrEnumerable>)”Insert instructions before this weaver’s current position.
public ILWeaver InsertBeforeCurrent(params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”InsertAfter(int, params IEnumerable<Instruction>)
Section titled “InsertAfter(int, params IEnumerable<Instruction>)”Insert instructions after the provided index.
public ILWeaver InsertAfter(int index, params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”index int
instructions IEnumerable<Instruction>
Returns
Section titled “Returns”InsertAfter(int, params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertAfter(int, params IEnumerable<InstructionOrEnumerable>)”Insert instructions after the provided index.
public ILWeaver InsertAfter(int index, params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”index int
instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”InsertAfter(Instruction, params IEnumerable<Instruction>)
Section titled “InsertAfter(Instruction, params IEnumerable<Instruction>)”Insert instructions after the provided instruction.
public ILWeaver InsertAfter(Instruction target, params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”target Instruction
instructions IEnumerable<Instruction>
Returns
Section titled “Returns”InsertAfter(Instruction, params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertAfter(Instruction, params IEnumerable<InstructionOrEnumerable>)”Insert instructions after the provided instruction.
public ILWeaver InsertAfter(Instruction target, params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”target Instruction
instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”InsertAfterCurrent(params IEnumerable<Instruction>)
Section titled “InsertAfterCurrent(params IEnumerable<Instruction>)”Insert instructions after this weaver’s current position. Retargets Current to the last inserted instruction.
public ILWeaver InsertAfterCurrent(params IEnumerable<Instruction> instructions)Parameters
Section titled “Parameters”instructions IEnumerable<Instruction>
Returns
Section titled “Returns”InsertAfterCurrent(params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertAfterCurrent(params IEnumerable<InstructionOrEnumerable>)”Insert instructions after this weaver’s current position. Retargets Current to the last inserted instruction.
public ILWeaver InsertAfterCurrent(params IEnumerable<InstructionOrEnumerable> instructions)Parameters
Section titled “Parameters”instructions IEnumerable<InstructionOrEnumerable>
Returns
Section titled “Returns”InsertBranchOverIfTrue(Instruction, Instruction, params IEnumerable<Instruction>)
Section titled “InsertBranchOverIfTrue(Instruction, Instruction, params IEnumerable<Instruction>)”Inserts a brtrue instruction before start instruction which, if the provided condition returns true (non-zero on the stack), branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOverIfTrue(Instruction start, Instruction end, params IEnumerable<Instruction> condition)Parameters
Section titled “Parameters”start Instruction
The first instruction to branch over.
end Instruction
The last instruction to branch over.
condition IEnumerable<Instruction>
A list of instructions which end up leaving one (1) value on the stack which represents either true (non-zero value, e.g. ldc.i4.1) or false (zero e.g. ldc.i4.0) which will be evaluated by brtrue.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOverIfTrue(Instruction, Instruction, params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBranchOverIfTrue(Instruction, Instruction, params IEnumerable<InstructionOrEnumerable>)”Inserts a brtrue instruction before start instruction which, if the provided condition returns true (non-zero on the stack), branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOverIfTrue(Instruction start, Instruction end, params IEnumerable<InstructionOrEnumerable> condition)Parameters
Section titled “Parameters”start Instruction
The first instruction to branch over.
end Instruction
The last instruction to branch over.
condition IEnumerable<InstructionOrEnumerable>
A list of instructions which end up leaving one (1) value on the stack which represents either true (non-zero value, e.g. ldc.i4.1) or false (zero e.g. ldc.i4.0) which will be evaluated by brtrue.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOverIfTrue((Instruction start, Instruction end), params IEnumerable<Instruction>)
Section titled “InsertBranchOverIfTrue((Instruction start, Instruction end), params IEnumerable<Instruction>)”Inserts a brtrue instruction before start instruction which, if the provided condition returns true (non-zero on the stack), branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOverIfTrue((Instruction start, Instruction end) range, params IEnumerable<Instruction> condition)Parameters
Section titled “Parameters”range (Instruction start, Instruction end)
A tuple of the first and last instructions to branch over.
condition IEnumerable<Instruction>
A list of instructions which end up leaving one (1) value on the stack which represents either true (non-zero value, e.g. ldc.i4.1) or false (zero e.g. ldc.i4.0) which will be evaluated by brtrue.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOverIfTrue((Instruction start, Instruction end), params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBranchOverIfTrue((Instruction start, Instruction end), params IEnumerable<InstructionOrEnumerable>)”Inserts a brtrue instruction before start instruction which, if the provided condition returns true (non-zero on the stack), branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOverIfTrue((Instruction start, Instruction end) range, params IEnumerable<InstructionOrEnumerable> condition)Parameters
Section titled “Parameters”range (Instruction start, Instruction end)
A tuple of the first and last instructions to branch over.
condition IEnumerable<InstructionOrEnumerable>
A list of instructions which end up leaving one (1) value on the stack which represents either true (non-zero value, e.g. ldc.i4.1) or false (zero e.g. ldc.i4.0) which will be evaluated by brtrue.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOverIfFalse(Instruction, Instruction, params IEnumerable<Instruction>)
Section titled “InsertBranchOverIfFalse(Instruction, Instruction, params IEnumerable<Instruction>)”Inserts a brfalse instruction before start instruction which, if the provided condition returns false (zero on the stack), branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOverIfFalse(Instruction start, Instruction end, params IEnumerable<Instruction> condition)Parameters
Section titled “Parameters”start Instruction
The first instruction to branch over.
end Instruction
The last instruction to branch over.
condition IEnumerable<Instruction>
A list of instructions which end up leaving one (1) value on the stack which represents either true (non-zero value, e.g. ldc.i4.1) or false (zero e.g. ldc.i4.0) which will be evaluated by brfalse.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOverIfFalse(Instruction, Instruction, params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBranchOverIfFalse(Instruction, Instruction, params IEnumerable<InstructionOrEnumerable>)”Inserts a brfalse instruction before start instruction which, if the provided condition returns false (zero on the stack), branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOverIfFalse(Instruction start, Instruction end, params IEnumerable<InstructionOrEnumerable> condition)Parameters
Section titled “Parameters”start Instruction
The first instruction to branch over.
end Instruction
The last instruction to branch over.
condition IEnumerable<InstructionOrEnumerable>
A list of instructions which end up leaving one (1) value on the stack which represents either true (non-zero value, e.g. ldc.i4.1) or false (zero e.g. ldc.i4.0) which will be evaluated by brfalse.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOverIfFalse((Instruction start, Instruction end), params IEnumerable<Instruction>)
Section titled “InsertBranchOverIfFalse((Instruction start, Instruction end), params IEnumerable<Instruction>)”Inserts a brfalse instruction before start instruction which, if the provided condition returns false (zero on the stack), branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOverIfFalse((Instruction start, Instruction end) range, params IEnumerable<Instruction> condition)Parameters
Section titled “Parameters”range (Instruction start, Instruction end)
A tuple of the first and last instructions to branch over.
condition IEnumerable<Instruction>
A list of instructions which end up leaving one (1) value on the stack which represents either true (non-zero value, e.g. ldc.i4.1) or false (zero e.g. ldc.i4.0) which will be evaluated by brfalse.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOverIfFalse((Instruction start, Instruction end), params IEnumerable<InstructionOrEnumerable>)
Section titled “InsertBranchOverIfFalse((Instruction start, Instruction end), params IEnumerable<InstructionOrEnumerable>)”Inserts a brfalse instruction before start instruction which, if the provided condition returns false (zero on the stack), branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOverIfFalse((Instruction start, Instruction end) range, params IEnumerable<InstructionOrEnumerable> condition)Parameters
Section titled “Parameters”range (Instruction start, Instruction end)
A tuple of the first and last instructions to branch over.
condition IEnumerable<InstructionOrEnumerable>
A list of instructions which end up leaving one (1) value on the stack which represents either true (non-zero value, e.g. ldc.i4.1) or false (zero e.g. ldc.i4.0) which will be evaluated by brfalse.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOver(Instruction, Instruction)
Section titled “InsertBranchOver(Instruction, Instruction)”Inserts a br instruction before start instruction which unconditionally branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOver(Instruction start, Instruction end)Parameters
Section titled “Parameters”start Instruction
The first instruction to branch over.
end Instruction
The last instruction to branch over.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
InsertBranchOver((Instruction start, Instruction end))
Section titled “InsertBranchOver((Instruction start, Instruction end))”Inserts a br instruction before start instruction which unconditionally branches OVER the end instruction, thus the instruction after “end” is branched to.
public ILWeaver InsertBranchOver((Instruction start, Instruction end) range)Parameters
Section titled “Parameters”range (Instruction start, Instruction end)
A tuple of the first and last instructions to branch over.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”If control flow would fall or branch to start instruction, the inserted instruction runs. However if the start instruction is skipped in control flow, the inserted instruction is also skipped. This means instructions after start and up to end are possible to execute if they are directly branched to.
EmitReferenceBefore<T>(Instruction, in T?, out int)
Section titled “EmitReferenceBefore<T>(Instruction, in T?, out int)”Store an object in the reference store, and emit the IL to retrieve it and place it on the stack.
public ILWeaver EmitReferenceBefore<T>(Instruction target, in T? value, out int id)Parameters
Section titled “Parameters”target Instruction
value T
id int
Returns
Section titled “Returns”EmitReferenceBeforeCurrent<T>(in T?, out int)
Section titled “EmitReferenceBeforeCurrent<T>(in T?, out int)”Store an object in the reference store, and emit the IL to retrieve it and place it on the stack.
public ILWeaver EmitReferenceBeforeCurrent<T>(in T? value, out int id)Parameters
Section titled “Parameters”value T
id int
Returns
Section titled “Returns”Create(OpCode, ParameterDefinition)
Section titled “Create(OpCode, ParameterDefinition)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, ParameterDefinition parameter)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
parameter ParameterDefinition
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, VariableDefinition)
Section titled “Create(OpCode, VariableDefinition)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, VariableDefinition variable)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
variable VariableDefinition
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, Instruction[])
Section titled “Create(OpCode, Instruction[])”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, Instruction[] targets)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
targets Instruction[]
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, Instruction)
Section titled “Create(OpCode, Instruction)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, Instruction target)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
target Instruction
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, double)
Section titled “Create(OpCode, double)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, double value)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
value double
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, float)
Section titled “Create(OpCode, float)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, float value)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
value float
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, long)
Section titled “Create(OpCode, long)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, long value)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
value long
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, sbyte)
Section titled “Create(OpCode, sbyte)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, sbyte value)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
value sbyte
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, byte)
Section titled “Create(OpCode, byte)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, byte value)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
value byte
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, string)
Section titled “Create(OpCode, string)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, string value)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
value string
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, FieldReference)
Section titled “Create(OpCode, FieldReference)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, FieldReference field)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
field FieldReference
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, CallSite)
Section titled “Create(OpCode, CallSite)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, CallSite site)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
site CallSite
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, TypeReference)
Section titled “Create(OpCode, TypeReference)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, TypeReference type)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
type TypeReference
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode)
Section titled “Create(OpCode)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, int)
Section titled “Create(OpCode, int)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, int value)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
value int
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, MethodReference)
Section titled “Create(OpCode, MethodReference)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, MethodReference method)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
method MethodReference
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, FieldInfo)
Section titled “Create(OpCode, FieldInfo)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, FieldInfo field)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
field FieldInfo
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, MethodBase)
Section titled “Create(OpCode, MethodBase)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, MethodBase method)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
method MethodBase
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, Type)
Section titled “Create(OpCode, Type)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, Type type)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
type Type
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Create(OpCode, object)
Section titled “Create(OpCode, object)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create(OpCode opcode, object operand)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
operand object
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”CreateCall(Delegate)
Section titled “CreateCall(Delegate)”Create a new instruction to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction CreateCall(Delegate method)Parameters
Section titled “Parameters”method Delegate
The instruction operand.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”Remarks
Section titled “Remarks”If the delegate method isn’t static, its instance must be pushed to the stack first.
The delegate method must not be a lambda expression, as one requires an anonymous instance to be loaded. If it is a lambda expression, use CreateDelegateCall<T>(T) instead.
CreateDelegateCall<T>(T)
Section titled “CreateDelegateCall<T>(T)”Creates instructions to invoke a Delegate as if it were a method. Stack behaviour matches the call OpCode.
Normally a Delegate would need to be invoked by pushing the Delegate instance as the first argument to the stack, after which every other argument is pushed. Then, the Delegate is invoked with a callvirt instruction.
With this method, the Delegate instance is automatically stored and loaded for you, and you can simply push all arguments to the stack and then call this method to create the required instructions to invoke the Delegate.
public Instruction[] CreateDelegateCall<T>(T @delegate) where T : DelegateParameters
Section titled “Parameters”delegate T
The Delegate method to be invoked.
Returns
Section titled “Returns”Instruction[]
An array of Instruction, containing all the instructions required to invoke the Delegate.
Create<T>(OpCode, string)
Section titled “Create<T>(OpCode, string)”Create a new instruction accessing a given member, to be emitted by InsertBeforeCurrent(params IEnumerable<Instruction>) or any of the variations.
public Instruction Create<T>(OpCode opcode, string memberName)Parameters
Section titled “Parameters”opcode OpCode
The instruction opcode.
memberName string
The accessed member name.
Returns
Section titled “Returns”Instruction
The created instruction.
Exceptions
Section titled “Exceptions”GetIncomingLabelsFor(Instruction)
Section titled “GetIncomingLabelsFor(Instruction)”Gets all branching labels pointing to the provided instruction.
public IEnumerable<ILLabel> GetIncomingLabelsFor(Instruction target)Parameters
Section titled “Parameters”target Instruction
The target instruction for the labels.
Returns
Section titled “Returns”GetIncomingLabelsForCurrent()
Section titled “GetIncomingLabelsForCurrent()”Gets all branching labels pointing to Current.
public IEnumerable<ILLabel> GetIncomingLabelsForCurrent()Returns
Section titled “Returns”RetargetLabels(IEnumerable<ILLabel>, Instruction)
Section titled “RetargetLabels(IEnumerable<ILLabel>, Instruction)”Retargets ILLabels to a target instruction.
public ILWeaver RetargetLabels(IEnumerable<ILLabel> labels, Instruction target)Parameters
Section titled “Parameters”labels IEnumerable<ILLabel>
The labels to retarget.
target Instruction
The new target instruction for labels.
Returns
Section titled “Returns”RetargetLabels(Instruction, Instruction)
Section titled “RetargetLabels(Instruction, Instruction)”Retargets ILLabels targeting source instruction to target instruction.
public ILWeaver RetargetLabels(Instruction source, Instruction target)Parameters
Section titled “Parameters”source Instruction
The instruction whose labels to retarget.
target Instruction
The new target instruction for labels.
Returns
Section titled “Returns”RetargetLabels(ILLabel?, Instruction)
Section titled “RetargetLabels(ILLabel?, Instruction)”Retargets ILLabels to a target instruction.
public ILWeaver RetargetLabels(ILLabel? label, Instruction target)Parameters
Section titled “Parameters”label MonoMod.Cil.ILLabel
The label to retarget.
target Instruction
The new target instruction for labels.
Returns
Section titled “Returns”DefineLabel()
Section titled “DefineLabel()”Defines a new MonoMod.Cil.ILLabel to be targeted.
public ILLabel DefineLabel()Returns
Section titled “Returns”MonoMod.Cil.ILLabel
The new MonoMod.Cil.ILLabel.
DefineLabel(out ILLabel)
Section titled “DefineLabel(out ILLabel)”Defines a new MonoMod.Cil.ILLabel to be targeted.
public ILWeaver DefineLabel(out ILLabel label)Parameters
Section titled “Parameters”label MonoMod.Cil.ILLabel
The new label.
Returns
Section titled “Returns”MarkLabelTo(Instruction, ILLabel)
Section titled “MarkLabelTo(Instruction, ILLabel)”Sets the target of a label to the provided Instruction.
public ILWeaver MarkLabelTo(Instruction target, ILLabel label)Parameters
Section titled “Parameters”target Instruction
The target for the label.
label MonoMod.Cil.ILLabel
The label to mark.
Returns
Section titled “Returns”DefineAndMarkLabelTo(Instruction, out ILLabel)
Section titled “DefineAndMarkLabelTo(Instruction, out ILLabel)”Creates a new label targetting the provided Instruction.
public ILWeaver DefineAndMarkLabelTo(Instruction target, out ILLabel markedLabel)Parameters
Section titled “Parameters”target Instruction
The target for the label.
markedLabel MonoMod.Cil.ILLabel
The marked label.
Returns
Section titled “Returns”DefineAndMarkLabelTo(Instruction)
Section titled “DefineAndMarkLabelTo(Instruction)”Creates a new label targetting the provided Instruction.
public ILLabel DefineAndMarkLabelTo(Instruction target)Parameters
Section titled “Parameters”target Instruction
The target for the label.
Returns
Section titled “Returns”MonoMod.Cil.ILLabel
The new MonoMod.Cil.ILLabel.
MarkLabelToFutureNextInsert(ILLabel)
Section titled “MarkLabelToFutureNextInsert(ILLabel)”Sets the target of a label to the future next inserted instruction.
public ILWeaver MarkLabelToFutureNextInsert(ILLabel label)Parameters
Section titled “Parameters”label MonoMod.Cil.ILLabel
The label to mark.
Returns
Section titled “Returns”DefineAndMarkLabelToFutureNextInsert(out ILLabel)
Section titled “DefineAndMarkLabelToFutureNextInsert(out ILLabel)”Creates a new label targetting the future next inserted instruction.
public ILWeaver DefineAndMarkLabelToFutureNextInsert(out ILLabel futureMarkedLabel)Parameters
Section titled “Parameters”futureMarkedLabel MonoMod.Cil.ILLabel
The marked label.
Returns
Section titled “Returns”DefineAndMarkLabelToFutureNextInsert()
Section titled “DefineAndMarkLabelToFutureNextInsert()”Creates a new label targetting the future next inserted instruction.
public ILLabel DefineAndMarkLabelToFutureNextInsert()Returns
Section titled “Returns”MonoMod.Cil.ILLabel
The new MonoMod.Cil.ILLabel.
MarkLabelToCurrentOrFutureNextInsert(ILLabel)
Section titled “MarkLabelToCurrentOrFutureNextInsert(ILLabel)”Sets the target of a label to the future next inserted instruction.
Targets Current as a placeholder.
public ILWeaver MarkLabelToCurrentOrFutureNextInsert(ILLabel label)Parameters
Section titled “Parameters”label MonoMod.Cil.ILLabel
The label to mark.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Prefer MarkLabelToFutureNextInsert(ILLabel) if the label will always be redirected to an inserted instruction. Using this method will then show that there branches where a next instruction isn’t inserted.
DefineAndMarkLabelToCurrentOrFutureNextInsert(out ILLabel)
Section titled “DefineAndMarkLabelToCurrentOrFutureNextInsert(out ILLabel)”Creates a new label targetting the future next inserted instruction.
Targets Current as a placeholder.
public ILWeaver DefineAndMarkLabelToCurrentOrFutureNextInsert(out ILLabel futureMarkedLabel)Parameters
Section titled “Parameters”futureMarkedLabel MonoMod.Cil.ILLabel
The marked label.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Prefer DefineAndMarkLabelToFutureNextInsert(out ILLabel) if the label will always be redirected to an inserted instruction. Using this method will then show that there branches where a next instruction isn’t inserted.
DefineAndMarkLabelToCurrentOrFutureNextInsert()
Section titled “DefineAndMarkLabelToCurrentOrFutureNextInsert()”Creates a new label targetting the future next inserted instruction.
Targets Current as a placeholder.
public ILLabel DefineAndMarkLabelToCurrentOrFutureNextInsert()Returns
Section titled “Returns”MonoMod.Cil.ILLabel
The new MonoMod.Cil.ILLabel.
Remarks
Section titled “Remarks”Prefer DefineAndMarkLabelToFutureNextInsert(out ILLabel) if the label will always be redirected to an inserted instruction. Using this method will then show that there branches where a next instruction isn’t inserted.
MarkLabelToCurrent(ILLabel)
Section titled “MarkLabelToCurrent(ILLabel)”Sets the target of a label to Current.
public ILWeaver MarkLabelToCurrent(ILLabel label)Parameters
Section titled “Parameters”label MonoMod.Cil.ILLabel
The label to mark.
Returns
Section titled “Returns”DefineAndMarkLabelToCurrent(out ILLabel)
Section titled “DefineAndMarkLabelToCurrent(out ILLabel)”Creates a new label targetting Current.
public ILWeaver DefineAndMarkLabelToCurrent(out ILLabel markedLabel)Parameters
Section titled “Parameters”markedLabel MonoMod.Cil.ILLabel
The marked label.
Returns
Section titled “Returns”DefineAndMarkLabelToCurrent()
Section titled “DefineAndMarkLabelToCurrent()”Creates a new label targetting Current.
public ILLabel DefineAndMarkLabelToCurrent()Returns
Section titled “Returns”MonoMod.Cil.ILLabel
The new MonoMod.Cil.ILLabel.
MarkLabelToCurrentPrevious(ILLabel)
Section titled “MarkLabelToCurrentPrevious(ILLabel)”Sets the target of a label to Current’s Previous.
public ILWeaver MarkLabelToCurrentPrevious(ILLabel label)Parameters
Section titled “Parameters”label MonoMod.Cil.ILLabel
The label to mark.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The label will point to the Previous instruction at the moment of calling this method.
DefineAndMarkLabelToCurrentPrevious(out ILLabel)
Section titled “DefineAndMarkLabelToCurrentPrevious(out ILLabel)”Creates a new label targetting Current’s Previous.
public ILWeaver DefineAndMarkLabelToCurrentPrevious(out ILLabel markedLabel)Parameters
Section titled “Parameters”markedLabel MonoMod.Cil.ILLabel
The marked label.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The label will point to the Previous instruction at the moment of calling this method.
DefineAndMarkLabelToCurrentPrevious()
Section titled “DefineAndMarkLabelToCurrentPrevious()”Creates a new label targetting Current’s Previous.
public ILLabel DefineAndMarkLabelToCurrentPrevious()Returns
Section titled “Returns”MonoMod.Cil.ILLabel
The new MonoMod.Cil.ILLabel.
Remarks
Section titled “Remarks”The label will point to the Previous instruction at the moment of calling this method.
MarkLabelToCurrentNext(ILLabel)
Section titled “MarkLabelToCurrentNext(ILLabel)”Sets the target of a label to Current’s Next.
public ILWeaver MarkLabelToCurrentNext(ILLabel label)Parameters
Section titled “Parameters”label MonoMod.Cil.ILLabel
The label to mark.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The label will point to the Next instruction at the moment of calling this method.
DefineAndMarkLabelToCurrentNext(out ILLabel)
Section titled “DefineAndMarkLabelToCurrentNext(out ILLabel)”Creates a new label targetting Current’s Next.
public ILWeaver DefineAndMarkLabelToCurrentNext(out ILLabel markedLabel)Parameters
Section titled “Parameters”markedLabel MonoMod.Cil.ILLabel
The marked label.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”The label will point to the Next instruction at the moment of calling this method.
DefineAndMarkLabelToCurrentNext()
Section titled “DefineAndMarkLabelToCurrentNext()”Creates a new label targetting Current’s Next.
public ILLabel DefineAndMarkLabelToCurrentNext()Returns
Section titled “Returns”MonoMod.Cil.ILLabel
The new MonoMod.Cil.ILLabel.
Remarks
Section titled “Remarks”The label will point to the Next instruction at the moment of calling this method.
CurrentTo(int)
Section titled “CurrentTo(int)”Set Current to a target index. See also CurrentTo(Instruction)
public ILWeaver CurrentTo(int index)Parameters
Section titled “Parameters”index int
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”Remarks
Section titled “Remarks”A negative index will loop back.
CurrentTo(Instruction)
Section titled “CurrentTo(Instruction)”Set Current to a target instruction. See also CurrentTo(int)
For use in MatchRelaxed(params Predicate<Instruction>[]) and other variations, use SetCurrentTo(Instruction) as that method returns true.
[MemberNotNull("current")]public ILWeaver CurrentTo(Instruction instruction)Parameters
Section titled “Parameters”instruction Instruction
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”SetCurrentTo(Instruction)
Section titled “SetCurrentTo(Instruction)”Set Current to a target instruction like CurrentTo(Instruction), except for use in MatchRelaxed(params Predicate<Instruction>[]) and other variations.
public bool SetCurrentTo(Instruction instruction)Parameters
Section titled “Parameters”instruction Instruction
The instruction to set as current.
Returns
Section titled “Returns”bool
Whether or not the instruction exists in the current method body.
SetInstructionTo(ref Instruction?, Instruction)
Section titled “SetInstructionTo(ref Instruction?, Instruction)”Set instruction to a target instruction for use in MatchRelaxed(params Predicate<Instruction>[]) and other variations.
public bool SetInstructionTo(ref Instruction? toBeSet, Instruction target)Parameters
Section titled “Parameters”toBeSet Instruction
The instruction to be set.
target Instruction
The instruction toBeSet will be set to.
Returns
Section titled “Returns”bool
Whether or not the target instruction exists in the current method body.
CurrentToNext()
Section titled “CurrentToNext()”Sets Current to the instruction after it.
public ILWeaver CurrentToNext()Returns
Section titled “Returns”CurrentToPrevious()
Section titled “CurrentToPrevious()”Sets Current to the instruction before it.
public ILWeaver CurrentToPrevious()Returns
Section titled “Returns”GetStackSizeZeroBeforeContinuous(Instruction, IInformationalMethodBody?)
Section titled “GetStackSizeZeroBeforeContinuous(Instruction, IInformationalMethodBody?)”Gets the first reachable instruction backward whose incoming stack size is 0, without any branching.
public Instruction GetStackSizeZeroBeforeContinuous(Instruction start, IInformationalMethodBody? informationalBody = null)Parameters
Section titled “Parameters”start Instruction
The instruction to start searching at.
informationalBody IInformationalMethodBody
The IInformationalMethodBody whose IInformationalInstructions’ stack size to check. An IInformationalMethodBody should not be reused after the method has been modified.
Returns
Section titled “Returns”GetStackSizeZeroAfterContinuous(Instruction, IInformationalMethodBody?)
Section titled “GetStackSizeZeroAfterContinuous(Instruction, IInformationalMethodBody?)”Gets the first reachable instruction forward whose stack size is 0, without any branching.
public Instruction GetStackSizeZeroAfterContinuous(Instruction start, IInformationalMethodBody? informationalBody = null)Parameters
Section titled “Parameters”start Instruction
The instruction to start searching at.
informationalBody IInformationalMethodBody
The IInformationalMethodBody whose IInformationalInstructions’ stack size to check. An IInformationalMethodBody should not be reused after the method has been modified.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”GetStackSizeZeroAreaContinuous(Instruction, IInformationalMethodBody?)
Section titled “GetStackSizeZeroAreaContinuous(Instruction, IInformationalMethodBody?)”Gets the both the first reachable instruction backward whose incoming stack size is 0, and the first instruction forward whose stack size is 0, without any branching.
public (Instruction start, Instruction end) GetStackSizeZeroAreaContinuous(Instruction start, IInformationalMethodBody? informationalBody = null)Parameters
Section titled “Parameters”start Instruction
informationalBody IInformationalMethodBody
Returns
Section titled “Returns”(Instruction start, Instruction end)
A tuple with the start and end instructions.
MatchRelaxed(params Predicate<Instruction>[])
Section titled “MatchRelaxed(params Predicate<Instruction>[])”Attempts to match a set of predicates to find one specific location in the instructions. This method searches the entire target method to ensure the match predicates are matching exactly what was attempted to match.
If the match fails, the match is attempted again against the “original” instructions of the method before it was manipulated. As such, you must NEVER offset Current to another predicate by index, as there may be instructions in between, or that instruction may not even exist in the current method body.
If you want to match multiple locations, use MatchMultipleRelaxed(Action<ILWeaver>, params Predicate<Instruction>[])
weaver .MatchRelaxed( x => x.MatchLdloc(1), x => x.MatchBrtrue(out _) && weaver.SetCurrentTo(x) ) .ThrowIfFailure() .InsertBeforeCurrent(weaver.Create(OpCodes.Call, GetCustomNumber));public ILWeaverResult MatchRelaxed(params Predicate<Instruction>[] predicates)Parameters
Section titled “Parameters”predicates Predicate<Instruction>[]
The predicates to match against.
Returns
Section titled “Returns”ILWeaverResult
An ILWeaverResult which can be used for checking if the match was a success or a failure.
MatchStrict(params Predicate<Instruction>[])
Section titled “MatchStrict(params Predicate<Instruction>[])”Attempts to match a set of predicates to find one specific location in the instructions. This method searches the entire target method to ensure the match predicates are matching exactly what was attempted to match.
Only a 1:1 match of the current method instructions matching predicates in order are accepted unlike with MatchRelaxed(params Predicate<Instruction>[]). As such you should use that method instead to keep your match more compatible with other mods, unless if you really know what you are doing.
If you want to match multiple locations, use MatchMultipleStrict(Action<ILWeaver>, params Predicate<Instruction>[])
weaver .MatchStrict( x => x.MatchLdloc(1), x => x.MatchBrtrue(out _) && weaver.SetCurrentTo(x) ) .ThrowIfFailure() .InsertBeforeCurrent(weaver.Create(OpCodes.Call, GetCustomNumber));public ILWeaverResult MatchStrict(params Predicate<Instruction>[] predicates)Parameters
Section titled “Parameters”predicates Predicate<Instruction>[]
The predicates to match against.
Returns
Section titled “Returns”ILWeaverResult
An ILWeaverResult which can be used for checking if the match was a success or a failure.
MatchMultipleRelaxed(Action<ILWeaver>, params Predicate<Instruction>[])
Section titled “MatchMultipleRelaxed(Action<ILWeaver>, params Predicate<Instruction>[])”Attempts to match a set of predicates multiple times to find specific locations in the instructions.
If the match fails, the match is attempted again against the “original” instructions of the method before it was manipulated. As such, you must NEVER offset Current to another predicate by index, as there may be instructions in between, or that instruction may not even exist in the current method body.
onMatch delegate’s argument. This means that the ILWeaver you run this method on will keep its original Current even if it’s set in the predicates.
weaver .MatchMultipleRelaxed( onMatch: matchWeaver => { matchWeaver.InsertBeforeCurrent( matchWeaver.Create(OpCodes.Call, GetCustomNumber) ); }, x => x.MatchLdloc(1), x => x.MatchBrtrue(out _) && weaver.SetCurrentTo(x) ) .ThrowIfFailure();public ILWeaverResult MatchMultipleRelaxed(Action<ILWeaver> onMatch, params Predicate<Instruction>[] predicates)Parameters
Section titled “Parameters”onMatch Action<ILWeaver>
A delegate which runs for each match, passing a copy of the original ILWeaver with the Current pointing to the one at the time of the match.
predicates Predicate<Instruction>[]
The predicates to match against.
Returns
Section titled “Returns”ILWeaverResult
An ILWeaverResult which can be used for checking if the match was a success or a failure.
MatchMultipleStrict(Action<ILWeaver>, params Predicate<Instruction>[])
Section titled “MatchMultipleStrict(Action<ILWeaver>, params Predicate<Instruction>[])”Attempts to match a set of predicates multiple times to find specific locations in the instructions.
Only a 1:1 match of the current method instructions matching predicates in order are accepted unlike with MatchMultipleRelaxed(Action<ILWeaver>, params Predicate<Instruction>[]). As such you should use that method instead to keep your match more compatible with other mods, unless if you really know what you are doing.
onMatch delegate’s argument. This means that the ILWeaver you run this method on will keep its original Current even if it’s set in the predicates.
weaver .MatchMultipleStrict( onMatch: matchWeaver => { matchWeaver.InsertBeforeCurrent( matchWeaver.Create(OpCodes.Call, GetCustomNumber) ); }, x => x.MatchLdloc(1), x => x.MatchBrtrue(out _) && weaver.SetCurrentTo(x) ) .ThrowIfFailure();public ILWeaverResult MatchMultipleStrict(Action<ILWeaver> onMatch, params Predicate<Instruction>[] predicates)Parameters
Section titled “Parameters”onMatch Action<ILWeaver>
A delegate which runs for each match, passing a copy of the original ILWeaver with the Current pointing to the one at the time of the match.
predicates Predicate<Instruction>[]
The predicates to match against.
Returns
Section titled “Returns”ILWeaverResult
An ILWeaverResult which can be used for checking if the match was a success or a failure.