mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
refactor: new code style in HookInfo.cs
This commit is contained in:
parent
b3044f33e3
commit
e6fd62ce2a
1 changed files with 44 additions and 16 deletions
|
|
@ -3,34 +3,62 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Dalamud.Hooking {
|
||||
internal class HookInfo {
|
||||
|
||||
internal static List<HookInfo> TrackedHooks = new List<HookInfo>();
|
||||
|
||||
internal IDalamudHook Hook { get; set; }
|
||||
internal Delegate Delegate { get; set; }
|
||||
internal Assembly Assembly { get; set; }
|
||||
namespace Dalamud.Hooking
|
||||
{
|
||||
/// <summary>
|
||||
/// Class containing information about registered hooks.
|
||||
/// </summary>
|
||||
internal class HookInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Static list of tracked and registered hooks.
|
||||
/// </summary>
|
||||
internal static readonly List<HookInfo> TrackedHooks = new List<HookInfo>();
|
||||
|
||||
private ulong? inProcessMemory = 0;
|
||||
internal ulong? InProcessMemory {
|
||||
get {
|
||||
if (Hook.IsDisposed) return 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) Hook.Address.ToInt64();
|
||||
if (hookAddr >= begin && hookAddr <= end) {
|
||||
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 {
|
||||
}
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue