Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##################################################
- #
- # README INFORMATION
- #
- ##################################################
- # This script allows running Raft as a resizable and movable window
- #
- # The first thing that needs to be done is to save this to your computer
- # as a *.ps1 file (that last character is the number 1). This is the
- # extension for powershell scripts, a terminal scripting language
- # that comes standard with WindowOS.
- #
- # The next thing to do is set up your computer to run powershell scripts.
- # For reference:
- # https://www.windowscentral.com/how-create-and-run-your-first-powershell-script-file-windows-10
- # "
- # If you want to run a script file on PowerShell, you have to change the execution policy on Windows 10.
- #
- # To change the execution policy to run PowerShell scripts, use these steps:
- #
- # Open Start.
- # Search for PowerShell, right-click the top-result and click the Run as administrator option.
- # Type the following command to allow scripts to run and press Enter:
- #
- # Set-ExecutionPolicy RemoteSigned
- #
- # Type A and press Enter.
- # "
- #
- # Then run Raft, and then run this script.
- # Note that you can't double click its icon - to run it from the file
- # explorer, the script needs to be right clicked, and select
- # "Run With Powershell"
- ##################################################
- #
- # THE SCRIPT
- #
- ###################################################
- # Get the the WindowsOS system functions we need marshalled into powershell
- $sig=@'
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll")]
- public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
- [DllImport("user32.dll")]
- public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
- [DllImport("user32.dll")]
- public static extern int MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, int bRepaint);
- '@
- # Take the import request of $sig and process it into an object
- $w32 = Add-Type -Namespace Win32 -Name Funcs -MemberDefinition $sig -PassThru
- # Constant value copied from Windows SDK WinUser.h
- # https://referencesource.microsoft.com/#UIAutomationClientsideProviders/MS/Win32/NativeMethods.cs,1dd555fb554b6b34
- $GWL_STYLE = -16
- # Get the handle of Raft that's running (The game is already running before you
- # ran this script, right?)
- #
- # These values are specific to how Raft creates itself. They were
- #discovered with Spy++.
- $raftWin = $w32::FindWindow('UnityWndClass', 'Raft')
- # Get the description of what kind of window styles it has.
- $displayFlags = $w32::GetWindowLong($raftWin, $GWL_STYLE)
- # Add resize handles on the edges, and the window titlebar back in.
- # We do that by adding in a composite style flag called WS_OVERLAPPEDWINDOW.
- # For this script, we're just going to copy its known values and
- # recreate that flag. Applying these styles is what gives desktop applications
- # their resize bars, titlebar, and other things (like the minimize and maximize
- # buttons in the titlebar, etc).
- #
- # First we copy in the window style flags of WS_OVERLAPPEDWINDOW
- # https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles
- #
- # We're going to take things slowly and define each of what we need
- # separately.
- $WS_OVERLAPPED = 0x00000000
- $WS_CAPTION = 0x00C00000
- $WS_SYSMENU = 0x00080000
- $WS_THICKFRAME = 0x00040000
- $WS_MINIMIZEBOX = 0x00020000
- $WS_MAXIMIZEBOX = 0x00010000
- # And bitwise or them together
- $WS_OVERLAPPEDWINDOW = $WS_OVERLAPPED -bor $WS_CAPTION -bor $WS_SYSMENU -bor $WS_THICKFRAME -bor $WS_MINIMIZEBOX -bor $WS_MAXIMIZEBOX
- # Add in the style.
- $displayFlags = $displayFlags -bor $WS_OVERLAPPEDWINDOW
- # And set the window to use the modified value.
- $w32::SetWindowLong($raftWin, $GWL_STYLE, $displayFlags)
- # And it's done, but the app may not instantly know that,
- # so we tinker with the window a little bit to poke it so
- # that our changes take effect.
- $w32::MoveWindow($raftWin, 0, 0, 800, 640, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement