MinSharp multihook

This commit is contained in:
Raymond 2021-10-27 12:13:15 -04:00
parent 93ae7c9a66
commit 0184062901
3 changed files with 16 additions and 2 deletions

View file

@ -67,7 +67,7 @@
<PackageReference Include="JetBrains.Annotations" Version="2021.2.0" />
<PackageReference Include="Lumina" Version="3.3.0" />
<PackageReference Include="Lumina.Excel" Version="5.50.0" />
<PackageReference Include="MinSharp" Version="1.0.1" />
<PackageReference Include="MinSharp" Version="1.0.2" />
<PackageReference Include="MonoMod.RuntimeDetour" Version="21.10.10.01" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />

View file

@ -56,7 +56,15 @@ namespace Dalamud.Hooking
this.address = address;
if (this.isMinHook)
{
this.minHookImpl = new MinSharp.Hook<T>(address, detour);
var indexList = hasOtherHooks
? HookManager.MultiHookTracker[address]
: HookManager.MultiHookTracker[address] = new();
var index = (ulong)indexList.Count;
this.minHookImpl = new MinSharp.Hook<T>(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
{

View file

@ -79,6 +79,11 @@ namespace Dalamud.Hooking.Internal
/// </summary>
internal static Dictionary<IntPtr, byte[]> Originals { get; } = new();
/// <summary>
/// Gets a static dictionary of the number of hooks on a given address.
/// </summary>
internal static Dictionary<IntPtr, List<IDalamudHook?>> MultiHookTracker { get; } = new();
/// <inheritdoc/>
public void Dispose()
{