Skip to content

Commit

Permalink
isaddonready fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaksuhn committed Jul 11, 2024
1 parent 547ac54 commit fe18778
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 35 deletions.
12 changes: 10 additions & 2 deletions SomethingNeedDoing/Grammar/Commands/CallbackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,16 @@ public async override Task Execute(ActiveMacro macro, CancellationToken token)
{
unsafe
{
if (TryGetAddonByName<AtkUnitBase>(addon, out var addonArg) && IsAddonReady(addonArg))
Callback.Fire(addonArg, updateState, [.. valueArgs]);
if (TryGetAddonByName<AtkUnitBase>(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)
Expand Down
14 changes: 0 additions & 14 deletions SomethingNeedDoing/Grammar/Commands/NativeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,17 @@

namespace SomethingNeedDoing.Grammar.Commands;

/// <summary>
/// A command handled by the game.
/// </summary>
internal class NativeCommand : MacroCommand
{
/// <summary>
/// Initializes a new instance of the <see cref="NativeCommand"/> class.
/// </summary>
/// <param name="text">Original text.</param>
/// <param name="wait">Wait value.</param>
private NativeCommand(string text, WaitModifier wait) : base(text, wait) { }

/// <summary>
/// Parse the text as a command.
/// </summary>
/// <param name="text">Text to parse.</param>
/// <returns>A parsed command.</returns>
public static NativeCommand Parse(string text)
{
_ = WaitModifier.TryParse(ref text, out var waitModifier);

return new NativeCommand(text, waitModifier);
}

/// <inheritdoc/>
public override async Task Execute(ActiveMacro macro, CancellationToken token)
{
Svc.Log.Debug($"Executing: {Text}");
Expand Down
4 changes: 4 additions & 0 deletions SomethingNeedDoing/Misc/Changelog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
22 changes: 3 additions & 19 deletions SomethingNeedDoing/Misc/Commands/AddonCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace SomethingNeedDoing.Misc.Commands;

Expand Down Expand Up @@ -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<AtkUnitBase>(addonName, out var addon) && addon->IsVisible;
public unsafe bool IsAddonReady(string addonName) => GenericHelpers.TryGetAddonByName<AtkUnitBase>(addonName, out var addon) && GenericHelpers.IsAddonReady(addon);

public unsafe bool IsNodeVisible(string addonName, params int[] ids)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fe18778

Please sign in to comment.