Example #1
0
        /// <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);
Example #2
0
        public void RemoveController(IHookController ctrl)
        {
            HookInfo hInfo = GetInfoByThread();

            hInfo.HookControllers.Remove(ctrl);
            if (hInfo.HookControllers.Count == 0)
            {
                RemoveHook(hInfo, false);
            }
        }
Example #3
0
        public void AddController(IHookController ctrl)
        {
            HookInfo hInfo = GetInfoByThread();

            hInfo.HookControllers.Add(ctrl);
            if (hInfo.HookControllers.Count == 1)
            {
                InstallHook(hInfo);
            }
        }
Example #4
0
        public void CheckController(IHookController ctrl)
        {
            HookInfo hInfo = GetInfoByThread();

            if (hInfo.HookControllers.Contains(ctrl))
            {
                return;
            }
            AddController(ctrl);
        }
Example #5
0
        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);
        }
Example #6
0
        /// <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));
        }
Example #7
0
        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);
        }
Example #8
0
 public void RemoveController(IHookController ctrl)
 {
     HookInfo hInfo = GetInfoByThread();
     hInfo.HookControllers.Remove(ctrl);
     if (hInfo.HookControllers.Count == 0) RemoveHook(hInfo, false);
 }
Example #9
0
 public void CheckController(IHookController ctrl)
 {
     HookInfo hInfo = GetInfoByThread();
     if (hInfo.HookControllers.Contains(ctrl)) return;
     AddController(ctrl);
 }
Example #10
0
 public void AddController(IHookController ctrl)
 {
     HookInfo hInfo = GetInfoByThread();
     hInfo.HookControllers.Add(ctrl);
     if (hInfo.HookControllers.Count == 1) InstallHook(hInfo);
 }