Solve minhook crash on plugin reload

This commit is contained in:
Raymond 2021-11-03 22:14:37 -04:00
parent 5380141d76
commit eca4ce05fd

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
@ -59,9 +60,9 @@ namespace Dalamud.Hooking
this.address = address; this.address = address;
if (this.isMinHook) if (this.isMinHook)
{ {
var indexList = hasOtherHooks if (!HookManager.MultiHookTracker.TryGetValue(address, out var indexList))
? HookManager.MultiHookTracker[address] indexList = HookManager.MultiHookTracker[address] = new();
: (HookManager.MultiHookTracker[address] = new());
var index = (ulong)indexList.Count; var index = (ulong)indexList.Count;
this.minHookImpl = new MinSharp.Hook<T>(address, detour, index); this.minHookImpl = new MinSharp.Hook<T>(address, detour, index);
@ -191,7 +192,9 @@ namespace Dalamud.Hooking
if (this.isMinHook) if (this.isMinHook)
{ {
this.minHookImpl.Dispose(); this.minHookImpl.Dispose();
HookManager.MultiHookTracker[this.address] = null;
var index = HookManager.MultiHookTracker[this.address].IndexOf(this);
HookManager.MultiHookTracker[this.address][index] = null;
} }
else else
{ {