LunaHook-mirror/LunaHook/resource/renpy_hook_font.py

63 lines
2.0 KiB
Python
Raw Normal View History

2024-03-13 11:14:01 +08:00
def callLunaHostFont():
try:
import ctypes
2024-05-30 17:32:03 +08:00
2024-03-13 11:14:01 +08:00
try:
2024-05-30 17:32:03 +08:00
internal_renpy_get_font = ctypes.CDLL("LunaHook64").internal_renpy_get_font
2024-03-13 11:14:01 +08:00
except:
2024-05-30 17:32:03 +08:00
internal_renpy_get_font = ctypes.CDLL("LunaHook32").internal_renpy_get_font
internal_renpy_get_font.restype = ctypes.c_wchar_p
2024-03-13 11:14:01 +08:00
return internal_renpy_get_font()
except:
return None
2024-05-30 17:32:03 +08:00
def callLunaIsUsingEmbed_nosplit():
try:
import ctypes
try:
internal_renpy_call_is_embed_using = ctypes.CDLL(
"LunaHook64"
).internal_renpy_call_is_embed_using
except:
internal_renpy_call_is_embed_using = ctypes.CDLL(
"LunaHook32"
).internal_renpy_call_is_embed_using
internal_renpy_call_is_embed_using.argstype = ctypes.c_int, ctypes.c_bool
internal_renpy_call_is_embed_using.restype = ctypes.c_bool
return internal_renpy_call_is_embed_using(0, False)
except:
return False
2024-03-08 23:54:27 +08:00
try:
import os
import renpy
2024-05-30 17:32:03 +08:00
2024-03-08 23:54:27 +08:00
def hook_renpy_text_font_get_font_init(original):
def new_init(*args, **kwargs):
2024-05-30 17:32:03 +08:00
# ctypes.windll.user32.MessageBoxW(None, str(kwargs), str(args), 0)
if callLunaIsUsingEmbed_nosplit():
font = callLunaHostFont()
if font and font != "" and os.path.exists(font):
font = font.replace(
"\\", "/"
) # 不知道为什么,用\会报错但之前写死C:\Windows\Fonts\msyh.ttc时就没事
args = (font,) + args[1:]
if "fn" in kwargs:
kwargs["fn"] = font
2024-03-08 23:54:27 +08:00
return original(*args, **kwargs)
return new_init
2024-05-30 17:32:03 +08:00
2024-03-08 23:54:27 +08:00
if "original_renpy_text_font_get_font" not in globals():
original_renpy_text_font_get_font = renpy.text.font.get_font
2024-05-30 17:32:03 +08:00
renpy.text.font.get_font = hook_renpy_text_font_get_font_init(
original_renpy_text_font_get_font
)
2024-03-08 23:54:27 +08:00
except:
2024-05-30 17:32:03 +08:00
pass