Project1

标题: 【字体读取】读取字体文件需要重启游戏才能生效怎么办 [打印本页]

作者: 紫英晓狼1130    时间: 2023-4-24 09:42
标题: 【字体读取】读取字体文件需要重启游戏才能生效怎么办
本帖最后由 紫英晓狼1130 于 2023-4-24 10:13 编辑

自动读取字体文件需要重启游戏才能生效怎么办?
插入了以下的自动读取文件夹内字体的脚本(见代码段)
但是每次重启电脑之后,就需要游戏重启之后才能正常显示字体……
其他的没什么问题,但每次关机之后都要玩家重启游戏很麻烦……
有两个思路:
改代码:把这段代码改好,改成不用重启……
自动重启:游戏程序开始时,再打开一个Game.exe,相当于自动重启游戏

根据2楼脚本,已经可以直接读取字体文件,无需重启
目前来看没什么问题,后续会用更多系统以及机器测试!

RUBY 代码复制
  1. #==============================================================================
  2. # ■ Font
  3. #------------------------------------------------------------------------------
  4. #  自动读取游戏字体。
  5. #==============================================================================
  6.   font_file = "/Fonts/GameFont.TTF"
  7.   font_name = "GameFont"
  8.   unless Font.exist?(font_name)
  9.     GetCurrentDirectory = Win32API.new('kernel32', 'GetCurrentDirectoryW', 'lp', 'l')
  10.     MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'llplpl', 'l')
  11.     len = GetCurrentDirectory.call(0, "")
  12.     buf = "\0" * (len - 1) * 2
  13.     GetCurrentDirectory.call(len, buf)
  14.     len = MultiByteToWideChar.call(0xFDE9, 0, font_file, -1, 0, 0)
  15.     fa = "\0" * len * 2
  16.     MultiByteToWideChar.call(0xFDE9, 0, font_file, -1, fa, len)
  17.     path = buf + fa
  18.     Win32API.new('gdi32', 'AddFontResourceW', 'p', 'l').call(path)
  19.   end
  20.   Font.default_name = font_name

作者: qq634488405    时间: 2023-4-24 09:51
  1. font_file=["/Font/wqx-16.ttf","/Font/wqx-12.ttf"]
  2. font_test=["Font/wqx-16.ttf","Font/wqx-12.ttf"]
  3. font_name=["WQX16","WQX12"]
  4. dll_name="RGSS103J"
  5. for i in 0..1
  6.   # 字体未安装且存在字体文件则进行安装
  7.   if not Font.exist?(font_name[i]) and FileTest.exist?(font_test[i])
  8.     m2w = Win32API.new("kernel32","MultiByteToWideChar","llplpl","l")
  9.     w2m = Win32API.new("kernel32","WideCharToMultiByte","llplplll","l")
  10.     effe = Win32API.new("gdi32","EnumFontFamiliesExA","lplll","v")
  11.     wpm = Win32API.new("kernel32","WriteProcessMemory","lplll","l")
  12.     dll = Win32API.new("kernel32","GetModuleHandle","p","l").call(dll_name)
  13.     # add font resource
  14.     path = Dir.pwd + font_file[i]
  15.     len = m2w.call(0xFDE9, 0, path, -1, "", 0)
  16.     pp = "  " * len
  17.     m2w.call(0xFDE9, 0, path, -1, pp, len)
  18.     Win32API.new("gdi32","AddFontResourceW","p","v").call(pp)
  19.     # font name => ansi
  20.     len = m2w.call(0xFDE9, 0, font_name[i], -1, "", 0)
  21.     uname = "  " * len
  22.     m2w.call(0xFDE9, 0, font_name[i], -1, uname, len)
  23.     len = w2m.call(0, 0, uname, -1, "", 0, 0, 0)
  24.     aname = " " * len
  25.     w2m.call(0, 0, uname, -1, aname, len, 0, 0)
  26.     # get addr of the original lParam
  27.     tt = "    "
  28.     wpm.call(-1, tt, dll + 0x12B6C4, 4, 0)
  29.     wpm.call(-1, tt, tt.unpack("l")[0] + 0x150, 4, 0)
  30.     lp = tt.unpack("l")[0] + 4
  31.     # get dc
  32.     dc = Win32API.new("user32","GetDC","l","l").call(0)
  33.     # prepare logfont
  34.     logfont = [0,0,0,0,0,0,0,0,1,0,0,0,0].pack("l5C*") + aname
  35.     # call effe like RGSS did
  36.     effe.call(dc, logfont, dll + 0x13D60, lp, 0)
  37.     # done
  38.     Win32API.new("user32","ReleaseDC","ll","v").call(0, dc)
  39.   end
  40. end
复制代码

这是我之前抄的一段临时安装字体的脚本,作者应该时论坛内某位大佬。这个可以不用重启




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1