Add font reloading button.

This commit is contained in:
Ottermandias 2022-05-26 13:28:50 +02:00
parent 4189d240de
commit 46c8b811ad
2 changed files with 67 additions and 0 deletions

View file

@ -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<AtkModule*, bool, bool, void> 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 ];
}
}

View file

@ -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();
}
}
}
}