From fe187789400372dfa1b7dc2bed13386ebda8d939 Mon Sep 17 00:00:00 2001 From: Jackson <9527380+Jaksuhn@users.noreply.github.com> Date: Thu, 11 Jul 2024 13:48:01 +0200 Subject: [PATCH] isaddonready fix --- .../Grammar/Commands/CallbackCommand.cs | 12 ++++++++-- .../Grammar/Commands/NativeCommand.cs | 14 ------------ SomethingNeedDoing/Misc/Changelog.cs | 4 ++++ .../Misc/Commands/AddonCommands.cs | 22 +++---------------- 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/SomethingNeedDoing/Grammar/Commands/CallbackCommand.cs b/SomethingNeedDoing/Grammar/Commands/CallbackCommand.cs index f3721daa..a7803e62 100644 --- a/SomethingNeedDoing/Grammar/Commands/CallbackCommand.cs +++ b/SomethingNeedDoing/Grammar/Commands/CallbackCommand.cs @@ -94,8 +94,16 @@ public async override Task Execute(ActiveMacro macro, CancellationToken token) { unsafe { - if (TryGetAddonByName(addon, out var addonArg) && IsAddonReady(addonArg)) - Callback.Fire(addonArg, updateState, [.. valueArgs]); + if (TryGetAddonByName(addon, out var addonArg)) + { + if (IsAddonReady(addonArg)) + Callback.Fire(addonArg, updateState, [.. valueArgs]); + else + { + if (Service.Configuration.StopMacroIfAddonNotFound) + throw new MacroCommandError($"Addon {addon} not ready."); + } + } else { if (Service.Configuration.StopMacroIfAddonNotFound) diff --git a/SomethingNeedDoing/Grammar/Commands/NativeCommand.cs b/SomethingNeedDoing/Grammar/Commands/NativeCommand.cs index 8f550125..fc607fae 100644 --- a/SomethingNeedDoing/Grammar/Commands/NativeCommand.cs +++ b/SomethingNeedDoing/Grammar/Commands/NativeCommand.cs @@ -5,23 +5,10 @@ namespace SomethingNeedDoing.Grammar.Commands; -/// -/// A command handled by the game. -/// internal class NativeCommand : MacroCommand { - /// - /// Initializes a new instance of the class. - /// - /// Original text. - /// Wait value. private NativeCommand(string text, WaitModifier wait) : base(text, wait) { } - /// - /// Parse the text as a command. - /// - /// Text to parse. - /// A parsed command. public static NativeCommand Parse(string text) { _ = WaitModifier.TryParse(ref text, out var waitModifier); @@ -29,7 +16,6 @@ public static NativeCommand Parse(string text) return new NativeCommand(text, waitModifier); } - /// public override async Task Execute(ActiveMacro macro, CancellationToken token) { Svc.Log.Debug($"Executing: {Text}"); diff --git a/SomethingNeedDoing/Misc/Changelog.cs b/SomethingNeedDoing/Misc/Changelog.cs index fc5f91dc..66bce749 100644 --- a/SomethingNeedDoing/Misc/Changelog.cs +++ b/SomethingNeedDoing/Misc/Changelog.cs @@ -19,6 +19,10 @@ static void DisplayChangelog(string date, string changes, bool separator = true) using var font = ImRaii.PushFont(UiBuilder.MonoFont); + DisplayChangelog( + "2024-07-11", + "- Fixed IsAddonReady erroneously returning true.\n"); + DisplayChangelog( "2024-07-07", "- Removed the alt /item option.\n" + diff --git a/SomethingNeedDoing/Misc/Commands/AddonCommands.cs b/SomethingNeedDoing/Misc/Commands/AddonCommands.cs index b128c415..e3b0adc9 100644 --- a/SomethingNeedDoing/Misc/Commands/AddonCommands.cs +++ b/SomethingNeedDoing/Misc/Commands/AddonCommands.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Reflection; using System.Runtime.InteropServices; +using System.Windows.Forms; namespace SomethingNeedDoing.Misc.Commands; @@ -89,15 +90,8 @@ public unsafe int GetDDPassageProgress() return 0; } - public unsafe bool IsAddonVisible(string addonName) - { - var ptr = Svc.GameGui.GetAddonByName(addonName, 1); - if (ptr == nint.Zero) - return false; - - var addon = (AtkUnitBase*)ptr; - return addon->IsVisible; - } + public unsafe bool IsAddonVisible(string addonName) => GenericHelpers.TryGetAddonByName(addonName, out var addon) && addon->IsVisible; + public unsafe bool IsAddonReady(string addonName) => GenericHelpers.TryGetAddonByName(addonName, out var addon) && GenericHelpers.IsAddonReady(addon); public unsafe bool IsNodeVisible(string addonName, params int[] ids) { @@ -150,16 +144,6 @@ public void GetClicks() return sibNode != null ? GetNodeByIDChain(sibNode, ids) : null; } - public unsafe bool IsAddonReady(string addonName) - { - var ptr = Svc.GameGui.GetAddonByName(addonName, 1); - if (ptr == nint.Zero) - return false; - - var addon = (AtkUnitBase*)ptr; - return addon->UldManager.LoadedState == AtkLoadState.Loaded; - } - public unsafe string GetToastNodeText(int index, params int[] nodeNumbers) { var ptr = (AtkUnitBase*)Svc.GameGui.GetAddonByName("_WideText", index);