Advertisement
Funplayer

Unlock Window: RGSS2, RGSS3

Aug 20th, 2014
2,672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.29 KB | None | 0 0
  1. ################################################################################
  2. # Graphics add-on
  3. #    Plug N Play Window Unlocker.
  4. ################################################################################
  5. # Simple Directions:
  6. #   Simply place this script above your main and it will be ready.
  7. #
  8. #   Currently it creates a file named saved_resolution.txt to dump changed
  9. #   window metric variables, and extract changed window metric variables on load.  
  10. #
  11. #   Note:  Writes every time you change the window metrics.
  12. #   See line 67 for file location.
  13. ################################################################################
  14. # Advanced Directions:
  15. #   See microsoft's website for the directions on what each of these
  16. #   window styles do.  That will assist with editing the mainWindow.
  17. ################################################################################
  18.  
  19. ################################################################################
  20. # Created By Funplayer
  21. #   Use, destroy, replicate, whatever.
  22. #   Just make sure my name is in the credits, and you tell me when your game
  23. #   is on steam.  I'll go buy it.
  24. ################################################################################
  25.  
  26. module Window_Styles
  27.  
  28.   WS_BORDER = 0x00800000
  29.   WS_CAPTION = 0x00C00000
  30.   WS_CHILD = 0x40000000
  31.   WS_CHILDWINDOW = 0x40000000
  32.   WS_CLIPCHILDREN = 0x02000000
  33.   WS_CLIPSIBLINGS = 0x04000000
  34.   WS_DISABLED = 0x08000000
  35.   WS_DLGFRAME = 0x00400000
  36.   WS_GROUP = 0x00020000
  37.   WS_HSCROLL = 0x00100000
  38.   WS_ICONIC = 0x20000000
  39.   WS_MAXIMIZE = 0x01000000
  40.   WS_MAXIMIZEBOX = 0x00010000
  41.   WS_MINIMIZE = 0x20000000
  42.   WS_MINIMIZEBOX = 0x00020000
  43.   WS_OVERLAPPED = 0x00000000
  44.   WS_POPUP = 0x80000000
  45.   WS_SIZEBOX = 0x00040000
  46.   WS_SYSMENU = 0x00080000
  47.   WS_TABSTOP = 0x00010000
  48.   WS_THICKFRAME = 0x00040000
  49.   WS_TILED = 0x00000000
  50.   WS_VISIBLE = 0x10000000
  51.   WS_VSCROLL = 0x00200000
  52.  
  53.   def self.mainWindow
  54.     return (WS_BORDER |
  55.         WS_CAPTION   |
  56.         WS_CLIPSIBLINGS   |
  57.         WS_DLGFRAME   |
  58.         WS_GROUP   |
  59.         WS_MINIMIZEBOX   |
  60.         WS_MAXIMIZEBOX   |
  61.         WS_SYSMENU   |
  62.         WS_VISIBLE   |
  63.         WS_THICKFRAME  
  64.       )
  65.   end
  66.  
  67. end
  68.  
  69. class << Graphics
  70.   @@file_path        = "saved_resolution.txt"
  71.  
  72.   @@updateWindow     = Win32API.new('user32', 'UpdateWindow', 'l', 'l')
  73.   @@setWindowPos     = Win32API.new('user32', 'SetWindowPos','lllllll','l')
  74.   @@getSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')  
  75.   @@showWindow       = Win32API.new('user32', 'ShowWindow', 'll', 'l')
  76.   @@moveWindow       = Win32API.new('user32', 'MoveWindow',['l','i','i','i','i','l'],'l')
  77.   @@findWindowEx     = Win32API.new('user32', 'FindWindowEx',['l','l','p','p'],'i')
  78.   @@mainWindow       = @@findWindowEx.call(0,0,"RGSS Player",0)
  79.   @@getWindowRect    = Win32API.new("user32", "GetWindowRect",['P','PP'],'N')
  80.   @@getWindowInfo    = Win32API.new('user32', 'GetWindowInfo',['l'], 'l')
  81.   @@setWindowLong    = Win32API.new('user32', 'SetWindowLong','lll','l')
  82.  
  83.   @@ratioValue       = 1.30769230769231
  84.   @@screenWidth      = @@getSystemMetrics.call(0)
  85.   @@screenHeight     = @@getSystemMetrics.call(1)
  86.   @reso_setup        = false
  87.  
  88.   def setDefaultWindow
  89.     initialize_data
  90.   end
  91.  
  92.   alias update_replace update unless $@
  93.   def update(*args, &block)
  94.     update_replace(*args, &block)
  95.     if changed?
  96.       force_resolution
  97.       initialize_data
  98.     end
  99.   end
  100.  
  101.   def initialize_data
  102.     set_up_resolution_file unless prepared?
  103.     initializeMetrics
  104.     setUpMainWindow
  105.   end
  106.  
  107.   def prepared?
  108.     return ( @reso_setup )
  109.   end
  110.  
  111.   def initializeMetrics
  112.     defWidth     = $def_width
  113.     defHeight    = $def_height
  114.     screenWidth = @@getSystemMetrics.call(0)
  115.     screenHeight = @@getSystemMetrics.call(1)
  116.     @@width_multiplier = defWidth + (@@getSystemMetrics.call(5)+8)*2
  117.     @@height_multiplier = defHeight + (@@getSystemMetrics.call(6)+7)*2 + @@getSystemMetrics.call(4)
  118.     @@defaultWidth = ((screenWidth - @@width_multiplier) / 2)
  119.     @@defaultHeight = ((screenHeight - @@height_multiplier) / 2)
  120.   end
  121.  
  122.   def f_getMainWindowRect
  123.     pw = @@mainWindow
  124.     rect = Array.new.fill(0.chr,0..4*4).join
  125.     @@getWindowRect.call(pw,rect);
  126.     rect=rect.unpack("i*")
  127.     rect[2]=rect[2]-rect[0] #w=x2-x1
  128.     rect[3]=rect[3]-rect[1] #h=y2-y1
  129.     return rect
  130.   end
  131.  
  132.   def setUpMainWindow
  133.     @@showWindow.call(@@mainWindow, 5)
  134.     @@updateWindow.call(@@mainWindow)
  135.     @@setWindowLong.call(@@mainWindow, -16, Window_Styles.mainWindow)#0x14CA0000)
  136.     @@setWindowPos.call(@@mainWindow, 0, $def_x,$def_y,@@width_multiplier,@@height_multiplier, 0)
  137.   end
  138.  
  139.   def changed?
  140.     rect = f_getMainWindowRect
  141.     if $def_x != rect[0] or $def_y != rect[1] or
  142.           $def_width != (rect[2] - 18) or
  143.           $def_height != (rect[3] - 38)
  144.       $def_x = rect[0]
  145.       $def_y = rect[1]
  146.       $def_width = (rect[2] - 18)
  147.       $def_height = (rect[3] - 38)
  148.       return true
  149.     end
  150.     return false
  151.   end
  152.    
  153.   # Runs the logical process to create a proper valued ratio for the
  154.   # main game window.  This loop is still buggy, but it is much better
  155.   # than the last loop.
  156.   def force_resolution
  157.     set_up_resolution_file
  158.     # Determines ratio from constant
  159.     saved_ratio = (@@ratioValue*10000).truncate.to_i
  160.     # Checks if ratio is less than the minimum limit.
  161.     $def_width = 544 if $def_width < 544
  162.     $def_height = 416 if $def_height < 416
  163.     # Checks if the ratio is too large compared to your monitor.
  164.     $def_width -= ($def_width * 0.20).to_i if $def_width > @@screenWidth
  165.     $def_height -= ($def_height * 0.20).to_i if $def_height > @@screenHeight
  166.     # Chops off the extra counts from the ratioif need be.
  167.     $def_width = $def_width - ($def_width % 17) if $def_width % 17 != 0
  168.     $def_height = $def_height - ($def_height % 13) if $def_height % 13 != 0
  169.     # Creates a new ratio from the chopped counts
  170.     new_ratio = (($def_width.to_f/$def_height.to_f)*10000).truncate.to_i
  171.     # Runs a loop until the new ratio equals the saved ratio.
  172.     until new_ratio == saved_ratio
  173.       # If the ratio is greater than the ratio, the width is larger, so
  174.       # increase the height
  175.       if new_ratio > saved_ratio
  176.         if $def_height < @@screenHeight
  177.           $def_height += 13
  178.         else
  179.           $def_width -= 17
  180.         end
  181.       # Elseif increase the width, because the width needs to be changed.
  182.       elsif new_ratio < saved_ratio
  183.         if $def_width < @@screenWidth
  184.           $def_width += 17
  185.         else
  186.           $def_height -= 13
  187.         end
  188.       end
  189.       # Resets the main loop's variable to test again.
  190.       new_ratio = (($def_width.to_f/$def_height.to_f)*10000).truncate.to_i
  191.     end
  192.     if $def_width > @@screenWidth or $def_height > @@screenHeight
  193.       $def_width -= ($def_width * 0.10).to_i
  194.       $def_height -= ($def_height * 0.10).to_i
  195.     end
  196.     # Repositions the window if the window is out of balance
  197.     $def_x = 0 if $def_x < 0
  198.     $def_x = (@@screenWidth / 2).to_i if $def_x > @@screenWidth
  199.     $def_y = 0 if $def_y < 0
  200.     $def_y = (@@screenHeight / 2).to_i if $def_y > @@screenHeight
  201.     # Checks if the window is too far to the right.
  202.     $def_x = (@@screenWidth - $def_width) if ($def_x + $def_width) > @@screenWidth
  203.     $def_y = (@@screenHeight - $def_height) if ($def_y + $def_height) > @@screenHeight
  204.     # Once the new resolution is ready, it saves to file.
  205.     save_resolution_file
  206.   end
  207.  
  208.   def set_up_resolution_file
  209.     return if @reso_setup
  210.     @reso_setup = true
  211.     if File.exist?(@@file_path)
  212.       resolution_file    = File.open(@@file_path, 'r')
  213.       $def_x          = resolution_file.readline.to_i
  214.       $def_y          = resolution_file.readline.to_i
  215.       $def_width      = resolution_file.readline.to_i
  216.       $def_height     = resolution_file.readline.to_i
  217.       resolution_file.close
  218.       resolution_file = nil
  219.     else
  220.       File.open(@@file_path, 'w') do |file|
  221.         file.puts "#{$def_x}"
  222.         file.puts "#{$def_y}"
  223.         file.puts "#{$def_width}"
  224.         file.puts "#{$def_height}"
  225.       end
  226.     end
  227.   end
  228.  
  229.   def save_resolution_file
  230.     File.open(@@file_path, 'w') do |file|
  231.       file.puts "#{$def_x}"
  232.       file.puts "#{$def_y}"
  233.       file.puts "#{$def_width}"
  234.       file.puts "#{$def_height}"
  235.     end
  236.   end
  237.  
  238. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement