diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index 6ae8221a1..7285ab904 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -64,10 +64,10 @@ - + @@ -94,12 +94,6 @@ - - - PreserveNewest - - - diff --git a/Dalamud/Hooking/Hook.cs b/Dalamud/Hooking/Hook.cs index 7171e2ec7..4e4a54fa9 100644 --- a/Dalamud/Hooking/Hook.cs +++ b/Dalamud/Hooking/Hook.cs @@ -18,8 +18,8 @@ namespace Dalamud.Hooking { private readonly IntPtr address; private readonly Reloaded.Hooks.Definitions.IHook hookImpl; - private readonly CoreHook.IHook coreHookImpl; - private readonly bool isCoreHook; + private readonly MinSharp.Hook minHookImpl; + private readonly bool isMinHook; /// /// Initializes a new instance of the class. @@ -35,15 +35,15 @@ namespace Dalamud.Hooking /// /// Initializes a new instance of the class. /// Hook is not activated until Enable() method is called. - /// Please do not use CoreHook unless you have thoroughly troubleshot why Reloaded does not work. + /// 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. - /// Use the corehook hooking library instead of Reloaded. - public Hook(IntPtr address, T detour, bool useCoreHook) + /// Use the MinHook hooking library instead of Reloaded. + public Hook(IntPtr address, T detour, bool useMinHook) { address = HookManager.FollowJmp(address); - this.isCoreHook = useCoreHook || EnvironmentConfiguration.DalamudForceCoreHook; + this.isMinHook = useMinHook || EnvironmentConfiguration.DalamudForceCoreHook; var hasOtherHooks = HookManager.Originals.ContainsKey(address); if (!hasOtherHooks) @@ -53,18 +53,9 @@ namespace Dalamud.Hooking } this.address = address; - if (this.isCoreHook) + if (this.isMinHook) { - try - { - this.coreHookImpl = CoreHook.HookFactory.CreateHook(address, detour); - } - catch (Exception ex) - { - this.isCoreHook = false; - Log.Error(ex, "CoreHook is having a bad day, defaulting to Reloaded"); - this.hookImpl = ReloadedHooks.Instance.CreateHook(detour, address.ToInt64()); - } + this.minHookImpl = new MinSharp.Hook(address, detour); } else { @@ -96,9 +87,9 @@ namespace Dalamud.Hooking get { this.CheckDisposed(); - if (this.isCoreHook) + if (this.isMinHook) { - return this.coreHookImpl.Original; + return this.minHookImpl.Original; } else { @@ -115,9 +106,9 @@ namespace Dalamud.Hooking get { this.CheckDisposed(); - if (this.isCoreHook) + if (this.isMinHook) { - return this.coreHookImpl.Enabled; + return this.minHookImpl.Enabled; } else { @@ -145,14 +136,14 @@ namespace Dalamud.Hooking /// /// 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 CoreHook unless you have thoroughly troubleshot why Reloaded does not work. + /// Please do not use MinHook unless you have thoroughly troubleshot why Reloaded does not work. /// /// A name of the module currently loaded in the memory. (e.g. ws2_32.dll). /// A name of the exported function name (e.g. send). /// Callback function. Delegate must have a same original function prototype. - /// Use the corehook hooking library instead of Reloaded. + /// Use the MinHook hooking library instead of Reloaded. /// The hook with the supplied parameters. - public static Hook FromSymbol(string moduleName, string exportName, T detour, bool useCoreHook) + public static Hook FromSymbol(string moduleName, string exportName, T detour, bool useMinHook) { var moduleHandle = NativeFunctions.GetModuleHandleW(moduleName); if (moduleHandle == IntPtr.Zero) @@ -162,7 +153,7 @@ namespace Dalamud.Hooking if (procAddress == IntPtr.Zero) throw new Exception($"Could not get the address of {moduleName}::{exportName}"); - return new Hook(procAddress, detour, useCoreHook); + return new Hook(procAddress, detour, useMinHook); } /// @@ -173,12 +164,10 @@ namespace Dalamud.Hooking if (this.IsDisposed) return; - if (this.isCoreHook) + if (this.isMinHook) { this.Disable(); - // Disposing CoreHook causes an APPCRASH on game exit. - // We already overwrite the original hook code, so there shouldn't be any real risk with not disposing here. - // this.coreHookImpl.Dispose(); + this.minHookImpl.Dispose(); } else { @@ -195,10 +184,12 @@ namespace Dalamud.Hooking { this.CheckDisposed(); - if (this.isCoreHook) + if (this.isMinHook) { - if (!this.coreHookImpl.Enabled) - this.coreHookImpl.Enabled = true; + if (!this.minHookImpl.Enabled) + { + this.minHookImpl.Enable(); + } } else { @@ -217,10 +208,12 @@ namespace Dalamud.Hooking { this.CheckDisposed(); - if (this.isCoreHook) + if (this.isMinHook) { - if (this.coreHookImpl.Enabled) - this.coreHookImpl.Enabled = false; + if (this.minHookImpl.Enabled) + { + this.minHookImpl.Disable(); + } } else { diff --git a/Dalamud/corehook64.dll b/Dalamud/corehook64.dll deleted file mode 100644 index 9b21a40d1..000000000 Binary files a/Dalamud/corehook64.dll and /dev/null differ