diff --git a/AquaMai/AquaMai.csproj b/AquaMai/AquaMai.csproj
index a83253de..9965e89f 100644
--- a/AquaMai/AquaMai.csproj
+++ b/AquaMai/AquaMai.csproj
@@ -298,6 +298,7 @@ DEBUG
+
@@ -332,6 +333,7 @@ DEBUG
+
diff --git a/AquaMai/AquaMai.toml b/AquaMai/AquaMai.toml
index 07c4d557..d0136c7f 100644
--- a/AquaMai/AquaMai.toml
+++ b/AquaMai/AquaMai.toml
@@ -50,6 +50,9 @@ CustomPlaceName=""
# In the song selection screen, press the Service button or the "7" key (the round button in the middle of the arrow keys in the default ADX firmware) to toggle the display of self-made charts.
# A directory is considered to contain self-made charts if it does not have DataConfig.xml or OfficialChartsMark.txt in the Axxx directory.
HideSelfMadeCharts=true
+# Place font.ttf in the LocalAssets directory to replace the game's global font
+# Cannot be used together with FontFix
+CustomFont=false
[Fix]
# Allow login with higher data version
@@ -64,6 +67,9 @@ ForcePaidPlay=false
ExtendNotesPool=128
# Force the frame rate limit to 60 FPS and disable vSync. Do not use if your game has no issues
FrameRateLock=false
+# Use Microsoft YaHei Bold to display characters not in the font library
+# Cannot be used together with CustomFont
+FontFix=true
[Utils]
# Log user ID on login
diff --git a/AquaMai/AquaMai.zh.toml b/AquaMai/AquaMai.zh.toml
index 2a2666bc..4b137e67 100644
--- a/AquaMai/AquaMai.zh.toml
+++ b/AquaMai/AquaMai.zh.toml
@@ -59,6 +59,9 @@ CustomPlaceName=""
# 选歌界面按下 Service 键或者键盘上的 “7” 键(ADX 默认固件下箭头键中间的圆形按键)切换自制谱的显示和隐藏
# 是否是自制谱的判断方式是 Axxx 目录里没有 DataConfig.xml 或 OfficialChartsMark.txt 就认为这个目录里是自制谱
HideSelfMadeCharts=true
+# 在 LocalAssets 目录下放置 font.ttf 可以替换游戏的全局字体
+# 不可以和 FontFix 一起使用
+CustomFont=false
# ===================================
# 修复一些潜在的问题
@@ -80,6 +83,9 @@ ForcePaidPlay=false
ExtendNotesPool=128
# 强制设置帧率上限为 60 帧并关闭垂直同步。如果你的游戏没有问题,请不要使用
FrameRateLock=false
+# 在显示字库里没有的字时使用微软雅黑 Bold 显示
+# 不可以和 CustomFont 一起使用
+FontFix=true
[Utils]
# 登录时将 UserID 输出到日志
diff --git a/AquaMai/Config.cs b/AquaMai/Config.cs
index be04e42a..6c21f836 100644
--- a/AquaMai/Config.cs
+++ b/AquaMai/Config.cs
@@ -38,6 +38,7 @@ namespace AquaMai
public bool LoadLocalBga { get; set; }
public bool TestProof { get; set; }
public bool HideSelfMadeCharts { get; set; }
+ public bool CustomFont { get; set; }
public string CustomVersionString { get; set; } = "";
public string CustomPlaceName { get; set; } = "";
public string ExecOnIdle { get; set; } = "";
@@ -53,6 +54,7 @@ namespace AquaMai
public bool ForcePaidPlay { get; set; }
public int ExtendNotesPool { get; set; }
public bool FrameRateLock { get; set; }
+ public bool FontFix { get; set; }
}
public class UtilsConfig
diff --git a/AquaMai/Fix/FontFix.cs b/AquaMai/Fix/FontFix.cs
new file mode 100644
index 00000000..400989c7
--- /dev/null
+++ b/AquaMai/Fix/FontFix.cs
@@ -0,0 +1,32 @@
+using System.Collections.Generic;
+using HarmonyLib;
+using MelonLoader;
+using TMPro;
+using UnityEngine;
+using UnityEngine.TextCore.LowLevel;
+
+namespace AquaMai.Fix;
+
+public class FontFix
+{
+ private static TMP_FontAsset fontAsset;
+ private static List fixedFonts = [];
+
+ public static void DoCustomPatch(HarmonyLib.Harmony h)
+ {
+ var font = new Font(@"C:\Windows\Fonts\msyhbd.ttc");
+ fontAsset = TMP_FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 8192, 8192);
+ }
+
+ [HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
+ [HarmonyPostfix]
+ public static void PostFix(TextMeshProUGUI __instance)
+ {
+ if (fixedFonts.Contains(__instance.font)) return;
+# if DEBUG
+ MelonLogger.Msg($"[FontFix] Fixing font: {__instance.font.name}");
+# endif
+ __instance.font.fallbackFontAssetTable.Add(fontAsset);
+ fixedFonts.Add(__instance.font);
+ }
+}
diff --git a/AquaMai/UX/CustomFont.cs b/AquaMai/UX/CustomFont.cs
new file mode 100644
index 00000000..d1f03bcb
--- /dev/null
+++ b/AquaMai/UX/CustomFont.cs
@@ -0,0 +1,36 @@
+using System;
+using System.IO;
+using HarmonyLib;
+using MelonLoader;
+using TMPro;
+using UnityEngine;
+using UnityEngine.TextCore.LowLevel;
+
+namespace AquaMai.UX;
+
+public class CustomFont
+{
+ private static TMP_FontAsset fontAsset;
+
+ public static void DoCustomPatch(HarmonyLib.Harmony h)
+ {
+ var fontPath = Path.Combine(Environment.CurrentDirectory, "LocalAssets", "font.ttf");
+ if (!File.Exists(fontPath)) return;
+
+ var font = new Font(fontPath);
+
+ // 不设置成 8192 的话,贴图会用完,剩下的字显示不出来
+ fontAsset = TMP_FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 8192, 8192);
+ }
+
+ [HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
+ [HarmonyPostfix]
+ public static void PostFix(TextMeshProUGUI __instance)
+ {
+ if (fontAsset is null) return;
+# if DEBUG
+ MelonLogger.Msg($"{__instance.font.name} {__instance.text}");
+# endif
+ __instance.font = fontAsset;
+ }
+}