- font_file=["/Font/wqx-16.ttf","/Font/wqx-12.ttf"]
- font_test=["Font/wqx-16.ttf","Font/wqx-12.ttf"]
- font_name=["WQX16","WQX12"]
- dll_name="RGSS103J"
- for i in 0..1
- # 字体未安装且存在字体文件则进行安装
- if not Font.exist?(font_name[i]) and FileTest.exist?(font_test[i])
- m2w = Win32API.new("kernel32","MultiByteToWideChar","llplpl","l")
- w2m = Win32API.new("kernel32","WideCharToMultiByte","llplplll","l")
- effe = Win32API.new("gdi32","EnumFontFamiliesExA","lplll","v")
- wpm = Win32API.new("kernel32","WriteProcessMemory","lplll","l")
- dll = Win32API.new("kernel32","GetModuleHandle","p","l").call(dll_name)
- # add font resource
- path = Dir.pwd + font_file[i]
- len = m2w.call(0xFDE9, 0, path, -1, "", 0)
- pp = " " * len
- m2w.call(0xFDE9, 0, path, -1, pp, len)
- Win32API.new("gdi32","AddFontResourceW","p","v").call(pp)
- # font name => ansi
- len = m2w.call(0xFDE9, 0, font_name[i], -1, "", 0)
- uname = " " * len
- m2w.call(0xFDE9, 0, font_name[i], -1, uname, len)
- len = w2m.call(0, 0, uname, -1, "", 0, 0, 0)
- aname = " " * len
- w2m.call(0, 0, uname, -1, aname, len, 0, 0)
- # get addr of the original lParam
- tt = " "
- wpm.call(-1, tt, dll + 0x12B6C4, 4, 0)
- wpm.call(-1, tt, tt.unpack("l")[0] + 0x150, 4, 0)
- lp = tt.unpack("l")[0] + 4
- # get dc
- dc = Win32API.new("user32","GetDC","l","l").call(0)
- # prepare logfont
- logfont = [0,0,0,0,0,0,0,0,1,0,0,0,0].pack("l5C*") + aname
- # call effe like RGSS did
- effe.call(dc, logfont, dll + 0x13D60, lp, 0)
- # done
- Win32API.new("user32","ReleaseDC","ll","v").call(0, dc)
- end
- end
复制代码
这是我之前抄的一段临时安装字体的脚本,作者应该时论坛内某位大佬。这个可以不用重启 |