Пример #1
0
        public static IntPtr SetWindowsHookEx(HookType hookType, HookProc lpfn, IntPtr hMod, uint dwThreadId)
        {
            // TODO: SetWindowsHookEx currently ignores the module and thread.
            int             handle = PInvoke.AllHooks.Count + 1;
            List <Delegate> hooks  = PInvoke.Hooks[hookType];

            PInvoke.AllHooks.Add(Tuple.Create <HookType, Delegate, int>(hookType, lpfn, hooks.Count));
            hooks.Add(lpfn);
            XnaToFnaHelper.Log($"[PInvokeHooks] Added global hook #{handle} of type {hookType}");
            return((IntPtr)handle);
        }
Пример #2
0
        public static bool ClipCursor(ref Rectangle rect)
        {
            unsafe
            {
                fixed(Rectangle *rect_ = &rect)
                if ((long)rect_ == 0)
                {
                    // MSDN: If this parameter is NULL, the cursor is free to move anywhere on the screen.
                    XnaToFnaHelper.Log($"[CursorEvents] Cursor released from ClipCursor");
                    MouseEvents.Clip = null;
                    return(true);
                }
            }

            XnaToFnaHelper.Log($"[CursorEvents] Game tries to ClipCursor inside {rect}");
            MouseEvents.Clip = rect;
            return(true);
        }
Пример #3
0
        public static uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId)
        {
            Form form = Control.FromHandle(hWnd) as Form;

            if (form == null)
            {
                XnaToFnaHelper.Log($"[PInvokeHooks] Called GetWindowThreadProcessId for non-existing hWnd {hWnd}");
                form = GameForm.Instance;
            }
            // Yes, that's required, as DLC Quest passes IntPtr.Zero
            unsafe {
                fixed(uint *lpdwProcesId_ = &lpdwProcessId)
                if ((long)lpdwProcesId_ != 0)
                {
                    lpdwProcessId = 0;     // Optional
                }
            }
            return((uint)(form?.ThreadId ?? 0));
        }
Пример #4
0
        public static int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong)
        {
            // All other nIndex values seem to be style-related.
            if (nIndex == -4)
            {
                Form form = Control.FromHandle(hWnd)?.Form;
                if (form == null)
                {
                    return(0);
                }

                IntPtr prevHook = form.WindowHookPtr;
                form.WindowHookPtr = (IntPtr)dwNewLong;
                form.WindowHook    = Marshal.GetDelegateForFunctionPointer(form.WindowHookPtr, typeof(WndProc));
                XnaToFnaHelper.Log($"[PInvokeHooks] Window hook set on ProxyForms.Form #{form.GlobalIndex}");
                return((int)prevHook);
            }

            return(0);
        }
Пример #5
0
        public static IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam)
        {
            // This gets called when Duck Game dies...
            // TODO: Find more games using SendMessage.
            Form form = Control.FromHandle(hWnd) as Form;

            if (form == null)
            {
                XnaToFnaHelper.Log($"[PInvokeHooks] Called GetWindowThreadProcessId for non-existing hWnd {hWnd}");
                form = GameForm.Instance;
            }

            if (Msg == 16 /*WM_CLOSE*/)
            {
                form.Close();
                // TODO: What's the proper return value for SendMessage on WM_CLOSE?
                return(IntPtr.Zero);
            }

            return(IntPtr.Zero);
        }
Пример #6
0
 protected override void Initialize()
 {
     base.Initialize();
     // Required to get XNATOFNA_DISPLAY_* to apply.
     XnaToFnaHelper.ApplyChanges((GraphicsDeviceManager)Services.GetService(typeof(IGraphicsDeviceManager)));
 }
Пример #7
0
 public XnaToFnaGame()
     : base()
 {
     XnaToFnaHelper.Initialize(this);
 }