mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +01:00
Add hook stress test
This commit is contained in:
parent
81ced564d6
commit
672793b6c0
2 changed files with 189 additions and 16 deletions
|
|
@ -15,10 +15,10 @@ namespace Dalamud.Hooking.Internal;
|
|||
/// Only the specific callsite hooked is modified, if the game calls the virtual function from other locations this hook will not be triggered.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Delegate signature for this hook.</typeparam>
|
||||
internal class CallHook<T> : IDisposable where T : Delegate
|
||||
internal class CallHook<T> : IDalamudHook where T : Delegate
|
||||
{
|
||||
private readonly Reloaded.Hooks.AsmHook asmHook;
|
||||
|
||||
|
||||
private T? detour;
|
||||
private bool activated;
|
||||
|
||||
|
|
@ -29,7 +29,10 @@ internal class CallHook<T> : IDisposable where T : Delegate
|
|||
/// <param name="detour">Delegate to invoke.</param>
|
||||
internal CallHook(nint address, T detour)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(detour);
|
||||
|
||||
this.detour = detour;
|
||||
this.Address = address;
|
||||
|
||||
var detourPtr = Marshal.GetFunctionPointerForDelegate(this.detour);
|
||||
var code = new[]
|
||||
|
|
@ -38,14 +41,14 @@ internal class CallHook<T> : IDisposable where T : Delegate
|
|||
$"mov rax, 0x{detourPtr:X8}",
|
||||
"call rax",
|
||||
};
|
||||
|
||||
|
||||
var opt = new AsmHookOptions
|
||||
{
|
||||
PreferRelativeJump = true,
|
||||
Behaviour = Reloaded.Hooks.Definitions.Enums.AsmHookBehaviour.DoNotExecuteOriginal,
|
||||
MaxOpcodeSize = 5,
|
||||
};
|
||||
|
||||
|
||||
this.asmHook = new Reloaded.Hooks.AsmHook(code, (nuint)address, opt);
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +56,16 @@ internal class CallHook<T> : IDisposable where T : Delegate
|
|||
/// Gets a value indicating whether or not the hook is enabled.
|
||||
/// </summary>
|
||||
public bool IsEnabled => this.asmHook.IsEnabled;
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IntPtr Address { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string BackendName => "Reloaded AsmHook";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsDisposed => this.detour == null;
|
||||
|
||||
/// <summary>
|
||||
/// Starts intercepting a call to the function.
|
||||
/// </summary>
|
||||
|
|
@ -65,7 +77,7 @@ internal class CallHook<T> : IDisposable where T : Delegate
|
|||
this.asmHook.Activate();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.asmHook.Enable();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue