Project1
标题:
补丁/插件脚本嵌入工具
[打印本页]
作者:
有丘直方
时间:
2017-8-20 11:54
标题:
补丁/插件脚本嵌入工具
module ScriptPorter
SCRIPT_NAMES = []
SCRIPT_FILENAMES = ["Data/NewScript%03d.rvdata2", "Data/NewScript*.rvdata2"]
def self.filenames
Dir.glob(SCRIPT_FILENAMES[1])
end
def self.script_contents
$RGSS_SCRIPTS.select {|content| SCRIPT_NAMES.include?(content[1]) }
end
def self.scripts
script_contents.collect {|content| content[3].force_encoding("UTF-8") }
end
def self.next_filename
sprintf(SCRIPT_FILENAMES[0], filenames.size + 1)
end
def self.read_script(filename)
File.open(filename, "rb") {|file| Marshal.load(file) } rescue ""
end
def self.write_script(script)
File.open(next_filename, "wb") {|file| Marshal.dump(script, file) } rescue delete_file
end
def self.push_script(script)
imported_scripts.push(script)
end
def self.delete_file
filenames.each {|filename| File.delete(filename) rescue next }
end
def self.port_scripts
$TEST ? export_scripts : import_scripts
end
def self.export_scripts
scripts.each {|script| write_script(script) rescue delete_file }
end
def self.import_scripts
filenames.each {|filename| push_script(read_script(filename)) }
end
def self.imported_scripts
@imported_scripts ||= []
end
end
复制代码
作用:在工程中调用,把新的脚本或者修改过的脚本的修改过的部分制作成多个文件,发行新版本的游戏的补丁时就不需要出现完整的Scripts.rvdata2(我这里用rvdata2是因为我通常用VA)了
使用:把ScriptPorter::SCRIPT_NAMES设为补丁脚本名字组成的数组,ScriptPorter::SCRIPT_FILENAMES设为补丁的文件名的数组,前面一个是sprintf格式的,后面一个的文件名中要把sprintf格式的字符(%xx)换成文件名通配符(*)。当你确定需要制作补丁的时候,且确保上一个版本的游戏已经包含上面这个模块,请在下面加一句
ScriptPorter.port_scripts
复制代码
然后以DEBUG模式运行游戏。另外,为了使脚本补丁生效,你还需要在玩家手上的游戏(当然这是你第一次使用本嵌入工具的时候就要加入的东西,此后就不必理会了,因为玩家手上的游戏的Scripts.rvdata2永远不会变)里面出现这一句
ScriptPorter.imported_scripts.each {|script| eval(script) }
复制代码
作者:
chd114
时间:
2017-11-14 12:55
如果补丁是自己控制,那可以这样弄吗:玩家拿到的是一个基础的游戏档案,通过更新补丁获取新的游戏内容,这个补丁文件可以在更新时先解包,把新东西放进去以后再重新打包
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1