mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Do not throw ObjectDisposedException in IsEnabled and Disable (#2266)
This commit is contained in:
parent
bf491525f6
commit
2c735e9ec3
4 changed files with 35 additions and 58 deletions
|
|
@ -90,6 +90,7 @@ public abstract class Hook<T> : IDalamudHook where T : Delegate
|
|||
/// <summary>
|
||||
/// Starts intercepting a call to the function.
|
||||
/// </summary>
|
||||
/// <exception cref="ObjectDisposedException">Hook is already disposed.</exception>
|
||||
public virtual void Enable() => throw new NotImplementedException();
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -115,14 +115,7 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
this.CheckDisposed();
|
||||
return this.enabled;
|
||||
}
|
||||
}
|
||||
public override bool IsEnabled => !this.IsDisposed && this.enabled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string BackendName => "MinHook";
|
||||
|
|
@ -131,9 +124,7 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
|||
public override void Dispose()
|
||||
{
|
||||
if (this.IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.Disable();
|
||||
|
||||
|
|
@ -148,15 +139,13 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
|||
/// <inheritdoc/>
|
||||
public override void Enable()
|
||||
{
|
||||
this.CheckDisposed();
|
||||
|
||||
if (this.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (HookManager.HookEnableSyncRoot)
|
||||
{
|
||||
this.CheckDisposed();
|
||||
|
||||
if (this.enabled)
|
||||
return;
|
||||
|
||||
Marshal.WriteIntPtr(this.ppfnThunkJumpTarget, this.pfnDetour);
|
||||
this.enabled = true;
|
||||
}
|
||||
|
|
@ -165,15 +154,14 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
|||
/// <inheritdoc/>
|
||||
public override void Disable()
|
||||
{
|
||||
this.CheckDisposed();
|
||||
|
||||
if (!this.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (HookManager.HookEnableSyncRoot)
|
||||
{
|
||||
if (this.IsDisposed)
|
||||
return;
|
||||
|
||||
if (!this.enabled)
|
||||
return;
|
||||
|
||||
Marshal.WriteIntPtr(this.ppfnThunkJumpTarget, this.pfnOriginal);
|
||||
this.enabled = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,14 +50,7 @@ internal class MinHookHook<T> : Hook<T> where T : Delegate
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
this.CheckDisposed();
|
||||
return this.minHookImpl.Enabled;
|
||||
}
|
||||
}
|
||||
public override bool IsEnabled => !this.IsDisposed && this.minHookImpl.Enabled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string BackendName => "MinHook";
|
||||
|
|
@ -84,28 +77,29 @@ internal class MinHookHook<T> : Hook<T> where T : Delegate
|
|||
/// <inheritdoc/>
|
||||
public override void Enable()
|
||||
{
|
||||
this.CheckDisposed();
|
||||
|
||||
if (!this.minHookImpl.Enabled)
|
||||
lock (HookManager.HookEnableSyncRoot)
|
||||
{
|
||||
lock (HookManager.HookEnableSyncRoot)
|
||||
{
|
||||
this.minHookImpl.Enable();
|
||||
}
|
||||
this.CheckDisposed();
|
||||
|
||||
if (!this.minHookImpl.Enabled)
|
||||
return;
|
||||
|
||||
this.minHookImpl.Enable();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Disable()
|
||||
{
|
||||
this.CheckDisposed();
|
||||
|
||||
if (this.minHookImpl.Enabled)
|
||||
lock (HookManager.HookEnableSyncRoot)
|
||||
{
|
||||
lock (HookManager.HookEnableSyncRoot)
|
||||
{
|
||||
this.minHookImpl.Disable();
|
||||
}
|
||||
if (this.IsDisposed)
|
||||
return;
|
||||
|
||||
if (!this.minHookImpl.Enabled)
|
||||
return;
|
||||
|
||||
this.minHookImpl.Disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,14 +45,7 @@ internal class ReloadedHook<T> : Hook<T> where T : Delegate
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
this.CheckDisposed();
|
||||
return this.hookImpl.IsHookEnabled;
|
||||
}
|
||||
}
|
||||
public override bool IsEnabled => !this.IsDisposed && this.hookImpl.IsHookEnabled;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string BackendName => "Reloaded";
|
||||
|
|
@ -73,10 +66,10 @@ internal class ReloadedHook<T> : Hook<T> where T : Delegate
|
|||
/// <inheritdoc/>
|
||||
public override void Enable()
|
||||
{
|
||||
this.CheckDisposed();
|
||||
|
||||
lock (HookManager.HookEnableSyncRoot)
|
||||
{
|
||||
this.CheckDisposed();
|
||||
|
||||
if (!this.hookImpl.IsHookEnabled)
|
||||
this.hookImpl.Enable();
|
||||
}
|
||||
|
|
@ -85,10 +78,11 @@ internal class ReloadedHook<T> : Hook<T> where T : Delegate
|
|||
/// <inheritdoc/>
|
||||
public override void Disable()
|
||||
{
|
||||
this.CheckDisposed();
|
||||
|
||||
lock (HookManager.HookEnableSyncRoot)
|
||||
{
|
||||
if (this.IsDisposed)
|
||||
return;
|
||||
|
||||
if (!this.hookImpl.IsHookActivated)
|
||||
return;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue