Gabz

Gab RTP Export

Jun 3rd, 2014
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.42 KB | None | 0 0
  1. #=============================================================================
  2. # Gab RTP Export
  3. #---------------------------------------------------------------------------
  4. # @author  : Gab!
  5. # @date    : 2014/06/04
  6. # @version : 1.1
  7. #---------------------------------------------------------------------------
  8. # Exporta os arquivos do RTP que estão sendo utilizados pelo jogo para que
  9. # não haja necessidade de exportar todo o RTP ao distribuir o jogo.
  10. #
  11. # ATENÇÃO: Este script não identifica automaticamente recursos utilizados por
  12. #          outros scripts. O alvo é o banco de dados, mapas e eventos.
  13. #---------------------------------------------------------------------------
  14. # Basta colocar o script acima do Main para ativá-lo.
  15. #=============================================================================
  16.  
  17. if $TEST
  18.   # Método necessário
  19.   class << File
  20.     def copy(from, to, buffer=0)
  21.       File.open(from, 'rb'){|f|
  22.         File.open(to, 'wb'){|t|
  23.           if (buffer > 0) and block_given?
  24.             until f.eof
  25.               t << f.read(buffer)
  26.               yield
  27.             end
  28.           else
  29.             t << f.read
  30.           end
  31.         }
  32.       }
  33.     end
  34.   end
  35.  
  36.   # Arquivos Gráficos
  37.   @Graphics = {
  38.     Animations:   [],
  39.     BattleBacks1: [],
  40.     BattleBacks2: [],
  41.     Battlers:     [],
  42.     Characters:   [],
  43.     Faces:        [],
  44.     Parallaxes:   [],
  45.     System:       [],
  46.     Tilesets:     [],
  47.     Titles1:      [],
  48.     Titles2:      [],
  49.   }
  50.  
  51.   # Arquivos Sonoros
  52.   @Audio = {
  53.     BGM: [],
  54.     BGS: [],
  55.     SE:  [],
  56.     ME:  [],
  57.   }
  58.  
  59.   #  Actors
  60.   load_data('Data/Actors.rvdata2').each{|actor|
  61.     next unless actor
  62.     @Graphics[:Characters] << actor.character_name
  63.     @Graphics[:Faces]      << actor.face_name
  64.   }
  65.  
  66.   # Enemies
  67.   load_data('Data/Enemies.rvdata2').each{|enemy|
  68.     next unless enemy
  69.     @Graphics[:Battlers] << enemy.battler_name
  70.   }
  71.  
  72.   # Animations
  73.   load_data('Data/Animations.rvdata2').each{|animation|
  74.     next unless animation
  75.     @Graphics[:Animations] << animation.animation1_name
  76.     @Graphics[:Animations] << animation.animation2_name
  77.    
  78.     animation.timings.each{|timing|
  79.       @Audio[:SE] << timing.se.name
  80.     }
  81.   }
  82.  
  83.   # Tilesets
  84.   load_data('Data/Tilesets.rvdata2').each{|tileset|
  85.     next unless tileset
  86.     tileset.tileset_names.each{|tileset_name|
  87.       next if tileset_name.empty?
  88.       @Graphics[:Tilesets] << tileset_name
  89.     }
  90.   }
  91.  
  92.   # Parallaxes
  93.   Dir['Data/Map???.rvdata2'].each{|mapfile|
  94.     map = load_data(mapfile)
  95.     @Graphics[:Parallaxes  ] << map.parallax_name
  96.     @Graphics[:BattleBacks1] << map.battleback1_name
  97.     @Graphics[:BattleBacks1] << map.battleback2_name
  98.    
  99.     @Audio[:BGM] << map.bgm.name
  100.     @Audio[:BGS] << map.bgs.name
  101.    
  102.     map.events.each_value{|event|
  103.       event.pages.each{|page|
  104.         page.list.each{|command|
  105.           index = [241, 245, 249, 250].index(command.code)
  106.           next unless index
  107.           key = [:BGM, :BGS, :ME, :SE][index]
  108.           @Audio[key] << command.parameters.first.name
  109.         }
  110.       }
  111.     }
  112.   }
  113.  
  114.   # System
  115.   system = load_data('Data/System.rvdata2')
  116.   @Graphics[:Characters] << system.airship.character_name
  117.   @Graphics[:Characters] << system.ship.character_name
  118.   @Graphics[:Characters] << system.boat.character_name
  119.   @Graphics[:Titles1]    << system.title1_name
  120.   @Graphics[:Titles2]    << system.title2_name
  121.   @Graphics[:System] << "IconSet"
  122.   @Graphics[:System] << "Window"
  123.   @Graphics[:System] << "GameOver"
  124.   @Graphics[:System] << "Balloon"
  125.   @Graphics[:System] << "Shadow"
  126.   @Graphics[:System] << "BattleStart"
  127.  
  128.   @Audio[:BGM] << system.airship.bgm.name
  129.   @Audio[:BGM] << system.ship.bgm.name
  130.   @Audio[:BGM] << system.boat.bgm.name
  131.   @Audio[:BGM] << system.title_bgm.name
  132.   @Audio[:BGM] << system.battle_bgm.name
  133.  
  134.   @Audio[:ME]  << system.gameover_me.name
  135.   @Audio[:ME]  << system.battle_end_me.name
  136.  
  137.   @Audio[:SE] += system.sounds.map(&:name)
  138.  
  139.  
  140.   # Identifica diretório do RTP
  141.   library = 0.chr * 256
  142.   Win32API.new('kernel32', 'GetPrivateProfileStringA', 'PPPPLP', 'L').call(
  143.     'Game', 'Library', '', library, library.size, './Game.ini'
  144.   )
  145.   GameDLL = library.delete!("\0")
  146.    
  147.   RGSSGetRTPPath     = Win32API.new(GameDLL, 'RGSSGetRTPPath', 'L', 'L')
  148.   RGSSGetPathWithRTP = Win32API.new(GameDLL, 'RGSSGetPathWithRTP', 'L', 'L')
  149.   @RTP = DL::CPtr.new(RGSSGetPathWithRTP.call(RGSSGetRTPPath.call(1))).
  150.             to_s(480).
  151.             delete(0.chr).
  152.             gsub('\\', '/')
  153.  
  154.   if @RTP.empty?
  155.     msgbox("Gab RTP Export: Caminho para o RTP não encontrado!")
  156.   else
  157.     # Verificação dos arquivos
  158.     @Graphics.each_pair{|folder, files|
  159.       files.uniq.each{|file|
  160.         next if file.empty?
  161.         next unless Dir["Graphics/#{folder}/#{file}.*"].empty?
  162.        
  163.         fromFile = Dir["#{@RTP}/Graphics/#{folder}/#{file}.*"].select{|f|
  164.           File.extname(f) != '.txt'
  165.         }.first
  166.        
  167.         toFile = "Graphics/#{folder}/#{file}#{File.extname(fromFile)}"
  168.        
  169.         File.copy(fromFile, toFile)
  170.       }
  171.     }
  172.  
  173.     @Audio.each_pair{|folder, files|
  174.       files.uniq.each{|file|
  175.         next if file.empty?
  176.         next unless Dir["Audio/#{folder}/#{file}.*"].empty?
  177.        
  178.         fromFile = Dir["#{@RTP}/Audio/#{folder}/#{file}.*"].first
  179.         toFile = "Audio/#{folder}/#{file}#{File.extname(fromFile)}"
  180.        
  181.         File.copy(fromFile, toFile)
  182.       }
  183.     }
  184.   end
  185. end
Advertisement
Add Comment
Please, Sign In to add comment