From 01840629013ce423d5947a29ab95a6d6f38aee92 Mon Sep 17 00:00:00 2001 From: Raymond Date: Wed, 27 Oct 2021 12:13:15 -0400 Subject: [PATCH] MinSharp multihook --- Dalamud/Dalamud.csproj | 2 +- Dalamud/Hooking/Hook.cs | 11 ++++++++++- Dalamud/Hooking/Internal/HookManager.cs | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index b0d22d948..c493e68f9 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -67,7 +67,7 @@ - + diff --git a/Dalamud/Hooking/Hook.cs b/Dalamud/Hooking/Hook.cs index 261edcd9b..fb7277d00 100644 --- a/Dalamud/Hooking/Hook.cs +++ b/Dalamud/Hooking/Hook.cs @@ -56,7 +56,15 @@ namespace Dalamud.Hooking this.address = address; if (this.isMinHook) { - this.minHookImpl = new MinSharp.Hook(address, detour); + var indexList = hasOtherHooks + ? HookManager.MultiHookTracker[address] + : HookManager.MultiHookTracker[address] = new(); + var index = (ulong)indexList.Count; + + this.minHookImpl = new MinSharp.Hook(address, detour, index); + + // Add afterwards, so the hookIdent starts at 0. + indexList.Add(this); } else { @@ -168,6 +176,7 @@ namespace Dalamud.Hooking if (this.isMinHook) { this.minHookImpl.Dispose(); + HookManager.MultiHookTracker[this.address] = null; } else { diff --git a/Dalamud/Hooking/Internal/HookManager.cs b/Dalamud/Hooking/Internal/HookManager.cs index 1f67ee1e8..8990930a0 100644 --- a/Dalamud/Hooking/Internal/HookManager.cs +++ b/Dalamud/Hooking/Internal/HookManager.cs @@ -79,6 +79,11 @@ namespace Dalamud.Hooking.Internal /// internal static Dictionary Originals { get; } = new(); + /// + /// Gets a static dictionary of the number of hooks on a given address. + /// + internal static Dictionary> MultiHookTracker { get; } = new(); + /// public void Dispose() {