Example #1
0
        private int BuildClipPlanesImpl(RwCamera *rwCamera)
        {
            if (rwCamera == (void *)0)
            {
                return(BuildClipPlanesHook.OriginalFunction(rwCamera));
            }

            // Get window client size dimensions.
            var windowHandle = Variables.WindowHandle;

            if (!windowHandle.IsNull)
            {
                // Get current resolution (size of window client area)
                RECT clientSize = new RECT();
                User32_Gdi.GetClientRect(Variables.WindowHandle, ref clientSize);

                float aspectRatio         = AspectConverter.ToAspectRatio(ref clientSize);
                float relativeAspectRatio = AspectConverter.GetRelativeAspect(aspectRatio);

                // Stretch X/Y
                (*rwCamera).StretchViewWindow(aspectRatio, relativeAspectRatio, AspectRatioLimit);

                // Call original.
                int result = BuildClipPlanesHook.OriginalFunction(rwCamera);

                // Reverse Stretch of X/Y
                (*rwCamera).UnStretchViewWindow(aspectRatio, relativeAspectRatio, AspectRatioLimit);
                return(result);
            }

            return(BuildClipPlanesHook.OriginalFunction(rwCamera));
        }
Example #2
0
        private int TObjCameraInit(IntPtr thisPointer, int camLimit)
        {
            // Backup old resolution.
            var windowHandle = Variables.WindowHandle;

            if (!windowHandle.IsNull)
            {
                User32_Gdi.GetWindowRect(windowHandle, out var windowRect);
                int resolutionXBackup = windowRect.Width;
                int resolutionYBackup = windowRect.Height;

                // Get new resolution
                int greaterResolution = resolutionXBackup > resolutionYBackup ? resolutionXBackup : resolutionYBackup;
                AspectConverter.WidthToResolution(greaterResolution, AspectConverter.OriginalGameAspect, out var resolution);

                // Temp resize window and execute.
                User32_Gdi.MoveWindow(windowHandle, windowRect.left, windowRect.top, resolution.Width, resolution.Height, false);

                int result = _cameraInitHook.OriginalFunction(thisPointer, camLimit);

                // Restore window.
                User32_Gdi.MoveWindow(windowHandle, windowRect.left, windowRect.top, resolutionXBackup, resolutionYBackup, false);

                return(result);
            }

            return(_cameraInitHook.OriginalFunction(thisPointer, camLimit));
        }
Example #3
0
        public Form1()
        {
            InitializeComponent();
            var handler = User32_Gdi.FindWindow("#32770", "Windows 任务管理器");

            if (!handler.IsNull)
            {
                User32_Gdi.SetParent(handler, new HWND(Handle));
            }
        }
Example #4
0
        /* Patching hardcoded values in ResolutionVariablePatcher via events. */
        private void MessagePump()
        {
            _resolutionVariablePatcher = new ResolutionVariablePatcher(_config);
            _resolutionVariablePatcher.Patch(_config.Width, _config.Height);

            while (User32_Gdi.GetMessage(out var msg, HWND.NULL, 0, 0))
            {
                User32_Gdi.TranslateMessage(msg);
                User32_Gdi.DispatchMessage(msg);
            }
        }
        /* Patching hardcoded values in ResolutionVariablePatcher via events. */
        private void MessagePump()
        {
            _resizeEventHook = new ResizeEventHook();
            _resolutionVariablePatcher.SubscribeToResizeEventHook(_resizeEventHook);
            _renderHooks.SubscribeToResizeEventHook(_resizeEventHook);

            while (User32_Gdi.GetMessage(out var msg, HWND.NULL, 0, 0))
            {
                User32_Gdi.TranslateMessage(msg);
                User32_Gdi.DispatchMessage(msg);
            }
        }
Example #6
0
        /* Patching Resolution Changes Section */
        private void OnLocationChange(User32.HWINEVENTHOOK hWinEventHook, uint winEvent, HWND hWnd, int idObject, int idChild, uint idEventThread, uint dwmsEventTime)
        {
            if (idObject != 0 || idChild != 0)
            {
                return;
            }

            if (winEvent == EventObjectLocationchange)
            {
                // Two things performed here.
                RECT rect = new RECT();
                User32_Gdi.GetClientRect(Variables.WindowHandle, ref rect);

                Patch(rect.Width, rect.Height);
            }
        }
Example #7
0
        private void SetViewWindowImpl(RwCamera *rwCamera, RwView *view)
        {
            SetViewWindowHook.OriginalFunction(rwCamera, view);

            var windowHandle = Variables.WindowHandle;

            if (!windowHandle.IsNull)
            {
                // Get current resolution (size of window client area)
                RECT clientSize = new RECT();
                User32_Gdi.GetClientRect(Variables.WindowHandle, ref clientSize);

                float aspectRatio         = AspectConverter.ToAspectRatio(ref clientSize);
                float relativeAspectRatio = AspectConverter.GetRelativeAspect(aspectRatio);

                // Unstretch X/Y
                (*rwCamera).UnStretchRecipViewWindow(aspectRatio, relativeAspectRatio, AspectRatioLimit);
            }
        }
Example #8
0
        /// <summary>
        /// 起動中の同一アプリケーションに対して指定されたデータを送信します。
        /// </summary>
        /// <param name="args">送信するデータ</param>
        /// <returns>処理されたかどうかを示す値</returns>
        private bool TrySendArgs(IEnumerable <string> args)
        {
            // HACK: ウィンドウハンドルの取得
            // 本アプリは MainWindow が非表示であるため Process.MainWindowHandle からハンドルを取得できない。
            // すべてのハンドルを列挙し、ウィンドウテキストから特定を試みる。
            var target = HWND.NULL;

            if (User32_Gdi.EnumWindows(
                    new User32_Gdi.WNDENUMPROC((hWnd, _) =>
            {
                try
                {
                    var lpString = new StringBuilder(256);
                    User32_Gdi.GetWindowText(hWnd, lpString, lpString.Capacity);
                    if (lpString.ToString().Contains(Workspace.WINDOW_TITLE) == false)
                    {
                        return(true);
                    }
                    target = hWnd;
                    return(false);
                }
                catch
                {
                    return(true);
                }
            }),
                    IntPtr.Zero))
            {
                return(false);
            }

            // 引数を送信する
            var structure = new COPYDATASTRUCT();

            structure.dwData = IntPtr.Zero;
            structure.lpData = args.Any() ? string.Join("|", args) : string.Empty;
            structure.cbData = Encoding.UTF8.GetByteCount(structure.lpData) + 1;
            var lParam = Marshal.AllocHGlobal(Marshal.SizeOf(structure));

            Marshal.StructureToPtr(structure, lParam, false);
            User32_Gdi.SendMessage(target, (uint)User32_Gdi.WindowMessage.WM_COPYDATA, Process.GetCurrentProcess().Handle, lParam);
            return(true);
        }
Example #9
0
        /* Patching Resolution Changes Section */
        private void OnLocationChange(User32.HWINEVENTHOOK hWinEventHook, uint winEvent, HWND hWnd, int idObject, int idChild, uint idEventThread, uint dwmsEventTime)
        {
            if (idObject != 0 || idChild != 0)
            {
                return;
            }

            if (winEvent == EventObjectLocationchange)
            {
                // Two things performed here.
                RECT rect = new RECT();
                User32_Gdi.GetClientRect(Variables.WindowHandle, ref rect);
                CurrentHeight       = rect.Height;
                CurrentWidth        = rect.Width;
                ActualAspectRatio   = CurrentWidth / (float)CurrentHeight;
                RelativeAspectRatio = AspectConverter.GetRelativeAspect(ActualAspectRatio);

                Resized?.Invoke(this);
            }
        }
Example #10
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch ((User32_Gdi.WindowMessage)msg)
            {
            case User32_Gdi.WindowMessage.WM_DRAWCLIPBOARD:
                User32_Gdi.SendMessage(this._nextHandle, (uint)msg, wParam, lParam);
                this.OnDrawClipboard();
                handled = true;
                break;

            case User32_Gdi.WindowMessage.WM_CHANGECBCHAIN:
                if (wParam == this._nextHandle)
                {
                    this._nextHandle = lParam;
                }
                else
                {
                    User32_Gdi.SendMessage(this._nextHandle, (uint)msg, wParam, lParam);
                }
                handled = true;
                break;
            }
            return(IntPtr.Zero);
        }
Example #11
0
 internal static HWND IWin2Ptr(System.Windows.Forms.IWin32Window wnd, bool desktopIfNull = true) => wnd?.Handle ?? User32_Gdi.FindWindow("Progman", null);
Example #12
0
 internal static IntPtr IWin2Ptr(System.Windows.Forms.IWin32Window wnd, bool desktopIfNull = true)
 {
     return(wnd == null?User32_Gdi.FindWindow("Progman", null) : (IntPtr) new HandleRef(wnd, wnd.Handle));
 }