From 46c8b811ad9d59fd0262956b7e60111e8d0373c3 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 26 May 2022 13:28:50 +0200 Subject: [PATCH] Add font reloading button. --- Penumbra/Interop/FontReloader.cs | 56 +++++++++++++++++++ .../UI/ConfigWindow.SettingsTab.Advanced.cs | 11 ++++ 2 files changed, 67 insertions(+) create mode 100644 Penumbra/Interop/FontReloader.cs diff --git a/Penumbra/Interop/FontReloader.cs b/Penumbra/Interop/FontReloader.cs new file mode 100644 index 00000000..c962ae37 --- /dev/null +++ b/Penumbra/Interop/FontReloader.cs @@ -0,0 +1,56 @@ +using Dalamud.Logging; +using FFXIVClientStructs.FFXIV.Client.System.Framework; +using FFXIVClientStructs.FFXIV.Component.GUI; + +namespace Penumbra.Interop; + +// Handle font reloading via +public static unsafe class FontReloader +{ + private static readonly AtkModule* AtkModule = null; + private static readonly delegate* unmanaged ReloadFontsFunc = null; + + public static bool Valid + => ReloadFontsFunc != null; + + public static void Reload() + { + if( Valid ) + { + ReloadFontsFunc( AtkModule, false, true ); + } + else + { + PluginLog.Error( "Could not reload fonts, function could not be found." ); + } + } + + static FontReloader() + { + if( ReloadFontsFunc != null ) + { + return; + } + + var framework = Framework.Instance(); + if( framework == null ) + { + return; + } + + var uiModule = framework->GetUiModule(); + if( uiModule == null ) + { + return; + } + + var atkModule = uiModule->GetRaptureAtkModule(); + if( atkModule == null ) + { + return; + } + + AtkModule = &atkModule->AtkModule; + ReloadFontsFunc = ( ( delegate* unmanaged< AtkModule*, bool, bool, void >* )AtkModule->vtbl )[ 43 ]; + } +} \ No newline at end of file diff --git a/Penumbra/UI/ConfigWindow.SettingsTab.Advanced.cs b/Penumbra/UI/ConfigWindow.SettingsTab.Advanced.cs index dd3a0f01..d992f8ff 100644 --- a/Penumbra/UI/ConfigWindow.SettingsTab.Advanced.cs +++ b/Penumbra/UI/ConfigWindow.SettingsTab.Advanced.cs @@ -1,8 +1,10 @@ +using System.Numerics; using Dalamud.Interface; using ImGuiNET; using OtterGui; using OtterGui.Raii; using Penumbra.GameData.ByteString; +using Penumbra.Interop; using Penumbra.UI.Classes; namespace Penumbra.UI; @@ -24,6 +26,7 @@ public partial class ConfigWindow DrawEnableDebugModeBox(); DrawEnableFullResourceLoggingBox(); DrawReloadResourceButton(); + DrawReloadFontsButton(); ImGui.NewLine(); } @@ -168,5 +171,13 @@ public partial class ConfigWindow ImGuiUtil.HoverTooltip( "Reload some specific files that the game keeps in memory at all times.\n" + "You usually should not need to do this." ); } + + private static void DrawReloadFontsButton() + { + if( ImGuiUtil.DrawDisabledButton( "Reload Fonts", Vector2.Zero, "Force the game to reload its font files.", !FontReloader.Valid ) ) + { + FontReloader.Reload(); + } + } } } \ No newline at end of file