O TEMA DO FÓRUM ESTÁ EM MANUTENÇÃO. FEEDBACKS AQUI: ACESSAR

XAS Hero Edition 3.91 - Ally System 1.56 (Scripts Causando Lag)

Iniciado por Shyro Hazuke, 18/07/2016 às 17:30

18/07/2016 às 17:30 Última edição: 18/07/2016 às 17:41 por Shyro Hazuke
Então pessoal, gostaria de uma ajuda com os scripts do sistema aliado para o XAS 3.91 RMXP, o problema é o seguinte, são 4 scripts para o funcionamento desse sistema, e eles causam lag video em meu jogo, se eu tiro os scripts, funciona normalmente, agora se eu coloco, o jogo abre da para jogar normal, porém cai muito os frames, fica um lag absurdo, e o lag causa quando eu chego perto de algum evento, ou um mapa com bastante eventos, é obvio que a causa do lag é os scripts do sistema, mais eu não sei o porque causa isso.

Preciso muito desse sistema, pois meu jogo depende dele, acredito eu que esse sistema é o mais importante para que eu venha desenvolver o jogo.

Eu uso o ABS XAS hero edition, na versão 3.91
E o sistema de aliado está na versão 1.56 (acredito que seja a ultima lançada até o momento)

Segue os scripts para vocês darem uma olhadinha:

DRG - Core Engine (Esse não é o causador do lag, porque quando eu removo os outros 3 scripts e deixo só esse, o lag sai)
Spoiler
[code]
#==============================================================================
# ** Drago - Core Engine
# Version : 1.49
# Contact : littledrago.blogspot.com / forum.chaos-project.com
#==============================================================================
($imported ||= {})[:drg_core_engine] = 1.49
# =============================================================================
# NOTE:
# -----------------------------------------------------------------------------
# This is a devtool for me to make me easier for scripting
# If you want to use this, put above all custom script & below Scene_Debug
#
# =============================================================================
# DOCUMENTATION:
# -----------------------------------------------------------------------------
=begin
  Version History
 
  1.42 -
  ? Fixed Graphics.fullscreen?
 
  1.40 -
  ? Modified Game_Map#load_event
 
  1.39 -
  ? Fixed glitch at Bitmap#draw_icon
  ? Added Fiber class
  ? Added Game_Map#load_event
  ? Added Game_Map#call_event
 
  1.36 -
  ? Added Color class library
 
  1.34 -
  ? Added Module#define_third_method(sym = nil, _alias = nil,
                    prevent_stack = true, *a, &block)
  ? Added Bitmap#blur
 
  1.31 -
  ? Added Module#attr_sec_reader(symbol, default=0)
  ? Added Module#attr_sec_accessor(symbol, *a, &block)
  ? Added Module#alias_sec_method(sym = nil, *a, &block)
  ? Added Module#define_sec_method(sym = nil, *a, &block)
 
  1.29 -
  ? Added Array#have_all?(array)
  ? Added Array#have_any?(array)
 
  1.27 -
  ? Added Added Graphics.brightness
  ? Added Graphics.wait(frames = 10)
  ? Added Graphics.fadein(frames = 10)
  ? Added Graphics.fadeout(frames = 10)
  ? Added Bitmap#invert
  ? Added Bitmap#invert!
  ? Added Bitmap#brighten(amount = 10)
  ? Added Bitmap#brighten!(amount = 10)
  ? Added Bitmap#darken(amount = 10)
  ? Added Bitmap#darken!(amount = 10)
  ? Added Bitmap#grayscale
  ? Added Bitmap#grayscale!
  ? Added Bitmap#pixelate(size = 10)
  ? Added Bitmap#pixelate!(size = 10)
  ? Added Bitmap#frost(noise = 10)
  ? Added Bitmap#frost!(noise = 10)
 
  1.24 -
  ? Added Viewport#x
  ? Added Viewport#y
  ? Added Viewport#width
  ? Added Viewport#height
  ? Added Viewport#disposed?
 
  1.23 -
  ? Added Window_Base#draw_text (same as Bitmap#draw_text)
  ? Added Window_Base#draw_icon
  ? Added Window_Base#draw_battler
  ? Added Window_Base#draw_picture
 
  1.22 -
  ? Added Game_Map#load_map_data
  ? Added Game_Map#load_event
  ? Rename Array#product => Array#num_times (because of conflict with RGSS3)
 
  1.21 -
  ? Fixed Glitch at Bitmap#crop
 
  1.20 -
  ? Fixed Script Hanging Error at Bitmap#export
 
  1.19 -
  ? Added some of RMXP old method - Game_System#play_bgm
  ? Added some of RMXP old method - Game_System#play_bgs
  ? Added some of RMXP old method - Game_System#play_me
  ? Added some of RMXP old method - Game_System#play_se
 
  1.18 -
  ? Fixing Backtrace at Array#method_missing
 
  1.17 -
  ? Added Bitmap#flip_vertical
  ? Added Bitmap#flip_vertical!
  ? Added Bitmap#flip_horizontal
  ? Added Bitmap#flip_horizontal!
 
  1.16 -
  ? Added Bitmap#export
 
  1.15 -
  ? Added Game_Characters#character_above?
  ? Added Game_Characters#character_below?
  ? Added Game_Characters#character_right?
  ? Added Game_Characters#character_left?
 
  1.11 -
  ? Fixing Bug at changing screen size
 
  1.10 -
  ? Added Graphics.scale_screen(width, height)
 
  1.00 -
  ? Original Release

# -----------------------------------------------------------------------------
# Below is the available command in this script
# -----------------------------------------------------------------------------
# * Graphics
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
  This command is not recommended to used in RMXP
 
  Graphics.scale_screen(width,height)
  - Resize the screen and stretched it (if not RMXP) into new resolution
 
  Graphics.fill_monitor
  - Maximize the screen and stretched it (if not RMXP) to fill the monitor
 
  Graphics.control_screen_size(enable = true)
  - Enable or disable screen size control by mouse.
    Resized screen will be stretched (if not RMXP)
# -----------------------------------------------------------------------------

  Graphics.width        - Returns screen width
  Graphics.height       - Returns screen height
  Graphics.fullscreen?  - Returns true if Game in fullscreen mode, else false
  Graphics.fullscreen   - Switch to fullscreen mode
  Graphics.window       - Switch to windowed mode
  Graphics.toggle       - Switch between fullscreen mode and windowed mode
  Graphics.wait(frame)    - Wait for frame
  Graphics.wait_for_input - Wait until input is pressed
  Graphics.fadein(frame)  - Fade in the screen
  Graphics.fadeout(frame) - Fade out the screen
  Graphics.snap_to_bitmap - Snap screen to a bitmap object
 
  Graphics.high_priority = true/false - Change process priority to high / normal
  Graphics.disable_alt_enter  - Disable input ALT+Enter (until game is closed)
 
# -----------------------------------------------------------------------------
# * Module
# -----------------------------------------------------------------------------
  Module#attr_sec_reader(symbol, default=0)
  - Create attr_reader with default value
     Example : attr_sec_reader :something, "Sprite.new"
     Equal : def something
               @something ||= Sprite.new
             end
             
  Module#attr_sec_accessor(symbol, *a, &block)
  - Create (sheer of) attr_accessor with default value
     Example : attr_sec_accessor :sprite1, :sprite2, :sprite3, "Sprite.new"
     Equal : attr_writer :sprite1, :sprite2, :sprite3
             attr_sec_reader :sprite1, "Sprite.new"
             attr_sec_reader :sprite2, "Sprite.new"
             attr_sec_reader :sprite3, "Sprite.new"
 
  Module#alias_sec_method(sym = nil, *a, &block)
  - Create alias only if alias name is not defined and target method is exist
     Example : alias_sec_method :some_method, :target_method
     Equal : if method_defined?(:target) && !method_defined?(:something)
               alias_method :something, :target
             end
             
  Module#define_sec_method(sym = nil, *a, &block)
  - Define method only if the method is not defined
     Example : define_sec_method(:some_method) { |*a| block }
     Equal : unless method_defined?(:some_method)
               def some_method(*a)
                 block
               end
             end
 
# -----------------------------------------------------------------------------
# * Array
# -----------------------------------------------------------------------------
  Array Method Distributor
  - Distribute unexisted method in array into each variable
  (will work only if the method isn't exist in Array)
    Example : [Graphics,Input].update
                # equal => Graphics.update ; Input.update 
              [@string1,@string2,@integer1,@sprite].dispose
                # equal => @sprite.dispose
                # (all variable without dispose method is ignored)
              [@string1,@string2,@integer1].dispose
                # Throws NoMethodError if all method didn't have dispose method
 
  Array#random_each / Array#random_each_with_index
    Example : a = [1,2,3,4,5,6,7]
              a.random_each {|i| puts i} # 4,5,3,2,7,1,6
             
  Array#sum
  Array#num_times
  Array#average
    Example : [1,2,3,4].sum         # 10  (1+2+3+4)
              [1,2,3,4].average     # 2.5 (10 / 4)
              [1,2,3,4].num_times   # 24  (1*2*3*4)
             
  Array#shuffle / Array#shuffle! 
    Example : [1,2,3,4].shuffle     # [3,2,4,1] 
   
  Array#random / Array#random!
    Example : [1,2,3,4].random      # 3 
 
  Array#switch=(true/false)
  Array#switch_reverse
  - Turn on / off switches all variable in the array
    (will ignored if variable not integer or not an array)
    Example : [1,2,[3,2,'A'],5].switch = true
                # equal => $game_switches[1] = true
                           $game_switches[2] = true
                           $game_self_switches[[3,2,'A']] = true
                           $game_switches[5] = true
                           
  Array#variable(value = nil, method = "=")   
  - Change all variable value in the array (ignored if variable not integer)
    Example : [1,2,5].variable(10)
                # equal => $game_variables[1] = 10
                           $game_variables[2] = 10
                           $game_variables[5] = 10
    Example : [1,2,5].variable(10, "+=")
                # equal => $game_variables[1] += 10
                           $game_variables[2] += 10
                           $game_variables[5] += 10
                           
  Array#have_all?(array)
  - returns true if contains all elements of the array               
  Array#have_any?(array)
  - returns true if contains any elements of the array   
# -----------------------------------------------------------------------------
# * Sprite
# -----------------------------------------------------------------------------
  Sprite#clone
  Sprite#dup
  - Clone sprite without "can't clone sprite error"
    Example : a = Sprite.new
              b = a.clone
              a.dispose
              print a.disposed? # true
              print b.disposed? # false
             
# -----------------------------------------------------------------------------
# * Spriteset_Map
# -----------------------------------------------------------------------------
  Spriteset_Map#sprite_player
  - returns sprite player at @character_sprites in Spriteset_Map
 
  Spriteset_Map#find_character(character)
  - returns character sprite at @character_sprites in Spriteset_Map
 
# -----------------------------------------------------------------------------
# * Game Battler
# -----------------------------------------------------------------------------
  Game_Battler#hp_percent(integer = false, float_points = 2)
  Game_Battler#sp_percent(integer = false, float_points = 2)
  Example : $game_actors[1].hp_percent
                   # returns 0 - 100 based on percentage hp
                   
# -----------------------------------------------------------------------------
# * Bitmap
# -----------------------------------------------------------------------------
  Bitmap#export(filename)
  - exporting bitmap into a file (only support bmp and png)
  Example : bitmap = Bitmap.new(50,20)
            bitmap.export('empty.png')
           
  Bitmap#flip_vertical
  Bitmap#flip_vertical!
  Bitmap#flip_horizontal
  Bitmap#flip_horizontal!
  - flip the bitmap vertically or horizontally (using ! will modify self)
  Example : bitmap = Bitmap.new(50,20)
            bitmap.flip_vertical!
       
  Additional Bitmap Effects
  Note : calling this method is process consuming, use with caution
    Bitmap#invert
    Bitmap#invert!
    Bitmap#brighten(amount = 10)
    Bitmap#brighten!(amount = 10)
    Bitmap#darken(amount = 10)
    Bitmap#darken!(amount = 10)
    Bitmap#grayscale
    Bitmap#grayscale!
    Bitmap#pixelate(size = 10)
    Bitmap#pixelate!(size = 10)
    Bitmap#frost(noise = 10)
    Bitmap#frost!(noise = 10)
# -----------------------------------------------------------------------------
# * Color
# -----------------------------------------------------------------------------
  Color RGB value shortcut
  List :
    Color.red
    Color.white
    Color.black
    Color.green
    Color.blue
    Color.white
    Color.black
    Color.yellow
    Color.magenta
    Color.cyan
    Color.purple
    Color.gray
    Color.lightgray
    Color.darkgray
    Color.pink
    Color.orange
    Color.brown
    Color.golden
   
  Color Hex
  - You can use hex value as method in color class (not case sensitive)
  Example : Color.xffffff, Color.x04dacf, etc
 
 
# -----------------------------------------------------------------------------
# * Game_Map
# -----------------------------------------------------------------------------
 
  Game_Map#load_event(mapid, eventid, x, y, page_id)
  Game_Map#load_event(mapid, eventid, x, y)
  Game_Map#load_event(eventid, x, y)   # map_id will be assumed as current map
  - Duplicate an event from another map to current map at position (x, y)
 
  Game_Map#call_event(mapid, eventid, page_id)
  Game_Map#call_event(mapid, eventid)  # page_id will be assumed as -1
  Game_Map#call_event(eventid)         # map_id will be assumed as current map
  - Call an event from another map to current map
      Note that page_id is start from 1, not 0
      If you're using RMVX or RMVXA, setting page_id to -1 will bring you to
      the page with met condition.
 
# -----------------------------------------------------------------------------
# * End Documentation
# -----------------------------------------------------------------------------
=end
# =============================================================================

module LiTTleDRAgo
  #-------------------------------------------------------------------------
  # * Constant
  #-------------------------------------------------------------------------
  VX           = defined?(Window_ActorCommand)
  VXA          = defined?(Window_BattleActor)
  XP           = !VX
  RGSS1        = defined?(Hangup)
  RGSS2        = RUBY_VERSION == '1.8.1' && !RGSS1
  RGSS3        = RUBY_VERSION == '1.9.2'
  APPPATHDRAGO = "#{ENV['APPDATA']}/Drago/"
end

#==============================================================================
# ** Module     
#------------------------------------------------------------------------------

#==============================================================================

class Module
  #-------------------------------------------------------------------------
  # * New method: attr_sec_reader (Attr Secondary Reader)
  #-------------------------------------------------------------------------
  unless method_defined?(:attr_sec_reader)
    def attr_sec_reader(*sym)
      if (1..2) === sym.size
        module_eval("define_method(:#{sym[0]}) { @#{sym[0]} ||= #{sym[1]||0}}")
      elsif sym.size > 2
        (default = sym.pop) && sym.each {|s| attr_sec_reader(s,default)}
      end
    end
  end
  #-------------------------------------------------------------------------
  # * New method: attr_sec_accessor (Attr Secondary Accessor)
  #-------------------------------------------------------------------------
  unless method_defined?(:attr_sec_accessor)
    def attr_sec_accessor(sym = nil, *args)
      (args.size > 0) | sym.nil? || args.push(0)
      (default = args.pop) && (b = [sym].concat(args).compact)
      (b).each {|a| (attr_writer(a) || 0) && attr_sec_reader(a,default)}
    end
  end
  #-------------------------------------------------------------------------
  # * New method: alias_sec_method (Alias Secondary Method)
  #   Note : This method will create alias only if alias name is not defined
  #          and target alias is exist
  #-------------------------------------------------------------------------
  unless method_defined?(:alias_sec_method)
    private
    def alias_sec_method(sym = nil, *args)
      (args.size > 0) | sym.nil? || args.clear
      (t = args.pop) && (b = [sym].concat(args).compact).each do |a|
        c = t == :initialize ? true : method_defined?(t)
        method_defined?(a) || (c && alias_method(a, t))
      end
    end
  end
  #-------------------------------------------------------------------------
  # * New method: redirect_method
  #-------------------------------------------------------------------------
  unless method_defined?(:redirect_method)
    private
    def redirect_method(sym = nil, *args, &block)
      (args.size > 0) | sym.nil? || args.clear
      (t = args.pop) && (b = [sym].concat(args).compact).each do |a|
        meth = "def #{a}[*args] #{t}(*args) end"
        meth.gsub!(/(['")}\](\d+)])\(\*args\)/i)  {    $1     }#'
        meth.gsub!(/\[\*args\]/i)                 { '(*args)' }
        method_defined?(a) || module_eval(meth)
      end
    end
  end
  #-------------------------------------------------------------------------
  # * New method: define_sec_method
  #   Note : This method will not defining method if method name already
  #          exist
  #-------------------------------------------------------------------------
  unless method_defined?(:define_sec_method)
    private
    def define_sec_method(sym = nil, *args, &block)
      sym && (method_defined?(s = sym.to_sym) || define_method(s,*args,&block))
    end
    private
    alias_method :define_inexist_method, :define_sec_method
  end
  #-------------------------------------------------------------------------
  # * New method: define_third_method
  #   Note : After aliasing, define a method
  #-------------------------------------------------------------------------
  unless method_defined?(:define_third_method)
    private
    def define_third_method(sym = nil, _alias = nil,
                    prevent_stack = true, *args, &block)
      unless sym.nil? || _alias.nil?
        stack = (prevent_stack && method_defined?(_alias.to_sym))
        stack || alias_method(_alias.to_sym, sym.to_sym)
        define_method(sym.to_sym,*args,&block)
      end
    end
    private
    alias_method :define_after_alias_method, :define_third_method
  end
end

#==============================================================================
# ** CoreDLL
#------------------------------------------------------------------------------

#==============================================================================
module CoreDLL
  #-------------------------------------------------------------------------
  # * Constant
  #-------------------------------------------------------------------------
  DLL_USED = ['kernel32','msvcrt','user32','gdi32']
  SCENEVXA = "SceneManager.send(:instance_variable_set,:@scene,args.at(0))"
  #-------------------------------------------------------------------------
  # * Public Instance Variables
  #-------------------------------------------------------------------------
  attr_sec_reader :rtlmemory_pi,  "winapi(0,'RtlMoveMemory','pii','i')"
  attr_sec_reader :rtlmemory_ip,  "winapi(0,'RtlMoveMemory','ipi','i')"
  attr_sec_reader :setpriority,   "winapi(0,'SetPriorityClass','pi','i')"
  attr_sec_reader :getprocesstime,"winapi(0,'GetProcessTimes','ipppp','i')"
  attr_sec_reader :malloc,        "winapi(1,'malloc','i','i')"
  attr_sec_reader :free,          "winapi(1,'free','i','v')" 
  attr_sec_reader :getdc,         "winapi(2,'GetDC','i','i')"
  attr_sec_reader :releasedc,     "winapi(2,'ReleaseDC','ii','i')"
  attr_sec_reader :reghotkey,     "winapi(2,'RegisterHotKey', 'liii', 'i')"
  attr_sec_reader :sendinput,     "winapi(2,'SendInput','ipi','i')"
  attr_sec_reader :setwindowlong, "winapi(2, 'SetWindowLong','lll','l')"
  attr_sec_reader :bitblt,        "winapi(3,'BitBlt','iiiiiiiii','i')"
  attr_sec_reader :ccdc,          "winapi(3,'CreateCompatibleDC','i','i')"
  attr_sec_reader :ccbitmap,     "winapi(3,'CreateCompatibleBitmap','iii','i')"
  attr_sec_reader :deleteobject,  "winapi(3,'DeleteObject','i','i')"
  attr_sec_reader :getbitmapbits, "winapi(3,'GetBitmapBits','llp','l')"
  attr_sec_reader :getdibits,     "winapi(3,'GetDIBits','iiiiipi','i')"
  attr_sec_reader :setdibits,     "winapi(3,'SetDIBits','iiiiipi','i')"
  attr_sec_reader :selectobject,  "winapi(3,'SelectObject','ii','i')"
  attr_sec_reader :getpixel,      "winapi(3,'GetPixel','iii','i')"
  attr_sec_reader :setpixel,      "winapi(3,'SetPixel','liil','l')"
  attr_sec_reader :disabled_key,  "Array.new"
  attr_sec_reader :high_priority, 'false'
  #-------------------------------------------------------------------------
  # * Define Secondary Listing
  #-------------------------------------------------------------------------
  define_sec_method(:disable_alt_enter) { disable_keys(0x0D) }
  define_sec_method(:fullscreen?) { systemmetrix.at(0) == Graphics.width }
  define_sec_method(:fullscreen)  { toggle unless self.fullscreen? }
  define_sec_method(:window)      {   toggle if self.fullscreen?   }
  #-------------------------------------------------------------------------
  # * Redirect Listing
  #-------------------------------------------------------------------------
  redirect_method :cache, LiTTleDRAgo::VX  ? '(Cache)' : '(RPG::Cache)'
  redirect_method :scene, LiTTleDRAgo::VXA ? '(SceneManager.scene)':'($scene)'
  redirect_method :scene=,LiTTleDRAgo::VXA ? SCENEVXA : '($scene = args[0])'
  #-------------------------------------------------------------------------
  # * Enable change window size via mouse (border required)
  #   Screen will not resized if RMXP
  #-------------------------------------------------------------------------
  def control_screen_size(enable = true)
    hid = @hide_border ? 0x14000000 : 0x14CA0000
    set = enable ? (0x10C70000|0x00080000) : hid
    self.setwindowlong.call(self.hwnd,-16, set)
  end
  #-------------------------------------------------------------------------
  # * Hide window border
  #   Screen size can't be controlled via mouse
  #-------------------------------------------------------------------------
  def hide_borders
    (@hide_border = true) && control_screen_size(false)
  end
  #-------------------------------------------------------------------------
  # * Show window border
  #   Screen size can't be controlled via mouse
  #-------------------------------------------------------------------------
  def show_borders
    (@hide_border = false) || control_screen_size(false)
  end
  #-------------------------------------------------------------------------
  # * Disable Key
  #-------------------------------------------------------------------------
  def disable_keys(*keys)
    keys.each do |key|
      disabled_key.include?(key) || disabled_key.push(key)
      self.reghotkey.call(self.hwnd, 1, 0x0001, key)
    end
  end
  #-------------------------------------------------------------------------
  # * Resize the screen (scaled)
  #   Screen will not resized if RMXP
  #-------------------------------------------------------------------------
  def scale_screen(width, height)
    res = self.systemmetrix
    width  += (res.at(5) + res.at(45)) * 2
    height += (res.at(6) + res.at(45)) * 2 + res.at(4)
    x = [(res.at(0) - width) / 2, 0].max
    y = [(res.at(1) - height) / 2, 0].max
    self.setwindowpos(self.hwnd,0,x,y,width,height,0)
  end
  #-------------------------------------------------------------------------
  # * Scale the game.exe to fill the monitor
  #   Screen will not resized if RMXP
  #-------------------------------------------------------------------------
  def fill_monitor
    (res = systemmetrix) && setwindowpos(hwnd,0,0,0,res.at(0),res.at(1),0)
  end
  #-------------------------------------------------------------------------
  # * systemmetrix
  #-------------------------------------------------------------------------
  def systemmetrix
    @systemmetrix ||= winapi(2, 'GetSystemMetrics', %w(i), 'i')
    (res = []) && [0,1,4,5,6,45].each { |i| res = @systemmetrix.call(i) }
    res
  end
  #-------------------------------------------------------------------------
  # * setwindowpos
  #-------------------------------------------------------------------------
  def setwindowpos(hwnd = self.hwnd,at = 0,x = 0,y = 0,
      width = 640, height = 480, ni = 0)
    @setwindowpos ||= winapi(2, 'SetWindowPos', 'liiiiip','i')
    @setwindowpos.call(hwnd, at, x, y, width, height, ni)
  end
  #-------------------------------------------------------------------------
  # * Toggle between fullscreen and windowed
  #-------------------------------------------------------------------------
  def toggle
    @keybd ||= winapi(2, 'keybd_event', %w(i i l l), 'v')
    [@keybd.call(0xA4, 0, 0, 0), @keybd.call(13, 0, 0, 0)  ]
    [@keybd.call(13, 0, 2, 0),   @keybd.call(0xA4, 0, 2, 0)]
  end
  #-------------------------------------------------------------------------
  # * Show FPS
  #-------------------------------------------------------------------------
  def show_fps
    @show_fps ||= winapi(2, 'keybd_event', %w(l l l l), '')
    @show_fps.call(0x71,0,0,0)
    sleep(0.1)
    @show_fps.call(0x71,0,2,0)
  end
  #-------------------------------------------------------------------------
  # * Get the Game Window's width and height
  #-------------------------------------------------------------------------
  def client_size
    rect = [0, 0, 0, 0].pack('l4')
    @window_c_rect ||= winapi(2, 'GetClientRect', %w(l p), 'i')
    @window_c_rect.call(self.hwnd, rect)
    right, bottom = rect.unpack('l4')[2..3]
    return right, bottom
  end 
  #-------------------------------------------------------------------------
  # * Get the game window handle (specific to game)
  #-------------------------------------------------------------------------
  def hwnd
    @window_find ||= winapi(2, 'FindWindowEx', %w(l l p p), 'i')
    @game_window ||= @window_find.call(0,0,"RGSS Player",0)
    return @game_window
  end 
  #-------------------------------------------------------------------------
  # * always_on_top  (cannot be undone)
  #-------------------------------------------------------------------------
  def always_on_top
    res = self.systemmetrix
    width  = Graphics.width  + (res.at(5) + res.at(45)) * 2
    height = Graphics.height + (res.at(6) + res.at(45)) * 2 + res.at(4)
    x = [(res.at(0) - width) / 2, 0].max
    y = [(res.at(1) - height) / 2, 0].max
    self.setwindowpos(self.hwnd,-1,x,y,width,height,0x0200)
  end
  #-------------------------------------------------------------------------
  # * Get the value of game.ini
  #-------------------------------------------------------------------------
  def read_ini(field, key, ini = 'Game.ini')
    @gpps ||= winapi(0, 'GetPrivateProfileString', 'pppplp', 'l')
    @gpps.call(field,key,"",result="\0"*256,256,".//#{ini}") rescue return ""
    return result.delete!("\0")
  end
  #-------------------------------------------------------------------------
  # * High Priority (true/false)
  #-------------------------------------------------------------------------
  def high_priority=(value)
    @high_priority = value && true
    setpriority.call(-1, @high_priority ? 0x00000080 : 0x00000020)
  end
  #--------------------------------------------------------------------------
  # * snap_to_bitmap
  #--------------------------------------------------------------------------
  def snap_to_bitmap
    width, height = client_size.at(0), client_size.at(1)
    bitmap        = Bitmap.new(width, height)
    dc            = getdc.call(hwnd)
    address       = bitmap.address
    info          = [40,width,height,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
    hDC           = ccdc.call(dc)
    hBM           = ccbitmap.call(dc, width, height)
    deleteobject.call(selectobject.call(hDC, hBM))
    setdibits.call(hDC, hBM, 0, height, address, info, 0)
    bitblt.call(hDC, 0, 0, width, height, dc, 0, 0, 0xCC0020)
    getdibits.call(hDC, hBM, 0, height, address, info, 0)
    deleteobject.call(hBM)
    deleteobject.call(hDC)
    bitmap
  end                           
  #-------------------------------------------------------------------------
  # * Execute Win32API
  #-------------------------------------------------------------------------
  def winapi(*args)
    args[0] = (i = args.at(0)).is_a?(Integer) ? DLL_USED : i
    Win32API.new(*args)
  end
end                         
LiTTleDRAgo.extend(CoreDLL)

#==============================================================================
# ** RPG
#------------------------------------------------------------------------------

#==============================================================================
module RPG
  #--------------------------------------------------------------------------
  # ? Constant
  #--------------------------------------------------------------------------
  VX, VXA  = LiTTleDRAgo::VX, LiTTleDRAgo::VXA
  #============================================================================
  # ** System
  #----------------------------------------------------------------------------
  #
  #============================================================================
  class System
    #========================================================================
    # ** Words
    #------------------------------------------------------------------------
    #
    #========================================================================
    class Words     
      #----------------------------------------------------------------------
      # ? New Methods
      #----------------------------------------------------------------------
      attr_sec_accessor :weapon1,   VX && !VXA ? 'Vocab.weapon1' : "'Weapon 1'"
      attr_sec_accessor :weapon2,   VX && !VXA ? 'Vocab.weapon2' : "'Weapon 2'"
      attr_sec_accessor :status,    VX ? 'Vocab.status'          : "'Status'  "
      attr_sec_accessor :save,      VX ? 'Vocab.save'            : "'Save'    "
      attr_sec_accessor :game_end,  VX ? 'Vocab.game_end'        : "'Game End'"
      attr_sec_accessor :fight,     VX ? 'Vocab.fight'           : "'Fight'   "
      attr_sec_accessor :escape,    VX ? 'Vocab.escape'          : "'Escape'  "
      attr_sec_accessor :new_game,  VX ? 'Vocab.new_game'        : "'New Game'"
      attr_sec_accessor :continue,  VX ? 'Vocab.continue'        : "'Continue'"
      attr_sec_accessor :shutdown,  VX ? 'Vocab.shutdown'        : "'Shutdown'"
      attr_sec_accessor :to_title,  VX ? 'Vocab.to_title'        : "'To Title'"
      attr_sec_accessor :cancel,    VX ? 'Vocab.cancel'          : "'Cancel'  "
      attr_sec_accessor :params,    !VXA ? !VX ?
                                    '[hp,sp,str,dex,agi,int]' :         # XP
                                    '[hp,sp,atk,pdef,int,agi]' :        # VX
                                    '[hp,sp,atk,pdef,int,mdef,agi,luk]' # VXA
      #----------------------------------------------------------------------
      # ? Redirect Listings
      #----------------------------------------------------------------------
      redirect_method :gold,   (VXA ? 'Vocab.currency_unit' : 'Vocab.gold')
      redirect_method :hp,     'Vocab.hp'
      redirect_method :sp,     'Vocab.mp'
      redirect_method :str,    'String.new()'
      redirect_method :dex,    'String.new()'
      redirect_method :luk,    (VXA ? 'Vocab.param(7)' : 'String.new()')
      redirect_method :agi,    (VXA ? 'Vocab.param(6)' : 'Vocab.agi')
      redirect_method :int,    (VXA ? 'Vocab.param(4)' : 'Vocab.spi')
      redirect_method :atk,    (VXA ? 'Vocab.param(2)' : 'Vocab.atk')
      redirect_method :pdef,   (VXA ? 'Vocab.param(3)' : 'Vocab.def')
      redirect_method :mdef,   (VXA ? 'Vocab.param(5)' : 'String.new()')
      redirect_method :weapon, (VXA ? 'Vocab.etype(0)' : 'Vocab.weapon')
      redirect_method :armor1, (VXA ? 'Vocab.etype(1)' : 'Vocab.armor1')
      redirect_method :armor2, (VXA ? 'Vocab.etype(2)' : 'Vocab.armor2')
      redirect_method :armor3, (VXA ? 'Vocab.etype(3)' : 'Vocab.armor3')
      redirect_method :armor4, (VXA ? 'Vocab.etype(4)' : 'Vocab.armor4')
      redirect_method :attack, 'Vocab.attack'
      redirect_method :skill,  'Vocab.skill'
      redirect_method :guard,  'Vocab.guard'
      redirect_method :item,   'Vocab.item'
      redirect_method :equip,  'Vocab.equip'
    end
    #----------------------------------------------------------------------
    # ? Class Variables
    #----------------------------------------------------------------------
    if VX
      #------------------------------------------------------------------------
      # ? Public Instance Variables
      #------------------------------------------------------------------------
      attr_accessor :magic_number,      :windowskin_name, :gameover_name
      attr_accessor :battle_transition, :battleback_name, :title_name
      #------------------------------------------------------------------------
      # ? Redefined Methods
      #------------------------------------------------------------------------
      redirect_method :sounds,            "$data_system.sounds"
      redirect_method :cursor_se,         "sounds[0]"
      redirect_method :decision_se,       "sounds[1]"
      redirect_method :cancel_se,         "sounds[2]"
      redirect_method :buzzer_se,         "sounds[3]"
      redirect_method :equip_se,          "sounds[4]"
      redirect_method :save_se,           "sounds[5]"
      redirect_method :load_se,           "sounds[6]"
      redirect_method :battle_start_se,   "sounds[7]"
      redirect_method :escape_se,         "sounds[8]"
      if VXA
        redirect_method :shop_se,           "sounds[21]"
        redirect_method :actor_collapse_se, "sounds[15]"
      else
        redirect_method :shop_se,           "sounds[17]"
        redirect_method :actor_collapse_se, "sounds[13]"
      end
      redirect_method :enemy_collapse_se, "sounds[11]"
      redirect_method :words,             "@words ||= RPG::System::Words.new()"
      #------------------------------------------------------------------------
      # ? Aliased Methods
      #------------------------------------------------------------------------
      alias_sec_method :battleback_name, :battleback1_name
      alias_sec_method :title_name,      :title1_name     
    end
  end
end
#==============================================================================
# ** Sound
#------------------------------------------------------------------------------
#  This module plays sound effects. It obtains sound effects specified in the
# database from the global variable $data_system, and plays them.
#==============================================================================
module Sound
  #-------------------------------------------------------------------------
  # * Self
  #-------------------------------------------------------------------------
  class << self
    #------------------------------------------------------------------------
    # ? New Method :se_play
    #------------------------------------------------------------------------
    unless method_defined?(:se_play)
      def se_play(type)
        system = ($game_system ||= Game_System.new)
        case type
        when :cursor         then system.se_play($data_system.cursor_se)
        when :decision       then system.se_play($data_system.decision_se)
        when :cancel         then system.se_play($data_system.cancel_se)
        when :buzzer         then system.se_play($data_system.buzzer_se)
        when :shop           then system.se_play($data_system.shop_se)
        when :equip          then system.se_play($data_system.equip_se)
        when :save           then system.se_play($data_system.save_se)
        when :load           then system.se_play($data_system.load_se)
        when :battle_start   then system.se_play($data_system.battle_start_se)
        when :escape         then system.se_play($data_system.escape_se)
        when :actor_collapse then system.se_play($data_system.actor_collapse_se)
        when :enemy_collapse then system.se_play($data_system.enemy_collapse_se)
        end
      end
    end
    #--------------------------------------------------------------------------
    # * Redefined Method
    #--------------------------------------------------------------------------
    define_sec_method(:play_cursor)         { se_play(:cursor)         }
    define_sec_method(:play_decision)       { se_play(:decision)       }
    define_sec_method(:play_cancel)         { se_play(:cancel)         }
    define_sec_method(:play_buzzer)         { se_play(:buzzer)         }
    define_sec_method(:play_equip)          { se_play(:equip)          }
    define_sec_method(:play_save)           { se_play(:save)           }
    define_sec_method(:play_load)           { se_play(:load)           }
    define_sec_method(:play_battle_start)   { se_play(:battle_start)   }
    define_sec_method(:play_escape)         { se_play(:escape)         }
    define_sec_method(:play_enemy_collapse) { se_play(:enemy_collapse) }
    define_sec_method(:play_actor_collapse) { se_play(:actor_collapse) }
    define_sec_method(:play_shop)           { se_play(:shop)           }
    #--------------------------------------------------------------------------
    # * Alias Listing
    #--------------------------------------------------------------------------
    alias_sec_method :play_ok, :play_decision
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles data surrounding the system. Backround music, etc.
#  is managed here as well. Refer to "$game_system" for the instance of
#  this class.
#==============================================================================
class Game_System
  #--------------------------------------------------------------------------
  # * Constant
  #--------------------------------------------------------------------------
  USE_VOLUME_SOUND = false
  VX               = LiTTleDRAgo::VX && !LiTTleDRAgo::VXA
  #--------------------------------------------------------------------------
  # * Public Instance Variable
  #--------------------------------------------------------------------------
  attr_sec_accessor :bgm_volume, :bgs_volume, :me_volume, :se_volume, 100
  attr_sec_accessor :bgm_pitch,  :bgs_pitch,  :me_pitch,  :se_pitch , 100
  #--------------------------------------------------------------------------
  # * Redefined method: bgm_play, bgs_play, me_play, se_play, playing_bgm
  #                     bgm_memorize, bgm_restore
  #--------------------------------------------------------------------------
  rewrite = method_defined?(:bgm_play) && !USE_VOLUME_SOUND
  rewrite || define_method(:bgm_play){ |*a| drg_bgm_play(*a) }
  rewrite || define_method(:bgs_play){ |*a| drg_bgs_play(*a) }
  rewrite || define_method(:me_play) { |*a| drg_me_play(*a)  }
  rewrite || define_method(:se_play) { |*a| drg_se_play(*a)  }
  VX && define_sec_method(:bgm_memorize) { @memorized_bgm = @playing_bgm }
  VX && define_sec_method(:bgm_restore)  { bgm_play(@memorized_bgm)     }
  #--------------------------------------------------------------------------
  # * Redirect Listing
  #--------------------------------------------------------------------------
  redirect_method :bgm_stop,     'Audio.bgm_stop'
  redirect_method :bgs_stop,     'Audio.bgs_stop'
  redirect_method :se_stop,      'Audio.se_stop'
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias_sec_method :bgm_memorize, :save_bgm
  alias_sec_method :bgm_restore,  :replay_bgm
  alias_sec_method :save_bgm,     :bgm_memorize
  alias_sec_method :replay_bgm,   :bgm_restore
  #--------------------------------------------------------------------------
  # * New method: drg_bgm_play
  #--------------------------------------------------------------------------
  unless method_defined?(:drg_bgm_play)
    def drg_bgm_play(bgm,*_a)
      @playing_bgm = bgm
      if bgm.is_a?(RPG::AudioFile) and bgm.name != ""
        a = ["Audio/BGM/" + bgm.name, bgm.volume * bgm_volume.to_f / 100,
                bgm.pitch * bgm_pitch.to_f / 100]
        a << _a.at(0) if _a.at(0) && LiTTleDRAgo::RGSS3
        Audio.bgm_play(*a)
      elsif bgm.is_a?(String) && bgm != ''
        a = ["Audio/BGM/" + bgm, bgm_volume, bgm_pitch]
        a << _a.at(0) if _a.at(0) && LiTTleDRAgo::RGSS3
        Audio.bgm_play(*a)
      else
        Audio.bgm_stop
      end
      Graphics.frame_reset
    end
  end
  #--------------------------------------------------------------------------
  # * New method: drg_bgs_play
  #--------------------------------------------------------------------------
  unless method_defined?(:drg_bgs_play)
    def drg_bgs_play(bgs,*_a)
      @playing_bgs = bgs
      if bgs.is_a?(RPG::AudioFile) and bgs.name != ""
        a = ["Audio/BGS/" + bgs.name, bgs.volume * bgs_volume.to_f / 100,
                bgs.pitch * bgs_pitch.to_f / 100]
        a << _a.at(0) if _a.at(0) && LiTTleDRAgo::RGSS3
        Audio.bgs_play(*a)
      elsif bgs.is_a?(String) && bgs != ''
        a = ["Audio/BGS/" + bgs, bgs_volume, bgs_pitch]
        a << _a.at(0) if _a.at(0) && LiTTleDRAgo::RGSS3
        Audio.bgs_play(*a)
      else
        Audio.bgs_stop
      end
      Graphics.frame_reset
    end
  end
  #--------------------------------------------------------------------------
  # * New method: drg_me_play
  #--------------------------------------------------------------------------
  unless method_defined?(:drg_me_play)
    def drg_me_play(me,*_a)
      if me.is_a?(RPG::AudioFile) and me.name != ""
        a = ["Audio/ME/" + me.name, me.volume * me_volume.to_f / 100,
                me.pitch * me_pitch.to_f / 100]
        Audio.me_play(*a)
      elsif me.is_a?(String) && me != ''
        a = ["Audio/ME/" + me, me_volume, me_pitch]
        Audio.me_play(*a)
      else
        Audio.me_stop
      end
      Graphics.frame_reset
    end
  end
  #--------------------------------------------------------------------------
  # * New method: drg_se_play
  #--------------------------------------------------------------------------
  unless method_defined?(:drg_se_play)
    def drg_se_play(se,*_a)
      if se.is_a?(RPG::AudioFile) and se.name != ""
        a = ["Audio/SE/" + se.name, se.volume * se_volume.to_f / 100,
                 se.pitch * se_pitch.to_f / 100]
        Audio.se_play(*a)
      elsif se.is_a?(String) && se != ''
        a = ["Audio/SE/" + se, se_volume, se_pitch]
        Audio.se_play(*a)
      end
    end
  end
end

#==============================================================================
# ** Object
#------------------------------------------------------------------------------
#  This class is superclass for all class
#==============================================================================
class Object
  #-------------------------------------------------------------------------
  # * New method: all_variable_dispose
  #-------------------------------------------------------------------------
  def all_variable_dispose
    all = instance_variables.map {|s| instance_variable_get("#{s}")}.flatten
    all.delete_if {|s| s.not.respond_to?(:dispose) }
    all.delete_if {|s| s.respond_to?(:disposed?) && s.disposed?}
    all.dispose
  end
  #-------------------------------------------------------------------------
  # * New method: rand_between
  #-------------------------------------------------------------------------
  unless method_defined?(:rand_between)
    def rand_between(min, max)
      min + rand(max - min + 1) if min.is_a?(Numeric) && max.is_a?(Numeric)
    end
  end
  #-------------------------------------------------------------------------
  # * New method: get_note
  #-------------------------------------------------------------------------
  unless method_defined?(:get_note)
    def get_note
      respond_to?(:note) ? note : ""
    end
  end
  #-------------------------------------------------------------------------
  # * New method: screen_rect
  #-------------------------------------------------------------------------
  unless method_defined?(:screen_rect)
    def screen_rect(as_rect = true)
      array = [0,0,Graphics.width,Graphics.height]
      as_rect ? Rect.new(*array) : array
    end
  end
  #-------------------------------------------------------------------------
  # * New method: force_save
  #-------------------------------------------------------------------------
  unless method_defined?(:force_save)
    def force_save(index)
      return DataManager.save_game(index) if defined?(DataManager)
      save = LiTTleDRAgo::VX ? Scene_File.new(0,nil,0) : Scene_Save.new
      begin
        file = File.open(save.make_fi
[close]

As vezes um mapa com muitos eventos, causa lag também... Mas os scripts em si eu não sei