Advertisement
LiTTleDRAgo

[RGSS/2/3] Load RTP File

Aug 7th, 2013
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.99 KB | None | 0 0
  1. #==============================================================================
  2. # ** Load RTP File
  3. # Version : 1.40
  4. # Original by joe59491, edited by LiTTleDRAgo
  5. #==============================================================================
  6. module Load_RTP_File
  7.  
  8.   RMXP  = true
  9.   RMVX  = true
  10.   RMVXA = true
  11.  
  12. end
  13.  
  14. ($imported ||= {})[:load_rtp_file] = 1.40
  15. $TEST = true # $TEST has to be true in order for the RTP script to work
  16. #==============================================================================
  17. # ** Ini
  18. #------------------------------------------------------------------------------
  19. #  
  20. #==============================================================================
  21. module Ini
  22.   #--------------------------------------------------------------------------
  23.   # * self.readIni
  24.   #--------------------------------------------------------------------------
  25.   def self.readIni(item = "Title")
  26.     buf = 0.chr * 256
  27.     @gpps ||= Win32API.new("kernel32","GetPrivateProfileString","pppplp","l")
  28.     @gpps.call("Game",item,"",buf,256,"./Game.ini")
  29.     buf.delete!("\0")
  30.     return buf
  31.   end
  32. end
  33.  
  34. #==============================================================================
  35. # ** String
  36. #------------------------------------------------------------------------------
  37. #  
  38. #==============================================================================
  39. class String
  40.   #--------------------------------------------------------------------------
  41.   # ● UTF8_to_unicode
  42.   #--------------------------------------------------------------------------
  43.   def to_unicode  
  44.     @mbytetowchar ||= Win32API.new("kernel32","MultiByteToWideChar",'ilpipi','I')
  45.     len = @mbytetowchar.call(65001, 0, self, -1, 0, 0) << 1
  46.     @mbytetowchar.call(65001, 0, self, -1, (buf = " " * len), len)
  47.     return buf
  48.   end
  49. end
  50.  
  51. #==============================================================================
  52. # ** RPG::Path
  53. #------------------------------------------------------------------------------
  54. #  
  55. #==============================================================================
  56. module RPG
  57.   module Path
  58.     #--------------------------------------------------------------------------
  59.     # * Constant
  60.     #--------------------------------------------------------------------------
  61.     FindFirstFile = Win32API.new("kernel32", "FindFirstFileW", "PP", "L")
  62.     FindNextFile  = Win32API.new("kernel32", "FindNextFileW", "LP", "I")
  63.     #--------------------------------------------------------------------------
  64.     # * getRTPPath
  65.     #--------------------------------------------------------------------------
  66.     def self.getRTPPath(rgss,rtpname)
  67.       return "" if rtpname == "" or rtpname.nil?
  68.       rp = File.join(ENV['CommonProgramFiles'],'Enterbrain',rgss,rtpname,'/')
  69.       rp = rp.gsub("\\","/")
  70.       rp = rp.gsub("//","/")
  71.       return rp
  72.     end
  73.     #--------------------------------------------------------------------------
  74.     # * Class Variable
  75.     #--------------------------------------------------------------------------
  76.     @@RTP = []
  77.     if Load_RTP_File::RMXP
  78.       @@RTP << self.getRTPPath('RGSS','Standard')
  79.       (0..3).each do |i|
  80.         @@RTP << self.getRTPPath('RGSS',Ini.readIni("RTP#{i.to_s}"))
  81.       end
  82.     end  
  83.     @@RTP << self.getRTPPath('RGSS2',"RPGVX")    if Load_RTP_File::RMVX
  84.     @@RTP << self.getRTPPath('RGSS3',"RPGVXAce") if Load_RTP_File::RMVXA
  85.     @@RTP.reject! {|rtp| rtp.nil? || rtp.empty?}
  86.     #--------------------------------------------------------------------------
  87.     # * self.findP
  88.     #--------------------------------------------------------------------------
  89.     def self.findP(*paths)
  90.       findFileData = " " * 596
  91.       result = ""
  92.       for file in paths        
  93.         unless FindFirstFile.call(file.to_unicode, findFileData) == -1
  94.           name = file.split("/").last.split(".*").first
  95.           result = File.dirname(file) + "/" + name
  96.         end
  97.       end
  98.       return result
  99.     end
  100.     #--------------------------------------------------------------------------
  101.     # * self.RTP
  102.     #--------------------------------------------------------------------------
  103.     def self.RTP(path)
  104.       @list ||= {}
  105.       return @list[path] if @list.include?(path)
  106.       check = File.extname(path).empty?
  107.       rtp = []
  108.       @@RTP.each do |item|
  109.         unless item.empty?
  110.           rtp.push(item + path)
  111.           rtp.push(item + path + ".*") if check
  112.         end
  113.       end
  114.       rtp.push(path)
  115.       rtp.push(path + ".*") if check
  116.       pa = self.findP(*rtp)
  117.       @list[path] = pa == "" ? path : pa
  118.       return @list[path]
  119.     end
  120.   end
  121. end
  122.  
  123. #==============================================================================
  124. # ** Audio
  125. #------------------------------------------------------------------------------
  126. #  
  127. #==============================================================================
  128. class << Audio
  129.   #--------------------------------------------------------------------------
  130.   # * Alias Listing
  131.   #--------------------------------------------------------------------------
  132.   [:bgm_play,:bgs_play,:se_play,:me_play].each do |meth|
  133.     $@ || alias_method(:"#{meth}_path", :"#{meth}")
  134.     define_method(:"#{meth}") do |*args|
  135.       args[0] = RPG::Path::RTP(args[0]) if args[0].is_a?(String)
  136.       send(:"#{meth}_path",*args)
  137.     end
  138.   end
  139. end
  140.  
  141. #==============================================================================
  142. # ** Bitmap
  143. #------------------------------------------------------------------------------
  144. #  
  145. #==============================================================================
  146. class Bitmap
  147.   #--------------------------------------------------------------------------
  148.   # ● Alias Method
  149.   #--------------------------------------------------------------------------
  150.   $@ || alias_method(:rtp_path_init, :initialize)
  151.   #--------------------------------------------------------------------------
  152.   # ● Object Initialization
  153.   #--------------------------------------------------------------------------
  154.   def initialize(*args)
  155.     args[0] = RPG::Path::RTP(args.at(0)) if args.at(0).is_a?(String)
  156.     rtp_path_init(*args)
  157.   end
  158. end
  159.  
  160. #==============================================================================
  161. # ** Graphics
  162. #------------------------------------------------------------------------------
  163. #  This module handles all Graphics
  164. #==============================================================================
  165. class << Graphics
  166.   #--------------------------------------------------------------------------
  167.   # ● Alias Method
  168.   #--------------------------------------------------------------------------
  169.   $@ || alias_method(:rtp_path_transition, :transition)
  170.   #--------------------------------------------------------------------------
  171.   # ● transition
  172.   #--------------------------------------------------------------------------
  173.   def transition(*args)
  174.     args[1] = RPG::Path::RTP(args.at(1)) if args[1].is_a?(String)
  175.     rtp_path_transition(*args)
  176.   end
  177. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement