C# Class OTAPI.Patcher.Engine.Extensions.WrappingExtensions

Exibir arquivo Open project: DeathCradle/Open-Terraria-API

Public Methods

Method Description
CreateMethodParameter ( this method, int index ) : Instruction

Creates a new parameter instruction for a method.

Useful if you are altering IL in a method and need a parameter reference

EmitBeginCallback ( this current, MethodReference callback, bool instanceMethod, bool callbackRequiresInstance, bool isCancelable, int parameterOffset ) : Instruction

Emits il for a callback at the start of a method

EmitEndCallback ( this current, MethodReference callback, bool instanceMethod, bool callbackRequiresInstance ) : void

Emits a method-end callback into the current method. Optionally, if is specified it will insert a 'this' argument that will be sent to the first parameter of the callback.

EmitMethodCallback ( this method, MethodReference target, bool methodExpectsInstance, bool emitNonVoidPop = true ) : Instruction

Emits IL that is used to execute a generic method call.

We use this to execute a vanilla wrapped method

EmitMethodEnding ( this method, bool noHandling = false ) : Instruction

Emits IL that is used to exit a method. This expects that you are appending to a method being built.

InjectNonVoidBeginCallback ( this current, Mono.Cecil.MethodDefinition callback ) : void

Injects a cancelable (boolean) callback into the current method with the ability to return a value from the method using a custom variable. The callback must expect an instance parameter if the current method is instanced. Additionally, it must also have the result value by reference before any of the current method parameters are specified.

ReplaceTransfer ( this current, Instruction newTarget, Mono.Cecil.MethodDefinition originalMethod ) : void

Replaces instruction references (ie if, try) to a new instruction target. This is useful if you are injecting new code before a section of code that is already the receiver of a try/if block.

ReplaceWith ( this method, MethodReference replacement ) : void

Replaces all occurrences of the current method in the assembly with the provided method

Wrap ( this current, MethodReference beginCallback, MethodReference endCallback, bool beginIsCancellable, bool noEndHandling, bool allowCallbackInstance, TypeReference overrideReturnType = null ) : Mono.Cecil.MethodDefinition

Wraps the current method with begin/end callbacks.

This will rename the current method and replace it with a new method that will take its place. In the new method it will call the callbacks and perform canceling on the begin callback if required.

Method Details

CreateMethodParameter() public static method

Creates a new parameter instruction for a method.
Useful if you are altering IL in a method and need a parameter reference
public static CreateMethodParameter ( this method, int index ) : Instruction
method this
index int
return Mono.Cecil.Cil.Instruction

EmitBeginCallback() public static method

Emits il for a callback at the start of a method
public static EmitBeginCallback ( this current, MethodReference callback, bool instanceMethod, bool callbackRequiresInstance, bool isCancelable, int parameterOffset ) : Instruction
current this The method being generated
callback Mono.Cecil.MethodReference The callback to be executed at runtime
instanceMethod bool
callbackRequiresInstance bool Indicates the provided callback expects an instance argument at the first index
isCancelable bool Generates il to handle canceling, emits a nop for continuation
parameterOffset int
return Mono.Cecil.Cil.Instruction

EmitEndCallback() public static method

Emits a method-end callback into the current method. Optionally, if is specified it will insert a 'this' argument that will be sent to the first parameter of the callback.
public static EmitEndCallback ( this current, MethodReference callback, bool instanceMethod, bool callbackRequiresInstance ) : void
current this
callback Mono.Cecil.MethodReference
instanceMethod bool
callbackRequiresInstance bool
return void

EmitMethodCallback() public static method

Emits IL that is used to execute a generic method call.
We use this to execute a vanilla wrapped method
public static EmitMethodCallback ( this method, MethodReference target, bool methodExpectsInstance, bool emitNonVoidPop = true ) : Instruction
method this
target Mono.Cecil.MethodReference
methodExpectsInstance bool
emitNonVoidPop bool
return Mono.Cecil.Cil.Instruction

EmitMethodEnding() public static method

Emits IL that is used to exit a method. This expects that you are appending to a method being built.
public static EmitMethodEnding ( this method, bool noHandling = false ) : Instruction
method this
noHandling bool
return Mono.Cecil.Cil.Instruction

InjectNonVoidBeginCallback() public static method

Injects a cancelable (boolean) callback into the current method with the ability to return a value from the method using a custom variable. The callback must expect an instance parameter if the current method is instanced. Additionally, it must also have the result value by reference before any of the current method parameters are specified.
public static InjectNonVoidBeginCallback ( this current, Mono.Cecil.MethodDefinition callback ) : void
current this
callback Mono.Cecil.MethodDefinition
return void

ReplaceTransfer() public static method

Replaces instruction references (ie if, try) to a new instruction target. This is useful if you are injecting new code before a section of code that is already the receiver of a try/if block.
public static ReplaceTransfer ( this current, Instruction newTarget, Mono.Cecil.MethodDefinition originalMethod ) : void
current this The original instruction
newTarget Mono.Cecil.Cil.Instruction The new instruction that will receive the transfer
originalMethod Mono.Cecil.MethodDefinition The original method that is used to search for transfers
return void

ReplaceWith() public static method

Replaces all occurrences of the current method in the assembly with the provided method
public static ReplaceWith ( this method, MethodReference replacement ) : void
method this
replacement Mono.Cecil.MethodReference
return void

Wrap() public static method

Wraps the current method with begin/end callbacks.
This will rename the current method and replace it with a new method that will take its place. In the new method it will call the callbacks and perform canceling on the begin callback if required.
public static Wrap ( this current, MethodReference beginCallback, MethodReference endCallback, bool beginIsCancellable, bool noEndHandling, bool allowCallbackInstance, TypeReference overrideReturnType = null ) : Mono.Cecil.MethodDefinition
current this The current method to be wrapped
beginCallback Mono.Cecil.MethodReference The callback to be executed at the start of the method
endCallback Mono.Cecil.MethodReference The optional end callback that will be executed at the end of the method
beginIsCancellable bool Indicates that the begin callback can cancel the method execution
noEndHandling bool Indicates to only return from the method and not do any special popping and so on
allowCallbackInstance bool Indicates that the callbacks expect an instance parameter at the first parameter index
overrideReturnType Mono.Cecil.TypeReference
return Mono.Cecil.MethodDefinition