refactor: new code style in HookInfo.cs

This commit is contained in:
goat 2021-04-06 20:54:47 +02:00
parent b3044f33e3
commit e6fd62ce2a

View file

@ -3,34 +3,62 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
namespace Dalamud.Hooking { namespace Dalamud.Hooking
internal class HookInfo { {
/// <summary>
internal static List<HookInfo> TrackedHooks = new List<HookInfo>(); /// Class containing information about registered hooks.
/// </summary>
internal IDalamudHook Hook { get; set; } internal class HookInfo
internal Delegate Delegate { get; set; } {
internal Assembly Assembly { get; set; } /// <summary>
/// Static list of tracked and registered hooks.
/// </summary>
internal static readonly List<HookInfo> TrackedHooks = new List<HookInfo>();
private ulong? inProcessMemory = 0; private ulong? inProcessMemory = 0;
internal ulong? InProcessMemory {
get { /// <summary>
if (Hook.IsDisposed) return 0; /// 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 == null) return null;
if (this.inProcessMemory.Value > 0) return this.inProcessMemory.Value; if (this.inProcessMemory.Value > 0) return this.inProcessMemory.Value;
var p = Process.GetCurrentProcess().MainModule; var p = Process.GetCurrentProcess().MainModule;
var begin = (ulong) p.BaseAddress.ToInt64(); var begin = (ulong)p.BaseAddress.ToInt64();
var end = begin + (ulong) p.ModuleMemorySize; var end = begin + (ulong)p.ModuleMemorySize;
var hookAddr = (ulong) Hook.Address.ToInt64(); var hookAddr = (ulong)this.Hook.Address.ToInt64();
if (hookAddr >= begin && hookAddr <= end) {
if (hookAddr >= begin && hookAddr <= end)
{
this.inProcessMemory = hookAddr - begin; this.inProcessMemory = hookAddr - begin;
return this.inProcessMemory.Value; return this.inProcessMemory.Value;
} else { }
else
{
this.inProcessMemory = null; this.inProcessMemory = null;
return 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; }
} }
} }