mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-23 08:17:47 +01:00
Magic the magic happen
This commit is contained in:
parent
84769ae5b7
commit
658eedca37
188 changed files with 10329 additions and 3549 deletions
59
Dalamud/Hooking/Internal/HookInfo.cs
Normal file
59
Dalamud/Hooking/Internal/HookInfo.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Dalamud.Hooking.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Class containing information about registered hooks.
|
||||
/// </summary>
|
||||
internal class HookInfo
|
||||
{
|
||||
private ulong? inProcessMemory = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the RVA of the hook.
|
||||
/// </summary>
|
||||
internal ulong? InProcessMemory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Hook.IsDisposed) return 0;
|
||||
if (this.inProcessMemory == null) return null;
|
||||
if (this.inProcessMemory.Value > 0) return this.inProcessMemory.Value;
|
||||
|
||||
var p = Process.GetCurrentProcess().MainModule;
|
||||
var begin = (ulong)p.BaseAddress.ToInt64();
|
||||
var end = begin + (ulong)p.ModuleMemorySize;
|
||||
var hookAddr = (ulong)this.Hook.Address.ToInt64();
|
||||
|
||||
if (hookAddr >= begin && hookAddr <= end)
|
||||
{
|
||||
this.inProcessMemory = hookAddr - begin;
|
||||
return this.inProcessMemory.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inProcessMemory = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tracked hook.
|
||||
/// </summary>
|
||||
internal IDalamudHook Hook { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tracked delegate.
|
||||
/// </summary>
|
||||
internal Delegate Delegate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the hooked assembly.
|
||||
/// </summary>
|
||||
internal Assembly Assembly { get; set; }
|
||||
}
|
||||
}
|
||||
33
Dalamud/Hooking/Internal/HookManager.cs
Normal file
33
Dalamud/Hooking/Internal/HookManager.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dalamud.Hooking.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// This class manages the final disposition of hooks, cleaning up any that have not reverted their changes.
|
||||
/// </summary>
|
||||
internal class HookManager : IDisposable
|
||||
{
|
||||
// private readonly Dalamud dalamud;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HookManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dalamud">Dalamud instance.</param>
|
||||
public HookManager(Dalamud dalamud)
|
||||
{
|
||||
_ = dalamud;
|
||||
// this.dalamud = dalamud;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a static list of tracked and registered hooks.
|
||||
/// </summary>
|
||||
internal static List<HookInfo> TrackedHooks { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Dalamud/Hooking/Internal/IDalamudHook.cs
Normal file
25
Dalamud/Hooking/Internal/IDalamudHook.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
|
||||
namespace Dalamud.Hooking.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface describing a generic hook.
|
||||
/// </summary>
|
||||
internal interface IDalamudHook
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the address to hook.
|
||||
/// </summary>
|
||||
public IntPtr Address { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not the hook is enabled.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not the hook is disposed.
|
||||
/// </summary>
|
||||
public bool IsDisposed { get; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue