예제 #1
0
        private void PerformHotSampling()
        {
            if (_newWidthBox.Value < 100 || _newHeightBox.Value < 100)
            {
                return;
            }
            if ((Win32Wrapper.IsIconic(_gameWindowHwnd) || Win32Wrapper.IsZoomed(_gameWindowHwnd)))
            {
                Win32Wrapper.ShowWindow(_gameWindowHwnd, Win32Wrapper.SW_SHOWNOACTIVATE);
            }

            int newHorizontalResolution = (int)_newWidthBox.Value;
            int newVerticalResolution   = (int)_newHeightBox.Value;
            // always set the window at (0,0), if width is >= screen width.
            var  screenBounds = Screen.FromHandle(_gameWindowHwnd).Bounds;
            uint uFlags       = Win32Wrapper.SWP_NOZORDER | Win32Wrapper.SWP_NOACTIVATE | Win32Wrapper.SWP_NOOWNERZORDER | Win32Wrapper.SWP_NOSENDCHANGING;

            if (newHorizontalResolution < screenBounds.Width)
            {
                // let the window be where it is.
                uFlags |= Win32Wrapper.SWP_NOMOVE;
            }

            Win32Wrapper.SetWindowPos(_gameWindowHwnd, 0, 0, 0, newHorizontalResolution, newVerticalResolution, uFlags);
            if (GameSpecificConstants.HotsamplingRequiresEXITSIZEMOVE)
            {
                // A warning of unreachable code will be raised here, that's ok. this code is only used when the constant is true
                Win32Wrapper.SendMessage(_gameWindowHwnd, Win32Wrapper.WM_EXITSIZEMOVE, 0, 0);
            }

            LogHandlerSingleton.Instance().LogLine("Switching resolution on window with hwnd 0x{0} to resolution {1}x{2}", "Hotsampler", _gameWindowHwnd.ToString("x"),
                                                   newHorizontalResolution, newVerticalResolution);

            // remove / add borders
            uint nStyle = (uint)Win32Wrapper.GetWindowLong(_gameWindowHwnd, Win32Wrapper.GWL_STYLE);

            nStyle = (nStyle | (Win32Wrapper.WS_THICKFRAME + Win32Wrapper.WS_DLGFRAME + Win32Wrapper.WS_BORDER + Win32Wrapper.WS_MAXIMIZEBOX + Win32Wrapper.WS_MINIMIZEBOX));
            if (_useWindowBordersCheckBox.IsChecked == false)
            {
                nStyle ^= (Win32Wrapper.WS_THICKFRAME + Win32Wrapper.WS_DLGFRAME + Win32Wrapper.WS_BORDER + Win32Wrapper.WS_MAXIMIZEBOX + Win32Wrapper.WS_MINIMIZEBOX);
            }
            Win32Wrapper.SetWindowLong(_gameWindowHwnd, Win32Wrapper.GWL_STYLE, nStyle);
            uFlags = Win32Wrapper.SWP_NOSIZE | Win32Wrapper.SWP_NOMOVE | Win32Wrapper.SWP_NOZORDER | Win32Wrapper.SWP_NOACTIVATE | Win32Wrapper.SWP_NOOWNERZORDER | Win32Wrapper.SWP_NOSENDCHANGING | Win32Wrapper.SWP_FRAMECHANGED;
            Win32Wrapper.SetWindowPos(_gameWindowHwnd, 0, 0, 0, 0, 0, uFlags);

            // Send the resize viewport message to the dll so it can resize the viewport based on the new resolution. The game itself won't resize the viewport on its own.
            MessageHandlerSingleton.Instance().SendResizeViewportAction(newHorizontalResolution, newVerticalResolution);

            AddResolutionToRecentlyUsedList(newHorizontalResolution, newVerticalResolution);

            if (_switchAfterResizingCheckBox.IsChecked == true)
            {
                // focus the attached application's window
                Win32Wrapper.SetForegroundWindow(_gameWindowHwnd);
            }
        }
        private static int FindPortByWinMsg()
        {
            //Start message queue
            Win32Wrapper.PeekMessage(out Win32Wrapper.NativeMessage msg, 0, (uint)0x600, (uint)0x600, Win32Wrapper.PM_REMOVE);

            Trace.WriteLine("Prepare message for Stealth", "Stealth.Main");
            var procstring = Process.GetCurrentProcess().Id.ToString("X8") + Process.GetCurrentProcess().MainModule.FileName.Replace(".vshost", "") + '\0';

            Trace.WriteLine(string.Format("Procstring: {0}", procstring), "Stealth.Main");
            var aCopyData = new Win32Wrapper.CopyDataStruct
            {
                dwData = (uint)Win32Wrapper.GetCurrentThreadId(),
                cbData = Process.GetCurrentProcess().MainModule.FileName.Replace(".vshost", "").Length + 8 + 1,
                lpData = Marshal.StringToHGlobalAnsi(procstring)
            };

            IntPtr copyDataPtr = aCopyData.MarshalToPtr();

            try
            {
                Trace.WriteLine("Find Stealth window", "Stealth.Main");
                IntPtr tWndPtr = Win32Wrapper.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "TStealthForm", null);
                if (tWndPtr != IntPtr.Zero)
                {
                    Trace.WriteLine("Stealth window found. Send message.", "Stealth.Main");
                    IntPtr ret = Win32Wrapper.SendMessage(tWndPtr, Win32Wrapper.WM_COPYDATA, IntPtr.Zero, copyDataPtr);
                    Trace.WriteLine("Message sended. Wait message from Stealth.", "Stealth.Main");
                    while (!Win32Wrapper.PeekMessage(out msg, 0, (uint)0x600, (uint)0x600, Win32Wrapper.PM_REMOVE))
                    {
                        Thread.Sleep(10);
                    }
                    Trace.WriteLine(string.Format("Message recieved. Port: {0}", (int)(msg.wParam)), "Stealth.Main");
                }
                else
                {
                    throw new InvalidOperationException("Could not attach to Stealth. Exiting.");
                }
            }
            catch (InvalidOperationException)
            {
                return(-1);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, "Stealth.Main");
                return(-1);
            }
            finally
            {
                Marshal.FreeHGlobal(copyDataPtr);
            }

            return((int)(msg.wParam));
        }
예제 #3
0
        private void PerformHotSampling()
        {
            if (_newWidthUpDown.Value < 100 || _newHeightUpDown.Value < 100)
            {
                return;
            }
            if ((Win32Wrapper.IsIconic(_gameWindowHwnd) || Win32Wrapper.IsZoomed(_gameWindowHwnd)))
            {
                Win32Wrapper.ShowWindow(_gameWindowHwnd, Win32Wrapper.SW_SHOWNOACTIVATE);
            }

            int newHorizontalResolution = (int)_newWidthUpDown.Value;
            int newVerticalResolution   = (int)_newHeightUpDown.Value;
            // always set the window at (0,0), if width is >= screen width.
            var  screenBounds = Screen.FromHandle(_gameWindowHwnd).Bounds;
            uint uFlags       = Win32Wrapper.SWP_NOZORDER | Win32Wrapper.SWP_NOACTIVATE | Win32Wrapper.SWP_NOOWNERZORDER | Win32Wrapper.SWP_NOSENDCHANGING;

            if (newHorizontalResolution < screenBounds.Width)
            {
                // let the window be where it is.
                uFlags |= Win32Wrapper.SWP_NOMOVE;
            }

            Win32Wrapper.SetWindowPos(_gameWindowHwnd, 0, 0, 0, newHorizontalResolution, newVerticalResolution, uFlags);
            if (GameSpecificConstants.HotsamplingRequiresEXITSIZEMOVE)
            {
                // A warning of unreachable code will be raised here, that's ok. this code is only used when the constant is true
                Win32Wrapper.SendMessage(_gameWindowHwnd, Win32Wrapper.WM_EXITSIZEMOVE, 0, 0);
            }

            // remove / add borders
            uint nStyle = (uint)Win32Wrapper.GetWindowLong(_gameWindowHwnd, Win32Wrapper.GWL_STYLE);

            nStyle = (nStyle | (Win32Wrapper.WS_THICKFRAME + Win32Wrapper.WS_DLGFRAME + Win32Wrapper.WS_BORDER + Win32Wrapper.WS_MAXIMIZEBOX + Win32Wrapper.WS_MINIMIZEBOX));
            if (!_useWindowBordersCheckBox.Checked)
            {
                nStyle ^= (Win32Wrapper.WS_THICKFRAME + Win32Wrapper.WS_DLGFRAME + Win32Wrapper.WS_BORDER + Win32Wrapper.WS_MAXIMIZEBOX + Win32Wrapper.WS_MINIMIZEBOX);
            }
            Win32Wrapper.SetWindowLong(_gameWindowHwnd, Win32Wrapper.GWL_STYLE, nStyle);
            uFlags = Win32Wrapper.SWP_NOSIZE | Win32Wrapper.SWP_NOMOVE | Win32Wrapper.SWP_NOZORDER | Win32Wrapper.SWP_NOACTIVATE | Win32Wrapper.SWP_NOOWNERZORDER | Win32Wrapper.SWP_NOSENDCHANGING | Win32Wrapper.SWP_FRAMECHANGED;
            Win32Wrapper.SetWindowPos(_gameWindowHwnd, 0, 0, 0, 0, 0, uFlags);
        }