Advertisement
Kaelan

Max Resolution Breaker v1.3

Jun 6th, 2014
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.80 KB | None | 0 0
  1. =begin
  2. #===============================================================================
  3.  Title: Unlimited Resolution
  4.  Date: Oct 24, 2013
  5. --------------------------------------------------------------------------------
  6.  ** Change log
  7.  Jun 6, 2014
  8.    - Kaelan: fixed several bugs in the Plane class which prevented the sprite
  9.      from being modified correctly. Patched for compatibility with Victor's
  10.      Fogs and Overlays script. Include this after his script.
  11.  Apr 20, 2014
  12.    - added Kaelan's suggestion for disposing the viewport when done with it
  13.  Nov 6, 2013
  14.    - added some plane modifications to fix parallax images
  15.  Oct 24, 2013
  16.    - Initial release
  17. --------------------------------------------------------------------------------  
  18.  ** Terms of Use
  19.  * Free
  20. --------------------------------------------------------------------------------
  21.  ** Description
  22.  
  23.  This script modifies Graphics.resize_screen to overcome the 640x480 limitation.
  24.  It also includes some code to properly display maps that are smaller than the
  25.  screen size.
  26.  
  27.  Now you can have arbitrarily large game resolutions.
  28.  
  29. --------------------------------------------------------------------------------
  30.  ** Installation
  31.  
  32.  You should place this script above all custom scripts
  33.  
  34. --------------------------------------------------------------------------------
  35.  ** Usage
  36.  
  37.  As usual, simply resize your screen using the script call
  38.  
  39.    Graphics.resize_screen(width, height)
  40.  
  41. --------------------------------------------------------------------------------
  42.  ** Credits
  43.  
  44.  Unknown author for overcoming the 640x480 limitation
  45.  Lantier, from RMW forums for posting the snippet above
  46.  Esrever for handling the viewport
  47.  Jet, for the custom Graphics code
  48.  FenixFyre, for the Plane class fix
  49.  Kaelan, for several bug fixes
  50.  
  51. #===============================================================================
  52. =end
  53. $imported = {} if $imported.nil?
  54. $imported["TH_UnlimitedResolution"] = true
  55. #===============================================================================
  56. # ** Configuration
  57. #===============================================================================
  58. class << SceneManager
  59.  
  60.   alias resolution_run run
  61.   def run(*args, &block)
  62.     Graphics.ensure_sprite
  63.     resolution_run(*args, &block)
  64.   end
  65. end
  66.  
  67. module Graphics
  68.  
  69.   @@super_sprite = Sprite.new
  70.   @@super_sprite.z = (2 ** (0.size * 8 - 2) - 1)
  71.  
  72.   class << self
  73.     alias :th_large_screen_resize_screen :resize_screen
  74.    
  75.     def freeze(*args, &block)
  76.       @@super_sprite.bitmap = snap_to_bitmap
  77.     end
  78.    
  79.     def transition(time = 10, filename = nil, vague = nil)
  80.       if filename
  81.         @@super_sprite.bitmap = Bitmap.new(filename)
  82.       end
  83.       @@super_sprite.opacity = 255
  84.       incs = 255.0 / time
  85.       time.times do |i|
  86.         @@super_sprite.opacity = 255.0 - incs * i
  87.         Graphics.wait(1)
  88.       end
  89.       @@super_sprite.bitmap.dispose if @@super_sprite.bitmap
  90.       reform_sprite_bitmap
  91.       Graphics.brightness = 255
  92.     end
  93.    
  94.     def reform_sprite_bitmap
  95.       @@super_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  96.       @@super_sprite.bitmap.fill_rect(@@super_sprite.bitmap.rect, Color.new(0, 0, 0, 255))
  97.     end
  98.    
  99.     def fadeout(frames)
  100.       incs = 255.0 / frames
  101.       frames.times do |i|
  102.         i += 1
  103.         Graphics.brightness = 255 - incs * i
  104.         Graphics.wait(1)
  105.       end
  106.     end
  107.    
  108.     def fadein(frames)
  109.       incs = 255.0 / frames
  110.       frames.times do |i|
  111.         Graphics.brightness = incs * i
  112.         Graphics.wait(1)
  113.       end
  114.     end
  115.  
  116.     def brightness=(i)
  117.       @@super_sprite.opacity = 255.0 - i
  118.     end
  119.    
  120.     def brightness
  121.       255 - @@super_sprite.opacity
  122.     end
  123.    
  124.     def ensure_sprite
  125.       if @@super_sprite.disposed?
  126.         @@super_sprite = Sprite.new
  127.         @@super_sprite.z = (2 ** (0.size * 8 - 2) - 1)
  128.         reform_sprite_bitmap
  129.       end
  130.     end
  131.   end
  132.  
  133.   #-----------------------------------------------------------------------------
  134.   # Unknown Scripter. Copied from http://pastebin.com/sM2MNJZj
  135.   #-----------------------------------------------------------------------------
  136.   def self.resize_screen(width, height)
  137.     wt, ht = width.divmod(32), height.divmod(32)
  138.     #wt.last + ht.last == 0 || fail('Incorrect width or height')
  139.     wh = -> w, h, off = 0 { [w + off, h + off].pack('l2').scan /.{4}/ }
  140.     w, h = wh.(width, height)
  141.     ww, hh = wh.(width, height, 32)
  142.     www, hhh = wh.(wt.first.succ, ht.first.succ)
  143.     base = 0x10000000  # fixed?
  144.     mod = -> adr, val { DL::CPtr.new(base + adr)[0, val.size] = val }
  145.     mod.(0x195F, "\x90" * 5)  # ???
  146.     mod.(0x19A4, h)
  147.     mod.(0x19A9, w)
  148.     mod.(0x1A56, h)
  149.     mod.(0x1A5B, w)
  150.     mod.(0x20F6, w)
  151.     mod.(0x20FF, w)
  152.     mod.(0x2106, h)
  153.     mod.(0x210F, h)
  154.     # speed up y?
  155.     #mod.(0x1C5E3, h)
  156.     #mod.(0x1C5E8, w)
  157.     zero = [0].pack ?l
  158.     mod.(0x1C5E3, zero)
  159.     mod.(0x1C5E8, zero)
  160.     mod.(0x1F477, h)
  161.     mod.(0x1F47C, w)
  162.     mod.(0x211FF, hh)
  163.     mod.(0x21204, ww)
  164.     mod.(0x21D7D, hhh[0])
  165.     mod.(0x21E01, www[0])
  166.     mod.(0x10DEA8, h)
  167.     mod.(0x10DEAD, w)
  168.     mod.(0x10DEDF, h)
  169.     mod.(0x10DEF0, w)
  170.     mod.(0x10DF14, h)
  171.     mod.(0x10DF18, w)
  172.     mod.(0x10DF48, h)
  173.     mod.(0x10DF4C, w)
  174.     mod.(0x10E6A7, w)
  175.     mod.(0x10E6C3, h)
  176.     mod.(0x10EEA9, w)
  177.     mod.(0x10EEB9, h)
  178.     th_large_screen_resize_screen(width, height)
  179.   end
  180. end
  181.  
  182. #===============================================================================
  183. # Esrever's code from
  184. # http://www.rpgmakervxace.net/topic/100-any-chance-of-higher-resolution-or-larger-sprite-support/page-2#entry7997
  185. #===============================================================================
  186. class Game_Map
  187.  
  188.   #--------------------------------------------------------------------------
  189.   # overwrite method: scroll_down
  190.   #--------------------------------------------------------------------------
  191.   def scroll_down(distance)
  192.     last_y = @display_y
  193.     if loop_vertical?
  194.       @display_y += distance
  195.       @display_y %= @map.height * 256
  196.       @parallax_y += distance
  197.     else
  198.       dh = Graphics.height > height * 32 ? height : screen_tile_y
  199.       @display_y = [@display_y + distance, height - dh].min
  200.       @parallax_y += @display_y - last_y
  201.     end
  202.     @fog_y += loop_vertical? ? distance : @display_y - last_y if @fog_y
  203.   end
  204.  
  205.   #--------------------------------------------------------------------------
  206.   # overwrite method: scroll_right
  207.   #--------------------------------------------------------------------------
  208.   def scroll_right(distance)
  209.     last_x = @display_x
  210.     if loop_horizontal?
  211.       @display_x += distance
  212.       @display_x %= @map.width * 256
  213.       @parallax_x += distance
  214.     else
  215.       dw = Graphics.width > width * 32 ? width : screen_tile_x
  216.       @display_x = [@display_x + distance, width - dw].min
  217.       @parallax_x += @display_x - last_x
  218.     end
  219.     @fog_x += loop_horizontal? ? distance : @display_x - last_x if @fog_x
  220.   end
  221.  
  222. end # Game_Map
  223.  
  224. #==============================================================================
  225. # ■ Spriteset_Map
  226. #==============================================================================
  227. class Spriteset_Map
  228.  
  229.   #--------------------------------------------------------------------------
  230.   # overwrite method: create_viewports
  231.   #--------------------------------------------------------------------------
  232.   def create_viewports
  233.     if Graphics.width > $game_map.width * 32 && !$game_map.loop_horizontal?
  234.       dx = (Graphics.width - $game_map.width * 32) / 2
  235.     else
  236.       dx = 0
  237.     end
  238.     dw = [Graphics.width, $game_map.width * 32].min
  239.     dw = Graphics.width if $game_map.loop_horizontal?
  240.     if Graphics.height > $game_map.height * 32 && !$game_map.loop_vertical?
  241.       dy = (Graphics.height - $game_map.height * 32) / 2
  242.     else
  243.       dy = 0
  244.     end
  245.     dh = [Graphics.height, $game_map.height * 32].min
  246.     dh = Graphics.height if $game_map.loop_vertical?
  247.     @viewport1 = Viewport.new(dx, dy, dw, dh)
  248.     @viewport2 = Viewport.new(dx, dy, dw, dh)
  249.     @viewport3 = Viewport.new(dx, dy, dw, dh)
  250.     @viewport2.z = 50
  251.     @viewport3.z = 100
  252.   end
  253.  
  254.   #--------------------------------------------------------------------------
  255.   # new method: update_viewport_sizes
  256.   #--------------------------------------------------------------------------
  257.   def update_viewport_sizes
  258.     if Graphics.width > $game_map.width * 32 && !$game_map.loop_horizontal?
  259.       dx = (Graphics.width - $game_map.width * 32) / 2
  260.     else
  261.       dx = 0
  262.     end
  263.     dw = [Graphics.width, $game_map.width * 32].min
  264.     dw = Graphics.width if $game_map.loop_horizontal?
  265.     if Graphics.height > $game_map.height * 32 && !$game_map.loop_vertical?
  266.       dy = (Graphics.height - $game_map.height * 32) / 2
  267.     else
  268.       dy = 0
  269.     end
  270.     dh = [Graphics.height, $game_map.height * 32].min
  271.     dh = Graphics.height if $game_map.loop_vertical?
  272.     rect = Rect.new(dx, dy, dw, dh)
  273.     for viewport in [@viewport1, @viewport2, @viewport3]
  274.       viewport.rect = rect
  275.     end
  276.   end
  277.  
  278. end # Spriteset_Map
  279.  
  280. #-------------------------------------------------------------------------------
  281. # FenixFyre's custom Plane, simply drawing a sprite. Needs to do something about
  282. # the y-axis
  283. #-------------------------------------------------------------------------------
  284. class Plane
  285.   attr_reader :ox, :oy
  286.  
  287.   alias :th_unlimited_resolution_initialize :initialize
  288.   def initialize(viewport = nil)
  289.     th_unlimited_resolution_initialize(viewport)
  290.     @sprite = Sprite.new(viewport)
  291.     @bitmap = nil
  292.     @ox = 0
  293.     @oy = 0
  294.   end
  295.  
  296.   def method_missing(symbol, *args)
  297.     @sprite.method(symbol).call(*args)
  298.   end
  299.  
  300.   def bitmap=(bitmap)
  301.     @bitmap = bitmap
  302.     refresh
  303.   end
  304.  
  305.   alias :th_unlimited_resolution_dispose :dispose
  306.   def dispose
  307.     th_unlimited_resolution_dispose
  308.     @sprite.dispose if @sprite
  309.     @sprite = nil
  310.   end
  311.  
  312.   def bitmap
  313.     @sprite.bitmap
  314.   end
  315.  
  316.   def ox=(ox)
  317.     w = @sprite.viewport != nil ? @sprite.viewport.rect.width : Graphics.width
  318.     @ox = ox % w
  319.     @sprite.ox = @ox
  320.   end
  321.  
  322.   def oy=(oy)
  323.     h = @sprite.viewport != nil ? @sprite.viewport.rect.height : Graphics.height
  324.     @oy = oy % h
  325.     @sprite.oy = @oy
  326.   end
  327.  
  328.   def blend_type=(blend_type)
  329.     @blend_type = blend_type
  330.     @sprite.blend_type = blend_type
  331.   end
  332.  
  333.   def opacity=(opacity)
  334.     @opacity = opacity
  335.     @sprite.opacity = opacity
  336.   end
  337.  
  338.   def z=(z)
  339.     @z = z
  340.     @sprite.z = z
  341.   end
  342.  
  343.   def tone=(tone)
  344.     @tone = tone
  345.     @sprite.tone = tone
  346.   end
  347.  
  348.   def visible=(visible)
  349.     @visible = visible
  350.     @sprite.visible = visible
  351.   end
  352.  
  353.   def refresh
  354.     return if @bitmap.nil?
  355.     w = @sprite.viewport != nil ? @sprite.viewport.rect.width : Graphics.width
  356.     h = @sprite.viewport != nil ? @sprite.viewport.rect.height : Graphics.height
  357.     if @sprite.bitmap != nil
  358.       @sprite.bitmap.dispose
  359.     end
  360.     @sprite.bitmap = Bitmap.new(w * 2, h * 2)
  361.        
  362.     max_x = (w*2) / @bitmap.width
  363.     max_y = (h*2) / @bitmap.height
  364.            
  365.     for x in 0..max_x
  366.       for y in 0..max_y
  367.         @sprite.bitmap.blt(x * @bitmap.width, y * @bitmap.height,
  368.          @bitmap, Rect.new(0, 0, @bitmap.width, @bitmap.height))
  369.       end
  370.     end
  371.  
  372.   end
  373. end
  374.  
  375. #==============================================================================
  376. # ■ Scene_Map
  377. #==============================================================================
  378. class Scene_Map < Scene_Base
  379.  
  380.   #--------------------------------------------------------------------------
  381.   # alias method: post_transfer
  382.   #--------------------------------------------------------------------------
  383.   alias scene_map_post_transfer_ace post_transfer
  384.   def post_transfer
  385.     @spriteset.update_viewport_sizes
  386.     scene_map_post_transfer_ace
  387.   end
  388.  
  389. end # Scene_Map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement