赞 | 3 |
VIP | 37 |
好人卡 | 8 |
积分 | 0 |
经验 | 22564 |
最后登录 | 2017-5-16 |
在线时间 | 491 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 49
- 在线时间
- 491 小时
- 注册时间
- 2012-1-27
- 帖子
- 421
|
- #encoding: utf-8
- #==============================================================================
- # ■ [PS0]RTP 精简
- # RTP_RIP
- #------------------------------------------------------------------------------
- # 删除 RTP 中不需要的文件,减小游戏发布时的体积。
- #==============================================================================
- # [更新记录]
- # - 2012.02.13 By Shy07
- # * 初版(实验版本)
- #------------------------------------------------------------------------------
- # [使用方法]
- # - 实验版本,适合默认脚本制作的 Ace 游戏。游戏制作完毕以后,将 RTP 文件夹
- # 下的 Audio、Graphics 文件夹复制到游戏文件夹,提示文件夹重复选合并,提示文件
- # 重复选不要复制。
- # - 完成以上操作后复制这段脚本到游戏脚本中,运行。如果有提示文件无法移除,
- # 可以手动删除;移除的文件在游戏文件夹的 BAK 文件夹下。
- # - 运行完这段后记得把这段脚本删除或注释掉最后 RTP_RIP.remove_files 那一行。
- # 发布游戏时把 Game.ini 里的 RTP=RPGVXAce 改成 RTP= 再用压缩工具打包(不要用
- # Ace 制作发行包)。
- # - 最后,这段脚本还不完善,运行以后一定要完整测试游戏,确认不缺少文件后,
- # 再删除 BAK 文件夹。
- #==============================================================================
-
- #==============================================================================
- # ■ String
- #------------------------------------------------------------------------------
- # String 类追加定义。
- #==============================================================================
-
- class String
- #----------------------------------------------------------------------------
- # ● API
- #----------------------------------------------------------------------------
- @@MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- @@WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- #----------------------------------------------------------------------------
- # ● UTF-8 转系统编码
- #----------------------------------------------------------------------------
- def u2s
- i = @@MultiByteToWideChar.call(65001, 0 , self, -1, nil,0)
- buffer = "\0" * (i*2)
- @@MultiByteToWideChar.call(65001, 0 , self, -1, buffer, i)
- i = @@WideCharToMultiByte.call(0, 0, buffer, -1, nil, 0, nil, nil)
- result = "\0" * i
- @@WideCharToMultiByte.call(0, 0, buffer, -1, result, i, nil, nil)
- result.chop!
- return result
- end
- #----------------------------------------------------------------------------
- # ● 系统编码转 UTF-8
- #----------------------------------------------------------------------------
- def s2u
- i = @@MultiByteToWideChar.call(0, 0, self, -1, nil, 0)
- buffer = "\0" * (i*2)
- @@MultiByteToWideChar.call(0, 0, self, -1, buffer, buffer.size / 2)
- i = @@WideCharToMultiByte.call(65001, 0, buffer, -1, nil, 0, nil, nil)
- result = "\0" * i
- @@WideCharToMultiByte.call(65001, 0, buffer, -1, result, result.size, nil, nil)
- result.chop!
- return result
- end
- end
-
- #==============================================================================
- # ■ RTP_RIP
- #------------------------------------------------------------------------------
- # RTP 精简
- #==============================================================================
-
- module RTP_RIP
- #--------------------------------------------------------------------------
- # ● 常量
- #--------------------------------------------------------------------------
- FMs = ["bmp", "jpg", "png", "wav", "mp3", "ogg", "wma", "mid"]
-
- PATH = ["Graphics/Animations/", "Graphics/Battlebacks1/",
- "Graphics/Battlebacks2/", "Graphics/Battlers/",
- "Graphics/Characters/", "Graphics/Faces/",
- "Graphics/Parallaxes/", "Graphics/Pictures/",
- "Graphics/Titles1/", "Graphics/Titles2/",
- "Graphics/Tilesets/",
- "Audio/BGM/", "Audio/BGS/", "Audio/ME/", "Audio/SE/"]
-
- SYSTEM = ["Graphics/System/Balloon", "Graphics/System/BattleStart",
- "Graphics/System/GameOver", "Graphics/System/IconSet",
- "Graphics/System/Shadow", "Graphics/System/Window"]
- # 模块函数
- module_function
- #--------------------------------------------------------------------------
- # ● 获取全部文件
- #--------------------------------------------------------------------------
- def get_all_files
- @old_dir = Dir.pwd.s2u
- @resource_type = []
- FMs.each do |fm|
- @resource_type << fm
- @resource_type << fm.upcase
- end
- @all_files = []
- @path = ""
- next_file(@path)
- Dir.chdir(@old_dir)
- end
- #--------------------------------------------------------------------------
- # ● 下一个文件
- #--------------------------------------------------------------------------
- def next_file(path)
- Dir.chdir(@old_dir)
- Dir.chdir(path) if path != ""
- Dir["*"].each do |f|
- if FileTest.directory?(f)
- @path = @path + f + "/"
- next_file(@path)
- else
- arr = f.split(/\./)
- if @resource_type.include? arr.pop
- fi = arr.shift
- arr.each {|v| fi += "." + v }
- @all_files << @path + fi
- end
- end
- end
- path_a = path.split(/\//)
- @path = ""
- (0...path_a.size - 1).each {|i| @path += path_a[i] + "/" }
- Dir.chdir(@old_dir)
- Dir.chdir(@path) if @path != ""
- end
- #--------------------------------------------------------------------------
- # ● 检测是否空文件名
- #--------------------------------------------------------------------------
- def check_file(arr, filename, path = "")
- arr << path + filename unless filename == ""
- end
- #--------------------------------------------------------------------------
- # ● 获取事件列表文件列表
- #--------------------------------------------------------------------------
- def get_list_files(list)
- arr = []
- list.each do |cmd|
- case cmd.code
- when 101
- check_file(arr, cmd.parameters[0], PATH[5])
- when 132
- check_file(arr, cmd.parameters[0].name, PATH[11])
- when 133
- check_file(arr, cmd.parameters[0].name, PATH[13])
- #~ when 212 # 显示动画,暂不分析
- when 231
- check_file(arr, cmd.parameters[1], PATH[7])
- when 241
- check_file(arr, cmd.parameters[0].name, PATH[11])
- when 245
- check_file(arr, cmd.parameters[0].name, PATH[12])
- when 249
- check_file(arr, cmd.parameters[0].name, PATH[13])
- when 250
- check_file(arr, cmd.parameters[0].name, PATH[14])
- #~ when 282 # 更改图块组,暂不分析
- when 283
- check_file(arr, cmd.parameters[0], PATH[1])
- check_file(arr, cmd.parameters[1], PATH[2])
- when 284
- check_file(arr, cmd.parameters[0], PATH[6])
- #~ when 301 # 战斗处理,暂不分析
- when 322
- check_file(arr, cmd.parameters[1], PATH[4])
- check_file(arr, cmd.parameters[3], PATH[5])
- when 323
- check_file(arr, cmd.parameters[1], PATH[4])
- #~ when 337 # 显示战斗动画,暂不分析
- end
- end
- return arr
- end
- #--------------------------------------------------------------------------
- # ● 获取动画文件列表
- #--------------------------------------------------------------------------
- def get_ani_files
- @ani_files = []
- load_data("Data/Animations.rvdata2").each do |ani|
- if ani.nil?
- @ani_files << []
- else
- arr = []
- check_file(arr, ani.animation1_name, PATH[0])
- check_file(arr, ani.animation2_name, PATH[0])
- ani.timings.each {|timing| check_file(arr, timing.se.name, PATH[14]) }
- @ani_files << arr
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取角色文件列表
- #--------------------------------------------------------------------------
- def get_act_files
- @act_files = []
- load_data("Data/Actors.rvdata2").each do |act|
- if act.nil?
- @act_files << []
- else
- arr = []
- check_file(arr, act.character_name, PATH[4])
- check_file(arr, act.face_name, PATH[5])
- @act_files << arr
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取敌人文件列表
- #--------------------------------------------------------------------------
- def get_ene_files
- @ene_files = []
- load_data("Data/Enemies.rvdata2").each do |ene|
- if ene.nil?
- @ene_files << []
- else
- arr = []
- check_file(arr, ene.battler_name, PATH[3])
- @ene_files << arr
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取敌群文件列表
- #--------------------------------------------------------------------------
- def get_trp_files
- @trp_files = []
- load_data("Data/Troops.rvdata2").each do |trp|
- if trp.nil?
- @trp_files << []
- else
- arr = []
- trp.pages.each {|page| arr += get_list_files(page.list) }
- @trp_files << arr
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取图块文件列表
- #--------------------------------------------------------------------------
- def get_til_files
- @til_files = []
- load_data("Data/Tilesets.rvdata2").each do |til|
- if til.nil?
- @til_files << []
- else
- arr = []
- til.tileset_names.each {|ts| check_file(arr, ts, PATH[10]) }
- @til_files << arr
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取公共事件文件列表
- #--------------------------------------------------------------------------
- def get_com_files
- @com_files = []
- load_data("Data/CommonEvents.rvdata2").each do |com|
- if com.nil?
- @com_files << []
- else
- @com_files << get_list_files(com.list)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取系统文件列表
- #--------------------------------------------------------------------------
- def get_sys_files
- arr = []
- data_system = load_data("Data/System.rvdata2")
- check_file(arr, data_system.boat.character_name, PATH[4])
- check_file(arr, data_system.ship.character_name, PATH[4])
- check_file(arr, data_system.airship.character_name, PATH[4])
- check_file(arr, data_system.title1_name, PATH[8])
- check_file(arr, data_system.title2_name, PATH[9])
- check_file(arr, data_system.title_bgm.name, PATH[11])
- check_file(arr, data_system.battle_bgm.name, PATH[11])
- check_file(arr, data_system.battle_end_me.name, PATH[13])
- check_file(arr, data_system.gameover_me.name, PATH[13])
- data_system.sounds.each {|sound| check_file(arr, sound.name, PATH[14]) }
- @sys_files = arr + SYSTEM
- end
- #--------------------------------------------------------------------------
- # ● 获取地图文件列表
- #--------------------------------------------------------------------------
- def get_map_files
- map_num = Dir.glob("Data/Map***.rvdata2").size
- @map_files = {}
- (1...map_num).each do |i|
- name = sprintf("Data/Map%03d.rvdata2", i)
- map = load_data(name)
- @map_files[name] = []
- @map_files[name] += @til_files[map.tileset_id]
- check_file(@map_files[name], map.bgm.name, PATH[11])
- check_file(@map_files[name], map.bgs.name, PATH[12])
- check_file(@map_files[name], map.battleback1_name, PATH[1])
- check_file(@map_files[name], map.battleback2_name, PATH[2])
- map.events.each_value do |value|
- value.pages.each do |page|
- check_file(@map_files[name], page.graphic.character_name, PATH[4])
- @map_files[name] += get_list_files(page.list)
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 链接文件列表
- #--------------------------------------------------------------------------
- def link_list
- self.get_all_files
- self.get_ani_files
- self.get_act_files
- self.get_ene_files
- self.get_trp_files
- self.get_til_files
- self.get_com_files
- self.get_sys_files
- self.get_map_files
- @linked_files = []
- @ani_files.each {|arr| @linked_files += arr }
- @act_files.each {|arr| @linked_files += arr }
- @ene_files.each {|arr| @linked_files += arr }
- @trp_files.each {|arr| @linked_files += arr }
- @til_files.each {|arr| @linked_files += arr }
- @com_files.each {|arr| @linked_files += arr }
- @linked_files += @sys_files
- @map_files.each_value {|value| @linked_files += value }
- end
- #--------------------------------------------------------------------------
- # ● 移除文件
- #--------------------------------------------------------------------------
- def remove_files
- self.link_list
- arr = @all_files.uniq - @linked_files.uniq
- begin;Dir.mkdir("BAK");rescue;end
- File.open("BAK/list.txt", "wb") {|f| arr.sort.each {|i| f.write i+"\r\n" } }
- arr.each do |f|
- FMs.each do |fm|
- if File.exist?(f + "." + fm)
- from = f + "." + fm
- to = "BAK/" + from.gsub(/\//, "_")
- begin;File.rename(from, to);rescue;p from + "-移除失败";end
- break
- elsif File.exist?(f + "." + fm.upcase)
- from = f + "." + fm.upcase
- to = "BAK/" + from.gsub(/\//, "_")
- begin;File.rename(from, to);rescue;p from + "-移除失败";end
- break
- end
- end
- end
- msgbox_p "Done!"
- exit
- end
- end
-
- # 移除文件
- #~ RTP_RIP.remove_files
复制代码 |
评分
-
查看全部评分
|