diff --git a/src/d3dhook.cpp b/src/d3dhook.cpp index 352907c..0738a01 100644 --- a/src/d3dhook.cpp +++ b/src/d3dhook.cpp @@ -112,6 +112,19 @@ void D3dHook::ProcessFrame(void* ptr) { ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); } + + if (FontMgr::IsFontReloadRequired()) + { + FontMgr::ReloadAll(); + if (gRenderer == Render_DirectX9) + { + ImGui_ImplDX9_InvalidateDeviceObjects(); + } + else + { + ImGui_ImplDX11_InvalidateDeviceObjects(); + } + } } else { diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 51b8668..0a4315a 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -87,7 +87,8 @@ void MenuThread(void* param) bool modloader = GetModuleHandle("modloader.asi"); const char *path = PLUGIN_PATH((char*)""); Log::Print("Install location: {}", modloader && strstr(path, "modloader") ? "Modloader" : "Game directory"); - Log::Print("CLEO installed: {}", GetModuleHandle("cleo.asi") || GetModuleHandle("cleo_redux.asi") ? "True" : "False"); + Log::Print("Font support package: {}", FontMgr::IsSupportPackageInstalled() ? "True" : "False"); + Log::Print("\nCLEO installed: {}", GetModuleHandle("cleo.asi") || GetModuleHandle("cleo_redux.asi") ? "True" : "False"); Log::Print("FLA installed: {}", GetModuleHandle("$fastman92limitAdjuster.asi") ? "True" : "False"); Log::Print("Mixsets installed: {}", GetModuleHandle("MixSets.asi") ? "True" : "False"); Log::Print("Modloader installed: {}", modloader ? "True" : "False"); diff --git a/src/fontmgr.cpp b/src/fontmgr.cpp index 7b9db04..afd54e6 100644 --- a/src/fontmgr.cpp +++ b/src/fontmgr.cpp @@ -51,7 +51,9 @@ ImFont* FontMgr::Load(const char* fontID, const char* path, float fontMul) void FontMgr::UnloadAll() { - ImGui::GetIO().Fonts->Clear(); + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->Clear(); + io.Fonts->ClearFonts(); } void FontMgr::ReloadAll() @@ -66,11 +68,12 @@ void FontMgr::ReloadAll() } io.FontDefault = Get("text"); io.Fonts->Build(); + m_bFontReloadRequired = false; } void FontMgr::Process() { - if (curState != eStates::Idle) + if (curState == eStates::Idle) { return; } @@ -83,10 +86,21 @@ void FontMgr::Process() Util::SetMessage(TEXT("Updater.Failed")); return; } - + + m_bFontReloadRequired = true; curState = eStates::Idle; } +bool FontMgr::IsSupportPackageInstalled() +{ + return std::filesystem::file_size(MENU_DATA_PATH("fonts/text.ttf")) > 1000000; // 1 MB +} + +bool FontMgr::IsFontReloadRequired() +{ + return m_bFontReloadRequired; +} + void FontMgr::StartOptionalFontDownload() { if (curState == eStates::Idle) diff --git a/src/fontmgr.h b/src/fontmgr.h index 64a870c..051e234 100644 --- a/src/fontmgr.h +++ b/src/fontmgr.h @@ -23,6 +23,7 @@ private: }; static inline std::vector m_vecFonts; static inline eStates curState = eStates::Idle; + static inline bool m_bFontReloadRequired = false; public: FontMgr() = delete; @@ -49,6 +50,12 @@ public: // Downloads optional font package static void StartOptionalFontDownload(); + + // Returns true if font support package is already installed + static bool IsSupportPackageInstalled(); + + // Returns true if font needs to be reloaded + static bool IsFontReloadRequired(); }; diff --git a/src/menu.cpp b/src/menu.cpp index e3de26d..c63126e 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -27,10 +27,9 @@ void Menu::ShowPage() { static int selected = Locale::GetCurrentLocaleIndex(); static std::vector& vec = Locale::GetLocaleList(); - static size_t fontSz = std::filesystem::file_size(MENU_DATA_PATH("fonts/text.ttf")); if (Locale::GetLocaleList()[Locale::GetCurrentLocaleIndex()] == "Chinese" - && fontSz < 1000000) // Normal font size is < 1 MB + && !FontMgr::IsSupportPackageInstalled()) { ImGui::Spacing(); ImGui::TextWrapped("Font support package is required to display this language! This may take a while depending on your connection.");