Magic the magic happen

This commit is contained in:
Raymond Lynch 2021-07-11 16:32:29 -04:00
parent 84769ae5b7
commit 658eedca37
188 changed files with 10329 additions and 3549 deletions

View 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; }
}
}

View 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()
{
}
}
}

View 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; }
}
}