/// <summary> /// <para>Returns a hook attached to the current <paramref name="instance"/>, that is assignable to a variable of <typeparamref name="THook"/> type.</para> /// </summary> /// <typeparam name="THook">The type of a hook to search for.</typeparam> /// <param name="instance">The instance of a hookable type.</param> /// <returns>The hook that is assignable to a variable of <typeparamref name="THook"/> type, if found; otherwise, <see langword="default"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="instance"/> is <see langword="null"/>.</exception> public static THook GetHook <THook>(this InvItem instance) { if (instance is null) { throw new ArgumentNullException(nameof(instance)); } IHookController <InvItem> controller = GetHookController(instance, ref instance.__RogueLibsHooks, false); return(controller != null?controller.GetHook <THook>() : default);
public void RemoveController(IHookController ctrl) { HookInfo hInfo = GetInfoByThread(); hInfo.HookControllers.Remove(ctrl); if (hInfo.HookControllers.Count == 0) { RemoveHook(hInfo, false); } }
public void AddController(IHookController ctrl) { HookInfo hInfo = GetInfoByThread(); hInfo.HookControllers.Add(ctrl); if (hInfo.HookControllers.Count == 1) { InstallHook(hInfo); } }
public void CheckController(IHookController ctrl) { HookInfo hInfo = GetInfoByThread(); if (hInfo.HookControllers.Contains(ctrl)) { return; } AddController(ctrl); }
internal bool InternalPreFilterMessage(HookInfo hInfo, int Msg, Control wnd, IntPtr HWnd, IntPtr WParam, IntPtr LParam) { bool result = false; for (int n = 0; n < hInfo.HookControllers.Count; n++) { IHookController ctrl = hInfo.HookControllers[n] as IHookController; result |= ctrl.InternalPreFilterMessage(Msg, wnd, HWnd, WParam, LParam); } return(result); }
/// <summary> /// <para>Detaches a hook of the specified <typeparamref name="THook"/> type from the current <paramref name="instance"/>.</para> /// </summary> /// <typeparam name="THook">The type of a hook to detach from the <paramref name="instance"/>.</typeparam> /// <param name="instance">The instance of a hookable type.</param> /// <returns><see langword="true"/>, if a hook was successfully detached; otherwise, <see langword="false"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="instance"/> is <see langword="null"/>.</exception> public static bool RemoveHook <THook>(this Trait instance) where THook : IHook <Trait> { if (instance is null) { throw new ArgumentNullException(nameof(instance)); } IHookController <Trait> controller = GetHookController(instance, ref instance.__RogueLibsHooks, false); if (controller is null) { return(false); } IHook <Trait> hook = controller.GetHook <THook>(); return(controller.RemoveHook(hook)); }
internal bool InternalPostFilterMessage(HookInfo hInfo, int Msg, Control wnd, IntPtr HWnd, IntPtr WParam, IntPtr LParam) { bool result = false; for (int n = hInfo.HookControllers.Count - 1; n >= 0; n--) { IHookController ctrl = hInfo.HookControllers[n] as IHookController; result |= ctrl.InternalPostFilterMessage(Msg, wnd, HWnd, WParam, LParam); if (Msg == 0x2) { if (ctrl.OwnerHandle == HWnd) { RemoveController(ctrl); } } } return(result); }
public void RemoveController(IHookController ctrl) { HookInfo hInfo = GetInfoByThread(); hInfo.HookControllers.Remove(ctrl); if (hInfo.HookControllers.Count == 0) RemoveHook(hInfo, false); }
public void CheckController(IHookController ctrl) { HookInfo hInfo = GetInfoByThread(); if (hInfo.HookControllers.Contains(ctrl)) return; AddController(ctrl); }
public void AddController(IHookController ctrl) { HookInfo hInfo = GetInfoByThread(); hInfo.HookControllers.Add(ctrl); if (hInfo.HookControllers.Count == 1) InstallHook(hInfo); }