/// <summary> /// Initializes a new instance of the <see cref="Hook{T}"/> class. /// Hook is not activated until Enable() method is called. /// Please do not use CoreHook unless you have thoroughly troubleshot why Reloaded does not work. /// </summary> /// <param name="address">A memory address to install a hook.</param> /// <param name="detour">Callback function. Delegate must have a same original function prototype.</param> /// <param name="useCoreHook">Use the corehook hooking library instead of Reloaded.</param> public Hook(IntPtr address, T detour, bool useCoreHook) { address = HookManager.FollowJmp(address); this.isCoreHook = useCoreHook || EnvironmentConfiguration.DalamudForceCoreHook; var hasOtherHooks = HookManager.Originals.ContainsKey(address); if (!hasOtherHooks) { MemoryHelper.ReadRaw(address, 0x32, out var original); HookManager.Originals[address] = original; } this.address = address; if (this.isCoreHook) { this.coreHookImpl = CoreHook.HookFactory.CreateHook <T>(address, detour); } else { this.hookImpl = ReloadedHooks.Instance.CreateHook <T>(detour, address.ToInt64()); } HookManager.TrackedHooks.Add(new HookInfo(this, detour, Assembly.GetCallingAssembly())); }
private Hook(IntPtr address, T detour, bool useMinHook, Assembly callingAssembly) { address = HookManager.FollowJmp(address); this.isMinHook = !EnvironmentConfiguration.DalamudForceReloaded && (EnvironmentConfiguration.DalamudForceMinHook || useMinHook); var hasOtherHooks = HookManager.Originals.ContainsKey(address); if (!hasOtherHooks) { MemoryHelper.ReadRaw(address, 0x32, out var original); HookManager.Originals[address] = original; } this.address = address; if (this.isMinHook) { if (!HookManager.MultiHookTracker.TryGetValue(address, out var indexList)) { indexList = HookManager.MultiHookTracker[address] = new(); } var index = (ulong)indexList.Count; this.minHookImpl = new MinSharp.Hook <T>(address, detour, index); // Add afterwards, so the hookIdent starts at 0. indexList.Add(this); } else { this.hookImpl = ReloadedHooks.Instance.CreateHook <T>(detour, address.ToInt64()); } HookManager.TrackedHooks.Add(new HookInfo(this, detour, callingAssembly)); }
/// <summary> /// Initializes a new instance of the <see cref="Hook{T}"/> class. /// Hook is not activated until Enable() method is called. /// </summary> /// <param name="address">A memory address to install a hook.</param> /// <param name="detour">Callback function. Delegate must have a same original function prototype.</param> public Hook(IntPtr address, T detour) { address = FollowJmp(address); var hasOtherHooks = HookManager.Originals.ContainsKey(address); if (!hasOtherHooks) { MemoryHelper.ReadRaw(address, 0x32, out var original); HookManager.Originals[address] = original; } this.address = address; this.hookImpl = ReloadedHooks.Instance.CreateHook <T>(detour, address.ToInt64()); HookManager.TrackedHooks.Add(new HookInfo(this, detour, Assembly.GetCallingAssembly())); }