mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +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>
|
/// <summary>
|
||||||
/// Starts intercepting a call to the function.
|
/// Starts intercepting a call to the function.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <exception cref="ObjectDisposedException">Hook is already disposed.</exception>
|
||||||
public virtual void Enable() => throw new NotImplementedException();
|
public virtual void Enable() => throw new NotImplementedException();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -115,14 +115,7 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool IsEnabled
|
public override bool IsEnabled => !this.IsDisposed && this.enabled;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
this.CheckDisposed();
|
|
||||||
return this.enabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string BackendName => "MinHook";
|
public override string BackendName => "MinHook";
|
||||||
|
|
@ -131,9 +124,7 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
if (this.IsDisposed)
|
if (this.IsDisposed)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
this.Disable();
|
this.Disable();
|
||||||
|
|
||||||
|
|
@ -147,16 +138,14 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Enable()
|
public override void Enable()
|
||||||
|
{
|
||||||
|
lock (HookManager.HookEnableSyncRoot)
|
||||||
{
|
{
|
||||||
this.CheckDisposed();
|
this.CheckDisposed();
|
||||||
|
|
||||||
if (this.enabled)
|
if (this.enabled)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
lock (HookManager.HookEnableSyncRoot)
|
|
||||||
{
|
|
||||||
Marshal.WriteIntPtr(this.ppfnThunkJumpTarget, this.pfnDetour);
|
Marshal.WriteIntPtr(this.ppfnThunkJumpTarget, this.pfnDetour);
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
@ -165,15 +154,14 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Disable()
|
public override void Disable()
|
||||||
{
|
{
|
||||||
this.CheckDisposed();
|
|
||||||
|
|
||||||
if (!this.enabled)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (HookManager.HookEnableSyncRoot)
|
lock (HookManager.HookEnableSyncRoot)
|
||||||
{
|
{
|
||||||
|
if (this.IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!this.enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
Marshal.WriteIntPtr(this.ppfnThunkJumpTarget, this.pfnOriginal);
|
Marshal.WriteIntPtr(this.ppfnThunkJumpTarget, this.pfnOriginal);
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,7 @@ internal class MinHookHook<T> : Hook<T> where T : Delegate
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool IsEnabled
|
public override bool IsEnabled => !this.IsDisposed && this.minHookImpl.Enabled;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
this.CheckDisposed();
|
|
||||||
return this.minHookImpl.Enabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string BackendName => "MinHook";
|
public override string BackendName => "MinHook";
|
||||||
|
|
@ -83,29 +76,30 @@ internal class MinHookHook<T> : Hook<T> where T : Delegate
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Enable()
|
public override void Enable()
|
||||||
|
{
|
||||||
|
lock (HookManager.HookEnableSyncRoot)
|
||||||
{
|
{
|
||||||
this.CheckDisposed();
|
this.CheckDisposed();
|
||||||
|
|
||||||
if (!this.minHookImpl.Enabled)
|
if (!this.minHookImpl.Enabled)
|
||||||
{
|
return;
|
||||||
lock (HookManager.HookEnableSyncRoot)
|
|
||||||
{
|
|
||||||
this.minHookImpl.Enable();
|
this.minHookImpl.Enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Disable()
|
public override void Disable()
|
||||||
{
|
|
||||||
this.CheckDisposed();
|
|
||||||
|
|
||||||
if (this.minHookImpl.Enabled)
|
|
||||||
{
|
{
|
||||||
lock (HookManager.HookEnableSyncRoot)
|
lock (HookManager.HookEnableSyncRoot)
|
||||||
{
|
{
|
||||||
|
if (this.IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!this.minHookImpl.Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
this.minHookImpl.Disable();
|
this.minHookImpl.Disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,7 @@ internal class ReloadedHook<T> : Hook<T> where T : Delegate
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool IsEnabled
|
public override bool IsEnabled => !this.IsDisposed && this.hookImpl.IsHookEnabled;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
this.CheckDisposed();
|
|
||||||
return this.hookImpl.IsHookEnabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string BackendName => "Reloaded";
|
public override string BackendName => "Reloaded";
|
||||||
|
|
@ -73,10 +66,10 @@ internal class ReloadedHook<T> : Hook<T> where T : Delegate
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Enable()
|
public override void Enable()
|
||||||
{
|
{
|
||||||
this.CheckDisposed();
|
|
||||||
|
|
||||||
lock (HookManager.HookEnableSyncRoot)
|
lock (HookManager.HookEnableSyncRoot)
|
||||||
{
|
{
|
||||||
|
this.CheckDisposed();
|
||||||
|
|
||||||
if (!this.hookImpl.IsHookEnabled)
|
if (!this.hookImpl.IsHookEnabled)
|
||||||
this.hookImpl.Enable();
|
this.hookImpl.Enable();
|
||||||
}
|
}
|
||||||
|
|
@ -85,10 +78,11 @@ internal class ReloadedHook<T> : Hook<T> where T : Delegate
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Disable()
|
public override void Disable()
|
||||||
{
|
{
|
||||||
this.CheckDisposed();
|
|
||||||
|
|
||||||
lock (HookManager.HookEnableSyncRoot)
|
lock (HookManager.HookEnableSyncRoot)
|
||||||
{
|
{
|
||||||
|
if (this.IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!this.hookImpl.IsHookActivated)
|
if (!this.hookImpl.IsHookActivated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue