From e6fd62ce2a04b94d06e4b8b5ad996f887a773b38 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Tue, 6 Apr 2021 20:54:47 +0200 Subject: [PATCH] refactor: new code style in HookInfo.cs --- Dalamud/Hooking/HookInfo.cs | 60 +++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/Dalamud/Hooking/HookInfo.cs b/Dalamud/Hooking/HookInfo.cs index 6f5e1d9e0..b4d579d39 100644 --- a/Dalamud/Hooking/HookInfo.cs +++ b/Dalamud/Hooking/HookInfo.cs @@ -3,34 +3,62 @@ using System.Collections.Generic; using System.Diagnostics; using System.Reflection; -namespace Dalamud.Hooking { - internal class HookInfo { - - internal static List TrackedHooks = new List(); - - internal IDalamudHook Hook { get; set; } - internal Delegate Delegate { get; set; } - internal Assembly Assembly { get; set; } +namespace Dalamud.Hooking +{ + /// + /// Class containing information about registered hooks. + /// + internal class HookInfo + { + /// + /// Static list of tracked and registered hooks. + /// + internal static readonly List TrackedHooks = new List(); private ulong? inProcessMemory = 0; - internal ulong? InProcessMemory { - get { - if (Hook.IsDisposed) return 0; + + /// + /// Gets the RVA of the hook. + /// + 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; } } } + /// + /// Gets or sets the tracked hook. + /// + internal IDalamudHook Hook { get; set; } + + /// + /// Gets or sets the tracked delegate. + /// + internal Delegate Delegate { get; set; } + + /// + /// Gets or sets the hooked assembly. + /// + internal Assembly Assembly { get; set; } } }