Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################
- # Graphics add-on
- # Plug N Play Window Unlocker.
- ################################################################################
- # Simple Directions:
- # Simply place this script above your main and it will be ready.
- #
- # Currently it creates a file named saved_resolution.txt to dump changed
- # window metric variables, and extract changed window metric variables on load.
- #
- # Note: Writes every time you change the window metrics.
- # See line 67 for file location.
- ################################################################################
- # Advanced Directions:
- # See microsoft's website for the directions on what each of these
- # window styles do. That will assist with editing the mainWindow.
- ################################################################################
- ################################################################################
- # Created By Funplayer
- # Use, destroy, replicate, whatever.
- # Just make sure my name is in the credits, and you tell me when your game
- # is on steam. I'll go buy it.
- ################################################################################
- module Window_Styles
- WS_BORDER = 0x00800000
- WS_CAPTION = 0x00C00000
- WS_CHILD = 0x40000000
- WS_CHILDWINDOW = 0x40000000
- WS_CLIPCHILDREN = 0x02000000
- WS_CLIPSIBLINGS = 0x04000000
- WS_DISABLED = 0x08000000
- WS_DLGFRAME = 0x00400000
- WS_GROUP = 0x00020000
- WS_HSCROLL = 0x00100000
- WS_ICONIC = 0x20000000
- WS_MAXIMIZE = 0x01000000
- WS_MAXIMIZEBOX = 0x00010000
- WS_MINIMIZE = 0x20000000
- WS_MINIMIZEBOX = 0x00020000
- WS_OVERLAPPED = 0x00000000
- WS_POPUP = 0x80000000
- WS_SIZEBOX = 0x00040000
- WS_SYSMENU = 0x00080000
- WS_TABSTOP = 0x00010000
- WS_THICKFRAME = 0x00040000
- WS_TILED = 0x00000000
- WS_VISIBLE = 0x10000000
- WS_VSCROLL = 0x00200000
- def self.mainWindow
- return (WS_BORDER |
- WS_CAPTION |
- WS_CLIPSIBLINGS |
- WS_DLGFRAME |
- WS_GROUP |
- WS_MINIMIZEBOX |
- WS_MAXIMIZEBOX |
- WS_SYSMENU |
- WS_VISIBLE |
- WS_THICKFRAME
- )
- end
- end
- class << Graphics
- @@file_path = "saved_resolution.txt"
- @@updateWindow = Win32API.new('user32', 'UpdateWindow', 'l', 'l')
- @@setWindowPos = Win32API.new('user32', 'SetWindowPos','lllllll','l')
- @@getSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
- @@showWindow = Win32API.new('user32', 'ShowWindow', 'll', 'l')
- @@moveWindow = Win32API.new('user32', 'MoveWindow',['l','i','i','i','i','l'],'l')
- @@findWindowEx = Win32API.new('user32', 'FindWindowEx',['l','l','p','p'],'i')
- @@mainWindow = @@findWindowEx.call(0,0,"RGSS Player",0)
- @@getWindowRect = Win32API.new("user32", "GetWindowRect",['P','PP'],'N')
- @@getWindowInfo = Win32API.new('user32', 'GetWindowInfo',['l'], 'l')
- @@setWindowLong = Win32API.new('user32', 'SetWindowLong','lll','l')
- @@ratioValue = 1.30769230769231
- @@screenWidth = @@getSystemMetrics.call(0)
- @@screenHeight = @@getSystemMetrics.call(1)
- @reso_setup = false
- def setDefaultWindow
- initialize_data
- end
- alias update_replace update unless $@
- def update(*args, &block)
- update_replace(*args, &block)
- if changed?
- force_resolution
- initialize_data
- end
- end
- def initialize_data
- set_up_resolution_file unless prepared?
- initializeMetrics
- setUpMainWindow
- end
- def prepared?
- return ( @reso_setup )
- end
- def initializeMetrics
- defWidth = $def_width
- defHeight = $def_height
- screenWidth = @@getSystemMetrics.call(0)
- screenHeight = @@getSystemMetrics.call(1)
- @@width_multiplier = defWidth + (@@getSystemMetrics.call(5)+8)*2
- @@height_multiplier = defHeight + (@@getSystemMetrics.call(6)+7)*2 + @@getSystemMetrics.call(4)
- @@defaultWidth = ((screenWidth - @@width_multiplier) / 2)
- @@defaultHeight = ((screenHeight - @@height_multiplier) / 2)
- end
- def f_getMainWindowRect
- pw = @@mainWindow
- rect = Array.new.fill(0.chr,0..4*4).join
- @@getWindowRect.call(pw,rect);
- rect=rect.unpack("i*")
- rect[2]=rect[2]-rect[0] #w=x2-x1
- rect[3]=rect[3]-rect[1] #h=y2-y1
- return rect
- end
- def setUpMainWindow
- @@showWindow.call(@@mainWindow, 5)
- @@updateWindow.call(@@mainWindow)
- @@setWindowLong.call(@@mainWindow, -16, Window_Styles.mainWindow)#0x14CA0000)
- @@setWindowPos.call(@@mainWindow, 0, $def_x,$def_y,@@width_multiplier,@@height_multiplier, 0)
- end
- def changed?
- rect = f_getMainWindowRect
- if $def_x != rect[0] or $def_y != rect[1] or
- $def_width != (rect[2] - 18) or
- $def_height != (rect[3] - 38)
- $def_x = rect[0]
- $def_y = rect[1]
- $def_width = (rect[2] - 18)
- $def_height = (rect[3] - 38)
- return true
- end
- return false
- end
- # Runs the logical process to create a proper valued ratio for the
- # main game window. This loop is still buggy, but it is much better
- # than the last loop.
- def force_resolution
- set_up_resolution_file
- # Determines ratio from constant
- saved_ratio = (@@ratioValue*10000).truncate.to_i
- # Checks if ratio is less than the minimum limit.
- $def_width = 544 if $def_width < 544
- $def_height = 416 if $def_height < 416
- # Checks if the ratio is too large compared to your monitor.
- $def_width -= ($def_width * 0.20).to_i if $def_width > @@screenWidth
- $def_height -= ($def_height * 0.20).to_i if $def_height > @@screenHeight
- # Chops off the extra counts from the ratioif need be.
- $def_width = $def_width - ($def_width % 17) if $def_width % 17 != 0
- $def_height = $def_height - ($def_height % 13) if $def_height % 13 != 0
- # Creates a new ratio from the chopped counts
- new_ratio = (($def_width.to_f/$def_height.to_f)*10000).truncate.to_i
- # Runs a loop until the new ratio equals the saved ratio.
- until new_ratio == saved_ratio
- # If the ratio is greater than the ratio, the width is larger, so
- # increase the height
- if new_ratio > saved_ratio
- if $def_height < @@screenHeight
- $def_height += 13
- else
- $def_width -= 17
- end
- # Elseif increase the width, because the width needs to be changed.
- elsif new_ratio < saved_ratio
- if $def_width < @@screenWidth
- $def_width += 17
- else
- $def_height -= 13
- end
- end
- # Resets the main loop's variable to test again.
- new_ratio = (($def_width.to_f/$def_height.to_f)*10000).truncate.to_i
- end
- if $def_width > @@screenWidth or $def_height > @@screenHeight
- $def_width -= ($def_width * 0.10).to_i
- $def_height -= ($def_height * 0.10).to_i
- end
- # Repositions the window if the window is out of balance
- $def_x = 0 if $def_x < 0
- $def_x = (@@screenWidth / 2).to_i if $def_x > @@screenWidth
- $def_y = 0 if $def_y < 0
- $def_y = (@@screenHeight / 2).to_i if $def_y > @@screenHeight
- # Checks if the window is too far to the right.
- $def_x = (@@screenWidth - $def_width) if ($def_x + $def_width) > @@screenWidth
- $def_y = (@@screenHeight - $def_height) if ($def_y + $def_height) > @@screenHeight
- # Once the new resolution is ready, it saves to file.
- save_resolution_file
- end
- def set_up_resolution_file
- return if @reso_setup
- @reso_setup = true
- if File.exist?(@@file_path)
- resolution_file = File.open(@@file_path, 'r')
- $def_x = resolution_file.readline.to_i
- $def_y = resolution_file.readline.to_i
- $def_width = resolution_file.readline.to_i
- $def_height = resolution_file.readline.to_i
- resolution_file.close
- resolution_file = nil
- else
- File.open(@@file_path, 'w') do |file|
- file.puts "#{$def_x}"
- file.puts "#{$def_y}"
- file.puts "#{$def_width}"
- file.puts "#{$def_height}"
- end
- end
- end
- def save_resolution_file
- File.open(@@file_path, 'w') do |file|
- file.puts "#{$def_x}"
- file.puts "#{$def_y}"
- file.puts "#{$def_width}"
- file.puts "#{$def_height}"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement