From 635062bb241a9d8318e4eed36fef8e690f253d9d Mon Sep 17 00:00:00 2001 From: pm chihya Date: Thu, 1 Jan 2026 22:11:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AA=E6=9B=BF=E6=8D=A2=E6=99=AE=E9=80=9A?= =?UTF-8?q?=E5=AD=97=E4=BD=93=EF=BC=8C=E4=BF=9D=E7=95=99=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E5=AD=97=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GakumasLocalify/Hook.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/GakumasLocalify/Hook.cpp b/src/GakumasLocalify/Hook.cpp index d6ea711..d004c2c 100644 --- a/src/GakumasLocalify/Hook.cpp +++ b/src/GakumasLocalify/Hook.cpp @@ -519,6 +519,8 @@ namespace GakumasLocal::HookMain { "TMPro", "TMP_Text", "get_font"); static auto set_font = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll", "TMPro", "TMP_Text", "set_font"); + static auto get_name = Il2cppUtils::GetMethod("UnityEngine.CoreModule.dll", + "UnityEngine", "Object", "get_name"); // static auto set_fontMaterial = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll", // "TMPro", "TMP_Text", "set_fontMaterial"); // static auto ForceMeshUpdate = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll", @@ -532,21 +534,32 @@ namespace GakumasLocal::HookMain { static auto UpdateFontAssetData = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll", "TMPro", "TMP_FontAsset", "UpdateFontAssetData"); + auto fontAsset = get_font->Invoke(TMP_Textself); + if (!fontAsset) { + Log::Error("UpdateFont: fontAsset is null."); + return; + } + + // 检查字体名称,跳过 CampusAlphanumeric 系列字体 + auto fontAssetName = get_name->Invoke(fontAsset); + if (fontAssetName) { + std::string fontName = fontAssetName->ToString(); + std::transform(fontName.begin(), fontName.end(), fontName.begin(), ::tolower); + if (fontName.find("campusalphanumeric") != std::string::npos) { + return; // 保持原版数字字体 + } + } + auto newFont = GetReplaceFont(); if (!newFont) return; - auto fontAsset = get_font->Invoke(TMP_Textself); - if (fontAsset) { - set_sourceFontFile->Invoke(fontAsset, newFont); - if (!updatedFontPtrs.contains(fontAsset)) { - updatedFontPtrs.emplace(fontAsset); - UpdateFontAssetData->Invoke(fontAsset); - } - if (updatedFontPtrs.size() > 200) updatedFontPtrs.clear(); - } - else { - Log::Error("UpdateFont: fontAsset is null."); + set_sourceFontFile->Invoke(fontAsset, newFont); + if (!updatedFontPtrs.contains(fontAsset)) { + updatedFontPtrs.emplace(fontAsset); + UpdateFontAssetData->Invoke(fontAsset); } + if (updatedFontPtrs.size() > 200) updatedFontPtrs.clear(); + set_font->Invoke(TMP_Textself, fontAsset); // auto fontMaterial = get_material->Invoke(fontAsset);