/// <summary> /// Creates a wrapper function with a custom calling convention which calls the supplied function. /// </summary> /// <param name="function">Pointer of native function to wrap.</param> public ReverseWrapper(nuint function) { NativeFunctionPtr = function.ToSigned(); WrapperPointer = NativeFunctionPtr; // Call above may or may not replace WrapperPointer. Create(this, function); }
/// <inheritdoc /> public TFunction GetWrapper(out IntPtr wrapperAddress) { if (!_wrapperCreated) { _wrapper = Hooks.CreateWrapper <TFunction>(Address, out var wrapperAddr); _wrapperAddress = wrapperAddr.ToUnsigned(); _wrapperCreated = true; } wrapperAddress = _wrapperAddress.ToSigned(); return(_wrapper); }
/// <summary> /// Creates a wrapper function which allows you to call a function with a custom calling convention using the calling convention of /// <typeparamref name="TFunction"/>. /// </summary> /// <param name="functionAddress">Address of the function to reverse wrap..</param> /// <param name="wrapperAddress"> /// Address of the wrapper used to call the original function. /// If the source and target calling conventions match, this is the same as <paramref name="functionAddress"/> /// </param> public static TFunction Create < #if NET5_0_OR_GREATER [DynamicallyAccessedMembers(Trimming.ReloadedAttributeTypes)] #endif TFunction>(nuint functionAddress, out nuint wrapperAddress) { CreatePointer <TFunction>(functionAddress, out wrapperAddress); if (typeof(TFunction).IsValueType && !typeof(TFunction).IsPrimitive) { return(Unsafe.As <nuint, TFunction>(ref wrapperAddress)); } return(Marshal.GetDelegateForFunctionPointer <TFunction>(wrapperAddress.ToSigned())); }