赞 | 0 |
VIP | 40 |
好人卡 | 2 |
积分 | 1 |
经验 | 10932 |
最后登录 | 2016-5-17 |
在线时间 | 462 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 462 小时
- 注册时间
- 2007-7-30
- 帖子
- 643
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 david50407 于 2010-11-14 16:40 编辑
某次在66上看到了一个 登录档的读取方法
便应用来写出了 让RGE读取RTP的方法
首先在最上面插入两个脚本
- #================================================= =============================
- # ■ String
- #------------------------------------------------- -----------------------------
- # 字符串类。可处理任意长度的字节串。 (追加编码转换的定义)
- #================================================= =============================
- class String
- #------------------------------------------------- -------------------------
- # ● 用来编码Ruby 字符串、解码unicode 的两个Windows API 函数
- #------------------------------------------------- -------------------------
- @@MultiByteToWideChar = Win32API.new("kernel32", "MultiByteToWideChar", ['I', 'L', 'P', 'I', 'P', 'I'], 'I')
- @@WideCharToMultiByte = Win32API.new("kernel32", "WideCharToMultiByte", ['I', 'L', 'P', 'I', 'P', 'I', 'P', 'P'], 'I')
- #------------------------------------------------- -------------------------
- # ● 返回将Ruby UTF-8 字符串对象(本身)编码为unicode 后的字符串
- #------------------------------------------------- -------------------------
- def to_unicode
- len = @@MultiByteToWideChar.call(65001, 0, self, -1, 0, 0) << 1
- buf =" " * len
- # 65001: UTF-8 字符集编码(代码页)
- @@MultiByteToWideChar.call(65001, 0, self, -1, buf, len)
- return buf
- end
- #------------------------------------------------- -------------------------
- # ● 返回将编码为unicode 的字符串对象(本身)解码为UTF-8 后的字符串
- #------------------------------------------------- -------------------------
- def to_UTF8
- len = @@WideCharToMultiByte.call(65001, 0, self, -1, 0, 0, 0, 0)
- buf =" " * len
- @@WideCharToMultiByte.call(65001, 0, self, -1, buf, len, 0, 0)
- # 去掉'\0' 字符串结束符(因为转换之后仅仅用于Ruby 字符串)
- buf.slice!(-1, 1)
- return buf
- end
- end
复制代码 用来支持中文
- #==============================================================================
- #module Ini
- #==============================================================================
- module Ini
- def self.readIni(item = "Title")
- buf = 0.chr * 256
- gpps = Win32API.new("kernel32","GetPrivateProfileString","pppplp","l")
- gpps.call("Game",item,"",buf,256,"./Game.ini")
- buf.delete!("\0")
- return buf
- end
- end
复制代码 让RGE能读取 ini 设定
而 ini 档内格式如下
- [Setting]
- Library=RGE.dll
- Scripts=Scripts.rges
- Package=
- [Plugin]
- Sriol=default.r32
- Priol=default.r32
- [Game]
- RTP1=Standard
- RTP2=
- RTP3=
复制代码 最多三个(当然可以自己改)
再插入一个脚本
这是精简版的Regedit模组
- module Regedit
- HKEY_LOCAL_MACHINE = 0x80000002
- STANDARD_RIGHTS_READ = 0x00020000
- KEY_QUERY_VALUE = 0x0001
- KEY_ENUMERATE_SUB_KEYS = 0x0008
- KEY_NOTIFY = 0x0010
- KEY_READ = STANDARD_RIGHTS_READ |
- KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
- KEY_EXECUTE = KEY_READ | 0x0200 # 0x0200 : Wow64_32Node
- @@reg = []
- # 0:开启 1:寻找
- [
- %w/RegOpenKeyEx LPLLP L/, #0
- %w/RegQueryValueExW LPLPPP L/, #1
- ].each do |fn|
- @@reg << Win32API.new("advapi32.dll", *fn)
- end
- module_function
- def REG
- return @@reg
- end
- # 返回顶端
- def OpenKey(hkey, name, opt, desired)
- result = packdw(0)
- check self.REG[0].call(hkey, name, opt, desired, result)
- @reg_jb = unpackdw(result)
- end
-
- def QueryValue(hkey, name)
- size = [128].pack('l')
- data = ' ' * 32
- #check (self.REG[1].call(hkey, name, 0, type, 0, size), name)
- self.REG[1].call(hkey, name.to_unicode, 0, 0, data, size)
- check (data, name)
- data = data.to_UTF8
- return data
- end
-
- def check(data, name="")
- if data == ' ' * 32
- p "找不到 RTP:#{name}!"
- exit
- end
- end
-
- def packdw(dw)
- [dw].pack("V")
- end
-
- def unpackdw(dw)
- dw += [0].pack("V")
- dw.unpack("V")[0]
- end
-
- def get_jb
- return @reg_jb if @reg_jb != nil
- end
- end
复制代码 让RGE能读取登录值
最后,压轴来了
再插入一个脚本
- # RTP 数量 (对应到ini档)
- $rtp_num = 3
- # 读取RTP路径
- def getRTPPath(rtpname)
- return "" if rtpname == "" or rtpname.nil?
- Regedit.OpenKey(Regedit::HKEY_LOCAL_MACHINE,"SOFTWARE\\Enterbrain\\RGSS\\RTP",0,Regedit::KEY_EXECUTE)
- rp = Regedit.QueryValue(Regedit.get_jb,rtpname)
- return "" if rp == "" or rp.nil?
- rp = File.expand_path(rp) + "/"
- return rp
- end
- $RTP = []
- for i in 0...$rtp_num
- $RTP[i] = getRTPPath(Ini.readIni("RTP#{i.to_s}"))
- end
- # 修正路径
- module RPG
- module Path
- FindFirstFile = Win32API.new("kernel32", "FindFirstFileW", "PP", "L")
- FindNextFile = Win32API.new("kernel32", "FindNextFileW", "LP", "I")
- def self.findP(*paths)
- findFileData = " " * 592
- for p in paths
- unless FindFirstFile.call(p.to_unicode, findFileData) == -1 # INVALID_HANDLE_VALUE
- return File.dirname(p) + "/" + findFileData[44, 45 + 260 * 2].to_UTF8
- end
- end
- return ""
- end
-
- @list = {}
- def self.Graphics(path)
- return @list[path] if @list.include?(path)
- check = File.extname(path).empty?
- rtp = []
- for i in 0...$rtp_num
- unless $RTP[i].empty?
- rtp.push($RTP[i] + path)
- if check
- rtp.push($RTP[i] + path + ".*")
- end
- end
- end
- pa = self.findP(*rtp)
- if pa == ""
- @list[path] = path
- else
- @list[path] = pa
- end
- return @list[path]
- end
- def self.Audio(path)
- return @list[path] if @list.include?(path)
- check = File.extname(path).empty?
- rtp = []
- for i in 0...$rtp_num
- unless $RTP[i].empty?
- rtp.push($RTP[i] + path)
- if check
- rtp.push($RTP[i] + path + ".*")
- end
- end
- end
- pa = self.findP(*rtp)
- if pa == ""
- @list[path] = path
- else
- @list[path] = pa
- end
- return @list[path]
- end
- end
- end
- # 修正路径
- module RPG
- module Cache
- @cache = {}
- def self.load_bitmap(folder_name, filename, hue = 0)
- path = folder_name + filename
- path = RPG::Path::Graphics(path) #
- if not @cache.include?(path) or @cache[path].disposed?
- if filename != ""
- @cache[path] = Bitmap.new(path)
- else
- @cache[path] = Bitmap.new(32, 32)
- end
- end
- if hue == 0
- @cache[path]
- else
- key = [path, hue]
- if not @cache.include?(key) or @cache[key].disposed?
- @cache[key] = @cache[path].clone
- @cache[key].hue_change(hue)
- end
- @cache[key]
- end
- end
- end
- class Sprite < ::Sprite
- def animation_process_timing(timing, hit)
- if (timing.condition == 0) or
- (timing.condition == 1 and hit == true) or
- (timing.condition == 2 and hit == false)
- if timing.se.name != ""
- se = timing.se
- path = RPG::Path::Audio("Audio/SE/" + se.name) #
- Audio.se_play(path, se.volume, se.pitch) #
- end
- case timing.flash_scope
- when 1
- self.flash(timing.flash_color, timing.flash_duration * 2)
- when 2
- if self.viewport != nil
- self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
- end
- when 3
- self.flash(nil, timing.flash_duration * 2)
- end
- end
- end
- end
- end
复制代码 附上范例
http://www.zumodrive.com/share/8oSEZDEzNW
于 2010/11/14 12:11 更新:
使Regedit 模块默认使用32Bit / Wow6432 的Node
支持中文或其他 Unicode 编码的 路径
重新上传范例 |
|