From b5d52732e0add94bf70c89fb20f9c355f36dfb0e Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Sat, 1 Jun 2024 15:04:06 -0700
Subject: [PATCH] Add hooking overloads (#1820)
---
.../GameInteropProviderPluginScoped.cs | 12 ++++++--
.../Plugin/Services/IGameInteropProvider.cs | 28 +++++++++++++++++--
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/Dalamud/Hooking/Internal/GameInteropProviderPluginScoped.cs b/Dalamud/Hooking/Internal/GameInteropProviderPluginScoped.cs
index 1138d4e07..eb096a771 100644
--- a/Dalamud/Hooking/Internal/GameInteropProviderPluginScoped.cs
+++ b/Dalamud/Hooking/Internal/GameInteropProviderPluginScoped.cs
@@ -47,7 +47,7 @@ internal class GameInteropProviderPluginScoped : IGameInteropProvider, IInternal
}
///
- public Hook HookFromFunctionPointerVariable(IntPtr address, T detour) where T : Delegate
+ public Hook HookFromFunctionPointerVariable(nint address, T detour) where T : Delegate
{
var hook = Hook.FromFunctionPointerVariable(address, detour);
this.trackedHooks.Add(hook);
@@ -71,13 +71,21 @@ internal class GameInteropProviderPluginScoped : IGameInteropProvider, IInternal
}
///
- public Hook HookFromAddress(IntPtr procAddress, T detour, IGameInteropProvider.HookBackend backend = IGameInteropProvider.HookBackend.Automatic) where T : Delegate
+ public Hook HookFromAddress(nint procAddress, T detour, IGameInteropProvider.HookBackend backend = IGameInteropProvider.HookBackend.Automatic) where T : Delegate
{
var hook = Hook.FromAddress(procAddress, detour, backend == IGameInteropProvider.HookBackend.MinHook);
this.trackedHooks.Add(hook);
return hook;
}
+ ///
+ public Hook HookFromAddress(UIntPtr procAddress, T detour, IGameInteropProvider.HookBackend backend = IGameInteropProvider.HookBackend.Automatic) where T : Delegate
+ => this.HookFromAddress((nint)procAddress, detour, backend);
+
+ ///
+ public unsafe Hook HookFromAddress(void* procAddress, T detour, IGameInteropProvider.HookBackend backend = IGameInteropProvider.HookBackend.Automatic) where T : Delegate
+ => this.HookFromAddress((nint)procAddress, detour, backend);
+
///
public Hook HookFromSignature(string signature, T detour, IGameInteropProvider.HookBackend backend = IGameInteropProvider.HookBackend.Automatic) where T : Delegate
=> this.HookFromAddress(this.scanner.ScanText(signature), detour, backend);
diff --git a/Dalamud/Plugin/Services/IGameInteropProvider.cs b/Dalamud/Plugin/Services/IGameInteropProvider.cs
index 217e08445..99e36c7ed 100644
--- a/Dalamud/Plugin/Services/IGameInteropProvider.cs
+++ b/Dalamud/Plugin/Services/IGameInteropProvider.cs
@@ -48,7 +48,7 @@ public interface IGameInteropProvider
/// Callback function. Delegate must have a same original function prototype.
/// The hook with the supplied parameters.
/// Delegate of detour.
- public Hook HookFromFunctionPointerVariable(IntPtr address, T detour) where T : Delegate;
+ public Hook HookFromFunctionPointerVariable(nint address, T detour) where T : Delegate;
///
/// Creates a hook by rewriting import table address.
@@ -85,7 +85,31 @@ public interface IGameInteropProvider
/// Hooking library to use.
/// The hook with the supplied parameters.
/// Delegate of detour.
- Hook HookFromAddress(IntPtr procAddress, T detour, HookBackend backend = HookBackend.Automatic) where T : Delegate;
+ Hook HookFromAddress(nint procAddress, T detour, HookBackend backend = HookBackend.Automatic) where T : Delegate;
+
+ ///
+ /// Creates a hook. Hooking address is inferred by calling to GetProcAddress() function.
+ /// The hook is not activated until Enable() method is called.
+ /// Please do not use MinHook unless you have thoroughly troubleshot why Reloaded does not work.
+ ///
+ /// A memory address to install a hook.
+ /// Callback function. Delegate must have a same original function prototype.
+ /// Hooking library to use.
+ /// The hook with the supplied parameters.
+ /// Delegate of detour.
+ Hook HookFromAddress(nuint procAddress, T detour, HookBackend backend = HookBackend.Automatic) where T : Delegate;
+
+ ///
+ /// Creates a hook. Hooking address is inferred by calling to GetProcAddress() function.
+ /// The hook is not activated until Enable() method is called.
+ /// Please do not use MinHook unless you have thoroughly troubleshot why Reloaded does not work.
+ ///
+ /// A memory address to install a hook.
+ /// Callback function. Delegate must have a same original function prototype.
+ /// Hooking library to use.
+ /// The hook with the supplied parameters.
+ /// Delegate of detour.
+ unsafe Hook HookFromAddress(void* procAddress, T detour, HookBackend backend = HookBackend.Automatic) where T : Delegate;
///
/// Creates a hook from a signature into the Dalamud target module.