Advertisement
Reavenk

RaftResizabler

Aug 5th, 2019 (edited)
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##################################################
  2. #
  3. #       README INFORMATION
  4. #
  5. ##################################################
  6. # This script allows running Raft as a resizable and movable window
  7. #
  8. # The first thing that needs to be done is to save this to your computer
  9. # as a *.ps1 file (that last character is the number 1). This is the
  10. # extension for powershell scripts, a terminal scripting language
  11. # that comes standard with WindowOS.
  12. #
  13. # The next thing to do is set up your computer to run powershell scripts.
  14. # For reference:
  15. # https://www.windowscentral.com/how-create-and-run-your-first-powershell-script-file-windows-10
  16. # "
  17. #   If you want to run a script file on PowerShell, you have to change the execution policy on Windows 10.
  18. #
  19. #   To change the execution policy to run PowerShell scripts, use these steps:
  20. #  
  21. #   Open Start.
  22. #   Search for PowerShell, right-click the top-result and click the Run as administrator option.
  23. #   Type the following command to allow scripts to run and press Enter:
  24. #  
  25. #   Set-ExecutionPolicy RemoteSigned
  26. #  
  27. #   Type A and press Enter.
  28. # "
  29. #
  30. # Then run Raft, and then run this script.
  31. # Note that you can't double click its icon - to run it from the file
  32. # explorer, the script needs to be right clicked, and select
  33. # "Run With Powershell"
  34.  
  35. ##################################################
  36. #
  37. #       THE SCRIPT
  38. #
  39. ###################################################
  40. # Get the the WindowsOS system functions we need marshalled into powershell
  41. $sig=@'
  42. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  43. public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  44.  
  45. [DllImport("user32.dll")]
  46. public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
  47.  
  48. [DllImport("user32.dll")]
  49. public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
  50.  
  51. [DllImport("user32.dll")]
  52. public static extern int MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, int bRepaint);
  53. '@    
  54.  
  55. # Take the import request of $sig and process it into an object
  56. $w32 = Add-Type -Namespace Win32 -Name Funcs -MemberDefinition $sig -PassThru
  57.  
  58. # Constant value copied from Windows SDK WinUser.h
  59. # https://referencesource.microsoft.com/#UIAutomationClientsideProviders/MS/Win32/NativeMethods.cs,1dd555fb554b6b34
  60. $GWL_STYLE = -16
  61.  
  62. # Get the handle of Raft that's running (The game is already running before you
  63. # ran this script, right?)
  64. #
  65. # These values are specific to how Raft creates itself. They were
  66. #discovered with Spy++.
  67. $raftWin = $w32::FindWindow('UnityWndClass', 'Raft')
  68.  
  69. # Get the description of what kind of window styles it has.
  70. $displayFlags = $w32::GetWindowLong($raftWin, $GWL_STYLE)
  71. # Add resize handles on the edges, and the window titlebar back in.
  72. # We do that by adding in a composite style flag called WS_OVERLAPPEDWINDOW.
  73. # For this script, we're just going to copy its known values and
  74. # recreate that flag. Applying these styles is what gives desktop applications
  75. # their resize bars, titlebar, and other things (like the minimize and maximize
  76. # buttons in the titlebar, etc).
  77. #
  78. # First we copy in the window style flags of WS_OVERLAPPEDWINDOW
  79. # https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles
  80. #
  81. # We're going to take things slowly and define each of what we need
  82. # separately.
  83. $WS_OVERLAPPED      = 0x00000000
  84. $WS_CAPTION         = 0x00C00000
  85. $WS_SYSMENU         = 0x00080000
  86. $WS_THICKFRAME      = 0x00040000
  87. $WS_MINIMIZEBOX     = 0x00020000
  88. $WS_MAXIMIZEBOX     = 0x00010000
  89. # And bitwise or them together
  90. $WS_OVERLAPPEDWINDOW = $WS_OVERLAPPED -bor $WS_CAPTION -bor $WS_SYSMENU -bor $WS_THICKFRAME -bor $WS_MINIMIZEBOX -bor $WS_MAXIMIZEBOX
  91.  
  92. # Add in the style.
  93. $displayFlags = $displayFlags -bor $WS_OVERLAPPEDWINDOW
  94. # And set the window to use the modified value.
  95. $w32::SetWindowLong($raftWin, $GWL_STYLE, $displayFlags)
  96.  
  97. # And it's done, but the app may not instantly know that,
  98. # so we tinker with the window a little bit to poke it so
  99. # that our changes take effect.
  100. $w32::MoveWindow($raftWin, 0, 0, 800, 640, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement