From cca5a774ab3a739cc5e2f89b4e42171be1a805b0 Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Tue, 3 Oct 2023 11:08:45 -0700 Subject: [PATCH] Fix a long-standing icon bug - Also switch some struct things around --- FFXIVPlugin/Game/Managers/HotbarManager.cs | 16 ++++++------- FFXIVPlugin/Game/Managers/IconManager.cs | 23 ++++++++++++------- .../Server/Controllers/HotbarController.cs | 2 +- .../Server/Controllers/IconController.cs | 4 ++-- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/FFXIVPlugin/Game/Managers/HotbarManager.cs b/FFXIVPlugin/Game/Managers/HotbarManager.cs index ba18edb..72c3c16 100644 --- a/FFXIVPlugin/Game/Managers/HotbarManager.cs +++ b/FFXIVPlugin/Game/Managers/HotbarManager.cs @@ -39,13 +39,11 @@ public static unsafe void PulseHotbarSlot(int hotbarId, int slotId) { // Handle the main hotbar, which is a bit interesting as it can behave oddly at times. var mainBarName = isCrossHotbar ? "_ActionCross" : "_ActionBar"; - var mainBarPtr = Injections.GameGui.GetAddonByName(mainBarName); + var mainBar = (AddonActionBarBase*) Injections.GameGui.GetAddonByName(mainBarName); - if (mainBarPtr != nint.Zero) { - var activeHotbarId = *(byte*) (mainBarPtr + 0x23C); // offset to RaptureHotbarId - - if (activeHotbarId == hotbarId) { - SafePulseBar((AddonActionBarBase*) mainBarPtr, slotId); + if (mainBar != null) { + if (mainBar->RaptureHotbarId == hotbarId) { + SafePulseBar(mainBar, slotId); } } else { Injections.PluginLog.Debug($"Couldn't find main hotbar addon {mainBarName}!"); @@ -54,10 +52,10 @@ public static unsafe void PulseHotbarSlot(int hotbarId, int slotId) { // And handle any extra visible normal hotbars if (!isCrossHotbar) { var actionBarName = $"_ActionBar{hotbarId:00}"; - var actionBarPtr = Injections.GameGui.GetAddonByName(actionBarName); + var actionBar = (AddonActionBarBase*) Injections.GameGui.GetAddonByName(actionBarName); - if (actionBarPtr != nint.Zero) { - SafePulseBar((AddonActionBarBase*) actionBarPtr, slotId); + if (actionBar != null) { + SafePulseBar(actionBar, slotId); } else { Injections.PluginLog.Debug($"Couldn't find hotbar addon {actionBarName}"); } diff --git a/FFXIVPlugin/Game/Managers/IconManager.cs b/FFXIVPlugin/Game/Managers/IconManager.cs index 1e343a6..f34a2cf 100644 --- a/FFXIVPlugin/Game/Managers/IconManager.cs +++ b/FFXIVPlugin/Game/Managers/IconManager.cs @@ -12,9 +12,16 @@ namespace XIVDeck.FFXIVPlugin.Game.Managers; public static class IconManager { private const string IconFileFormat = "ui/icon/{0:D3}000/{1}{2:D6}{3}.tex"; - private static string GetIconPath(string lang, int iconId, bool hq = false, bool highres = false, bool forceOriginal = false) { + private static string GetIconPath(string lang, int iconId, bool highres = false, bool forceOriginal = false) { + var useHqIcon = false; + + if (iconId > 1_000_000) { + useHqIcon = true; + iconId -= 1_000_000; + } + var path = string.Format(IconFileFormat, - iconId / 1000, (hq ? "hq/" : "") + lang, iconId, highres ? "_hr1" : ""); + iconId / 1000, (useHqIcon ? "hq/" : "") + lang, iconId, highres ? "_hr1" : ""); if (PenumbraIPC.Instance is {Enabled: true} && !forceOriginal && XIVDeckPlugin.Instance.Configuration.UsePenumbraIPC) path = PenumbraIPC.Instance.ResolvePenumbraPath(path); @@ -22,13 +29,13 @@ private static string GetIconPath(string lang, int iconId, bool hq = false, bool return path; } - public static TexFile? GetIcon(string lang, int iconId, bool hq = false, bool highres = false) { + public static TexFile? GetIcon(string lang, int iconId, bool highres = false) { TexFile? texFile; if (lang.Length > 0 && !lang.EndsWith("/")) lang += "/"; - var texPath = GetIconPath(lang, iconId, hq, true); + var texPath = GetIconPath(lang, iconId, true); if (Path.IsPathRooted(texPath)) { Injections.PluginLog.Verbose($"Using on-disk asset {texPath}"); @@ -47,17 +54,17 @@ private static string GetIconPath(string lang, int iconId, bool hq = false, bool switch (texFile) { case null when lang.Length > 0: Injections.PluginLog.Debug($"Couldn't get lang-specific icon for {texPath}, falling back to no-lang"); - return GetIcon(string.Empty, iconId, hq, true); + return GetIcon(string.Empty, iconId, true); case null when highres: Injections.PluginLog.Debug($"Couldn't get highres icon for {texPath}, falling back to lowres"); - return GetIcon(lang, iconId, hq); + return GetIcon(lang, iconId); default: return texFile; } } - public static string GetIconAsPngString(int iconId, bool hq = false) { - var icon = GetIcon("", iconId, hq, true) ?? GetIcon("", 0, hq, true)!; + public static string GetIconAsPngString(int iconId) { + var icon = GetIcon("", iconId, true) ?? GetIcon("", 0, true)!; return "data:image/png;base64," + Convert.ToBase64String(icon.GetImage().ConvertToPng()); } diff --git a/FFXIVPlugin/Server/Controllers/HotbarController.cs b/FFXIVPlugin/Server/Controllers/HotbarController.cs index b057368..3f37d4f 100644 --- a/FFXIVPlugin/Server/Controllers/HotbarController.cs +++ b/FFXIVPlugin/Server/Controllers/HotbarController.cs @@ -34,7 +34,7 @@ public unsafe SerializableHotbarSlot GetHotbarSlot(int hotbarId, int slotId) { IconId = iconId, SlotType = hotbarItem->CommandType, CommandId = (int) hotbarItem->CommandId, - IconData = IconManager.GetIconAsPngString(iconId % 1000000, iconId >= 1000000) + IconData = IconManager.GetIconAsPngString(iconId) }; } diff --git a/FFXIVPlugin/Server/Controllers/IconController.cs b/FFXIVPlugin/Server/Controllers/IconController.cs index e396c27..bb7912f 100644 --- a/FFXIVPlugin/Server/Controllers/IconController.cs +++ b/FFXIVPlugin/Server/Controllers/IconController.cs @@ -12,10 +12,10 @@ namespace XIVDeck.FFXIVPlugin.Server.Controllers; public class IconController : WebApiController { [Route(HttpVerbs.Get, "/{iconId}")] - public async Task GetIcon(int iconId, [QueryField] bool hq = false) { + public async Task GetIcon(int iconId) { this.HttpContext.Response.ContentType = "image/png"; - var icon = IconManager.GetIcon("", iconId, hq, true); + var icon = IconManager.GetIcon("", iconId, true); if (icon == null) throw HttpException.NotFound($"Icon {iconId} was not found.");