From 3c44a4360195a6199fcf0dd5afc69a4243c55b36 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Fri, 15 Apr 2022 22:37:26 +0900 Subject: [PATCH 1/4] Autodetect installed expac version on test launching with injector --- Dalamud.Injector/EntryPoint.cs | 72 ++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/Dalamud.Injector/EntryPoint.cs b/Dalamud.Injector/EntryPoint.cs index 829a15429..2462176a8 100644 --- a/Dalamud.Injector/EntryPoint.cs +++ b/Dalamud.Injector/EntryPoint.cs @@ -189,6 +189,50 @@ namespace Dalamud.Injector } } + private static Process GetProcessFromExecuting(string gamePath) + { + var gameVersion = File.ReadAllText(Path.Combine(Directory.GetParent(gamePath).FullName, "ffxivgame.ver")); + var sqpackPath = Path.Combine(Directory.GetParent(gamePath).FullName, "sqpack"); + var maxEntitledExpansionId = 0; + while (File.Exists(Path.Combine(sqpackPath, $"ex{maxEntitledExpansionId + 1}", $"ex{maxEntitledExpansionId + 1}.ver"))) + maxEntitledExpansionId++; + + var process = Process.Start(gamePath, new string[] + { + "DEV.TestSID=0", + "DEV.UseSqPack=1", + "DEV.DataPathType=1", + "DEV.LobbyHost01=127.0.0.1", + "DEV.LobbyPort01=54994", + "DEV.LobbyHost02=127.0.0.2", + "DEV.LobbyPort02=54994", + "DEV.LobbyHost03=127.0.0.3", + "DEV.LobbyPort03=54994", + "DEV.LobbyHost04=127.0.0.4", + "DEV.LobbyPort04=54994", + "DEV.LobbyHost05=127.0.0.5", + "DEV.LobbyPort05=54994", + "DEV.LobbyHost06=127.0.0.6", + "DEV.LobbyPort06=54994", + "DEV.LobbyHost07=127.0.0.7", + "DEV.LobbyPort07=54994", + "DEV.LobbyHost08=127.0.0.8", + "DEV.LobbyPort08=54994", + "DEV.LobbyHost09=127.0.0.9", + "DEV.LobbyPort09=54994", + "SYS.Region=0", + "language=1", + $"ver={gameVersion}", + $"DEV.MaxEntitledExpansionID={maxEntitledExpansionId}", + "DEV.GMServerHost=127.0.0.100", + "DEV.GameQuitMessageBox=0", + }); + + Thread.Sleep(1000); + + return process; + } + private static Process? GetProcess(string? arg) { Process process = null; @@ -196,7 +240,15 @@ namespace Dalamud.Injector var pid = -1; if (arg != default) { - pid = int.Parse(arg); + try + { + pid = int.Parse(arg); + } + catch (FormatException) + { + if (File.Exists(arg)) + return GetProcessFromExecuting(arg); + } } switch (pid) @@ -223,22 +275,8 @@ namespace Dalamud.Injector break; case -2: - var exePath = "C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\ffxiv_dx11.exe"; - var exeArgs = new StringBuilder() - .Append("DEV.TestSID=0 DEV.UseSqPack=1 DEV.DataPathType=1 ") - .Append("DEV.LobbyHost01=127.0.0.1 DEV.LobbyPort01=54994 ") - .Append("DEV.LobbyHost02=127.0.0.1 DEV.LobbyPort02=54994 ") - .Append("DEV.LobbyHost03=127.0.0.1 DEV.LobbyPort03=54994 ") - .Append("DEV.LobbyHost04=127.0.0.1 DEV.LobbyPort04=54994 ") - .Append("DEV.LobbyHost05=127.0.0.1 DEV.LobbyPort05=54994 ") - .Append("DEV.LobbyHost06=127.0.0.1 DEV.LobbyPort06=54994 ") - .Append("DEV.LobbyHost07=127.0.0.1 DEV.LobbyPort07=54994 ") - .Append("DEV.LobbyHost08=127.0.0.1 DEV.LobbyPort08=54994 ") - .Append("SYS.Region=0 language=1 version=1.0.0.0 ") - .Append("DEV.MaxEntitledExpansionID=2 DEV.GMServerHost=127.0.0.1 DEV.GameQuitMessageBox=0").ToString(); - process = Process.Start(exePath, exeArgs); - Thread.Sleep(1000); - break; + return GetProcessFromExecuting("C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\ffxiv_dx11.exe"); + default: try { From f53c0fb1e3eaae8c1ce0a1e495152701dfac2721 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Fri, 15 Apr 2022 23:05:33 +0900 Subject: [PATCH 2/4] Overwrite all relevant information after loading scaled fonts --- Dalamud/Interface/GameFonts/GameFontManager.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dalamud/Interface/GameFonts/GameFontManager.cs b/Dalamud/Interface/GameFonts/GameFontManager.cs index a376f508b..cb5426f48 100644 --- a/Dalamud/Interface/GameFonts/GameFontManager.cs +++ b/Dalamud/Interface/GameFonts/GameFontManager.cs @@ -189,6 +189,8 @@ namespace Dalamud.Interface.GameFonts font->FontSize /= fontScale; font->Ascent /= fontScale; font->Descent /= fontScale; + for (int i = 0, i_ = font->ConfigDataCount; i < i_; i++) + font->ConfigData[i].SizePixels /= fontScale; var glyphs = (ImFontGlyphReal*)font->Glyphs.Data; for (int i = 0, i_ = font->Glyphs.Size; i < i_; i++) { From 42f199a04061c70a845e88f83b95324945fbd444 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Fri, 15 Apr 2022 23:06:29 +0900 Subject: [PATCH 3/4] On low res font conditions are met, make plugin requested font sizes smaller /only/ if it's bigger than current limits --- .../Interface/Internal/InterfaceManager.cs | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index 21b5de793..cf53721c5 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -596,6 +596,29 @@ namespace Dalamud.Interface.Internal private unsafe class TargetFontModification : IDisposable { + /// + /// Initializes a new instance of the class. + /// Constructs new target font modification information, assuming that AXIS fonts will not be applied. + /// + /// Name of the font to write to ImGui font information. + /// Target font size in pixels, which will not be considered for further scaling. + internal TargetFontModification(string name, float sizePx) + { + this.Name = name; + this.Axis = AxisMode.Suppress; + this.TargetSizePx = sizePx; + this.Scale = 1; + this.SourceAxis = null; + } + + /// + /// Initializes a new instance of the class. + /// Constructs new target font modification information. + /// + /// Name of the font to write to ImGui font information. + /// Whether and how to use AXIS fonts. + /// Target font size in pixels, which will not be considered for further scaling. + /// Font scale to be referred for loading AXIS font of appropriate size. internal TargetFontModification(string name, AxisMode axis, float sizePx, float scale) { this.Name = name; @@ -630,6 +653,10 @@ namespace Dalamud.Interface.Internal } } + /// + /// Loads font for use in ImGui text functions. + /// + /// If non-zero, then glyphs will be loaded in smaller resolution to make all glyphs fit into given constraints. private unsafe void SetupFonts(int scaler = 0) { var gameFontManager = Service.Get(); @@ -817,8 +844,21 @@ namespace Dalamud.Interface.Internal config.OversampleV = 1; var name = Encoding.UTF8.GetString((byte*)config.Name.Data, config.Name.Count).TrimEnd('\0'); - this.loadedFontInfo[config.DstFont.NativePtr] = new($"PluginRequest({name})", TargetFontModification.AxisMode.Suppress, config.SizePixels, 1); - config.SizePixels = (disableBigFonts ? DefaultFontSizePx : config.SizePixels) * fontLoadScale; + + // While the font will be loaded in the scaled size after FontScale is applied, the font will be treated as having the requested size when used from plugins. + this.loadedFontInfo[config.DstFont.NativePtr] = new($"PluginRequest({name})", config.SizePixels); + + if (disableBigFonts) + { + // If a plugin has requested a font size that is bigger than current restrictions, load it scaled down. + // After loading glyphs onto font atlas, font information will be modified to make it look like the font of original size has been loaded. + if (config.SizePixels > DefaultFontSizePx * fontLoadScale) + config.SizePixels = DefaultFontSizePx * fontLoadScale; + } + else + { + config.SizePixels = config.SizePixels * fontLoadScale; + } } ioFonts.Build(); From 5fa750750b99a0bdf0bfc1e3300c38ba5e2287e0 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Fri, 15 Apr 2022 23:46:12 +0900 Subject: [PATCH 4/4] Fix dealing with MergeMode for plugin-requested fonts --- .../Interface/Internal/InterfaceManager.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index cf53721c5..10e8309c4 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -845,8 +845,26 @@ namespace Dalamud.Interface.Internal var name = Encoding.UTF8.GetString((byte*)config.Name.Data, config.Name.Count).TrimEnd('\0'); - // While the font will be loaded in the scaled size after FontScale is applied, the font will be treated as having the requested size when used from plugins. - this.loadedFontInfo[config.DstFont.NativePtr] = new($"PluginRequest({name})", config.SizePixels); + // ImFont information is reflected only if corresponding ImFontConfig has MergeMode not set. + if (config.MergeMode) + { + if (!this.loadedFontInfo.ContainsKey(config.DstFont.NativePtr)) + { + Log.Warning("MergeMode specified for {0} but not found in loadedFontInfo. Skipping.", name); + continue; + } + } + else + { + if (this.loadedFontInfo.ContainsKey(config.DstFont.NativePtr)) + { + Log.Warning("MergeMode not specified for {0} but found in loadedFontInfo. Skipping.", name); + continue; + } + + // While the font will be loaded in the scaled size after FontScale is applied, the font will be treated as having the requested size when used from plugins. + this.loadedFontInfo[config.DstFont.NativePtr] = new($"PlReq({name})", config.SizePixels); + } if (disableBigFonts) {