diff --git a/src/hook.cpp b/src/hook.cpp index a99e7da9..34c8f22a 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -1399,11 +1399,7 @@ namespace bool (*Object_IsNativeObjectAlive)(void*); - void* TextCommon_Awake_orig; - void TextCommon_Awake_hook(void* _this) - { - reinterpret_cast(TextCommon_Awake_orig)(_this); - + void* getReplaceFont() { void* replaceFont{}; const auto& bundleHandle = GetBundleHandleByAssetName(std::get(g_replace_font).FontPath); if (std::holds_alternative(g_replace_font) && bundleHandle) @@ -1416,7 +1412,7 @@ namespace // AssetBundle 不会被干掉 if (Object_IsNativeObjectAlive(replaceFont)) { - goto FontAlive; + return replaceFont; } else { @@ -1435,8 +1431,16 @@ namespace std::wprintf(L"Cannot load asset font\n"); } } + return replaceFont; + } + + void* TextCommon_Awake_orig; + void TextCommon_Awake_hook(void* _this) + { + reinterpret_cast(TextCommon_Awake_orig)(_this); + + auto replaceFont = getReplaceFont(); - FontAlive: if (replaceFont) { Text_set_font(_this, replaceFont); @@ -1457,6 +1461,160 @@ namespace text_set_linespacing(_this, g_custom_font_linespacing); } + void* (*TMP_FontAsset_CreateFontAsset)(void* font); + void (*TMP_Text_set_font)(void* _this, void* fontAsset); + + void* TextMeshProUguiCommon_Awake_orig; + void TextMeshProUguiCommon_Awake_hook(void* _this) + { + static auto get_outlineWidth = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_Text", "get_outlineWidth", 0 + ) + ); + static auto set_outlineWidth = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_Text", "set_outlineWidth", 1 + ) + ); + static auto get_outlineColor = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_Text", "get_outlineColor", 0 + ) + ); + static auto set_outlineColor = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_Text", "set_outlineColor", 1 + ) + ); + + static auto SetOutlineThickness = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_Text", "SetOutlineThickness", 1 + ) + ); + static auto set_fontSize = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_Text", "set_fontSize", 1 + ) + ); + static auto get_fontSize = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_Text", "get_fontSize", 0 + ) + ); + + static auto u_get_OutlineColor = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "umamusume.dll", "Gallop", + "TextMeshProUguiCommon", "get_OutlineColor", 0 + ) + ); + static auto u_set_OutlineColor = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "umamusume.dll", "Gallop", + "TextMeshProUguiCommon", "set_OutlineColor", 1 + ) + ); + static auto u_get_OutlineSize = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "umamusume.dll", "Gallop", + "TextMeshProUguiCommon", "get_OutlineSize", 0 + ) + ); + static auto u_set_OutlineSize = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "umamusume.dll", "Gallop", + "TextMeshProUguiCommon", "set_OutlineSize", 1 + ) + ); + static auto UpdateOutline = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "umamusume.dll", "Gallop", + "TextMeshProUguiCommon", "UpdateOutline", 0 + ) + ); + + static auto set_sourceFontFile = reinterpret_cast( + il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_FontAsset", "set_sourceFontFile", 1 + ) + ); + + + auto origOutLineWidth = get_outlineWidth(_this); + auto origOutLineColor = get_outlineColor(_this); + auto origFontSize = get_fontSize(_this); + + auto u_OrigColor = u_get_OutlineColor(_this); + auto u_OrigSize = u_get_OutlineSize(_this); + + // printf("TextMeshProUguiCommon_Awake: \n"); + reinterpret_cast(TextMeshProUguiCommon_Awake_orig)(_this); + + auto replaceFont = getReplaceFont(); + if (replaceFont) { + auto newFont = TMP_FontAsset_CreateFontAsset(replaceFont); + TMP_Text_set_font(_this, newFont); + + SetOutlineThickness(_this, 0.5f); + set_fontSize(_this, origFontSize + g_custom_font_size_offset); + set_outlineWidth(_this, origOutLineWidth); + set_outlineColor(_this, origOutLineColor); + u_set_OutlineColor(_this, u_OrigColor); + u_set_OutlineSize(_this, u_OrigSize); + UpdateOutline(_this); + } + } + + void* AnText_UpdateText_orig; + void AnText_UpdateText_hook(void* _this) { + static auto AnText_klass = il2cpp_symbols::get_class_from_instance(_this); + static FieldInfo* fontStyle_field = il2cpp_class_get_field_from_name(AnText_klass, "_fontStyle"); + static FieldInfo* fontSize_field = il2cpp_class_get_field_from_name(AnText_klass, "_fontSize"); + static FieldInfo* lineSpace_field = il2cpp_class_get_field_from_name(AnText_klass, "_lineSpace"); + + il2cpp_symbols::write_field(_this, fontStyle_field, g_custom_font_style); + il2cpp_symbols::write_field(_this, fontSize_field, il2cpp_symbols::read_field(_this, fontSize_field) + g_custom_font_size_offset); + il2cpp_symbols::write_field(_this, lineSpace_field, g_custom_font_linespacing); + + reinterpret_cast(AnText_UpdateText_orig)(_this); + } + + void* AnRootManager_GetFont_orig; + void* AnRootManager_GetFont_hook(void* _this, Il2CppString* fontName, bool fromCommon) { + // wprintf(L"AnRootManager_GetFont: %ls, fromCommon: %d\n", fontName->start_char, fromCommon); + // return getReplaceFont(); + return reinterpret_cast(AnRootManager_GetFont_orig)(_this, fontName, fromCommon); + } + + void* AnGlobalData_GetFont_orig; + void* AnGlobalData_GetFont_hook(void* _this, Il2CppString* fontName) { + // fontTable_key: FOT-Humming Std D + // fontTable_key: FOT-RodinWanpaku Pro EB + // fontTable_key: FOT-Yuruka Std UB + // commonFontTable 啥都没有 + + auto replaceFont = getReplaceFont(); + // wprintf(L"AnGlobalData_GetFont: %ls\n", fontName->start_char); + return replaceFont ? replaceFont : reinterpret_cast(AnGlobalData_GetFont_orig)(_this, fontName); + // return reinterpret_cast(AnGlobalData_GetFont_orig)(_this, il2cpp_string_new("FOT-Humming Std D0")); + } + void* AnGlobalData_GetFontFromCommon_orig; + void* AnGlobalData_GetFontFromCommon_hook(void* _this, Il2CppString* fontName) { + // wprintf(L"AnGlobalData_GetFontFromCommon: %ls\n", fontName->start_char); + auto replaceFont = getReplaceFont(); + return replaceFont ? replaceFont : reinterpret_cast(AnGlobalData_GetFontFromCommon_orig)(_this, fontName); + } + bool get_need_fullscreen(Resolution_t& r) { bool need_fullscreen = false; auto screen_ratio = r.width / static_cast(r.height); @@ -3967,8 +4125,20 @@ namespace "umamusume.dll", "Gallop", "TextCommon", "Awake", 0 ); + const auto TextMeshProUguiCommon_Awake_addr = il2cpp_symbols::get_method_pointer( + "umamusume.dll", "Gallop", + "TextMeshProUguiCommon", "Awake", 0 + ); + TMP_FontAsset_CreateFontAsset = reinterpret_cast(il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_FontAsset", "CreateFontAsset", 1 + )); + TMP_Text_set_font = reinterpret_cast(il2cpp_symbols::get_method_pointer( + "Unity.TextMeshPro.dll", "TMPro", + "TMP_Text", "set_font", 1 + )); + - TextRubyDataClass = il2cpp_symbols::get_class("umamusume.dll", "", "TextRubyData"); TextRubyDataClass_DataArray = il2cpp_class_get_field_from_name(TextRubyDataClass, "DataArray"); @@ -4038,11 +4208,32 @@ namespace ) ); + //auto Unity_Text_set_font_addr = il2cpp_symbols::get_method_pointer( + // "UnityEngine.UI.dll", "UnityEngine.UI", + // "Text", "set_font", 1 + //); + + auto AnText_UpdateText_addr = il2cpp_symbols::get_method_pointer( + "Plugins.dll", "AnimateToUnity", + "AnText", "_UpdateText", 0 + ); + auto AnRootManager_GetFont_addr = il2cpp_symbols::get_method_pointer( + "Plugins.dll", "AnimateToUnity", + "AnRootManager", "_GetFont", 2 + ); + auto AnGlobalData_GetFont_addr = il2cpp_symbols::get_method_pointer( + "Plugins.dll", "AnimateToUnity", + "AnGlobalData", "_GetFont", 1 + ); + auto AnGlobalData_GetFontFromCommon_addr = il2cpp_symbols::get_method_pointer( + "Plugins.dll", "AnimateToUnity", + "AnGlobalData", "_GetFontFromCommon", 1 + ); + Text_set_font = reinterpret_cast( il2cpp_symbols::get_method_pointer( "UnityEngine.UI.dll", "UnityEngine.UI", - "Text", "set_font", 1 - ) + "Text", "set_font", 1) ); Text_set_horizontalOverflow = reinterpret_cast( @@ -4673,6 +4864,11 @@ namespace if (!std::holds_alternative(g_replace_font)) { ADD_HOOK(TextCommon_Awake, "Gallop.TextCommon::Awake at %p\n"); + ADD_HOOK(TextMeshProUguiCommon_Awake, "TextMeshProUguiCommon_Awake at %p\n"); + ADD_HOOK(AnText_UpdateText, "AnText_UpdateText at %p\n"); + ADD_HOOK(AnRootManager_GetFont, "AnRootManager_GetFont at %p\n"); + ADD_HOOK(AnGlobalData_GetFont, "AnGlobalData_GetFont at %p\n"); + ADD_HOOK(AnGlobalData_GetFontFromCommon, "AnGlobalData_GetFontFromCommon at %p\n"); ADD_HOOK(text_set_size, "Text.set_size at %p\n"); if (!g_replace_assets) { diff --git a/src/local/local.cpp b/src/local/local.cpp index 2dc776f5..f54ab3d4 100644 --- a/src/local/local.cpp +++ b/src/local/local.cpp @@ -102,9 +102,16 @@ namespace local } std::unique_lock lock(db_lock); - if (text_db.contains(hash)) - { - *result = &text_db[hash]; + if (const auto it = text_db.find(hash); it != text_db.end()) { + *result = &it->second; + /* + if (text_db[hash].compare("已解锁上限至最大") == 0) { + static auto environment_get_stacktrace = + reinterpret_cast(il2cpp_symbols::get_method_pointer("mscorlib.dll", "System", "Environment", "get_StackTrace", 0)); + + printf("catchText\n%ls\n\n", environment_get_stacktrace()->start_char); + } + */ return true; }