diff --git a/Craftimizer/Utils/CSRecipeNote.cs b/Craftimizer/Utils/CSRecipeNote.cs new file mode 100644 index 0000000..7d26272 --- /dev/null +++ b/Craftimizer/Utils/CSRecipeNote.cs @@ -0,0 +1,15 @@ +using FFXIVClientStructs.FFXIV.Client.Game.UI; +using System.Runtime.InteropServices; + +namespace Craftimizer.Utils; + +[StructLayout(LayoutKind.Explicit, Size = 2880)] +public unsafe struct CSRecipeNote +{ + [FieldOffset(0x118)] public ushort ActiveCraftRecipeId; + + public static CSRecipeNote* Instance() + { + return (CSRecipeNote*)RecipeNote.Instance(); + } +} diff --git a/Craftimizer/Windows/SynthHelper.cs b/Craftimizer/Windows/SynthHelper.cs index 7315b35..bc4afc9 100644 --- a/Craftimizer/Windows/SynthHelper.cs +++ b/Craftimizer/Windows/SynthHelper.cs @@ -14,7 +14,6 @@ using Dalamud.Utility; using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.FFXIV.Client.UI; -using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Client.UI.Shell; using ImGuiNET; using System; @@ -161,10 +160,9 @@ public sealed unsafe class SynthHelper : Window, IDisposable if (!Service.Configuration.EnableSynthHelper) return false; - var agent = AgentRecipeNote.Instance(); - var recipeId = (ushort)agent->ActiveCraftRecipeId; + var recipeId = CSRecipeNote.Instance()->ActiveCraftRecipeId; - if (agent->ActiveCraftRecipeId == 0) + if (recipeId == 0) { RecipeData = null; return false; @@ -173,7 +171,10 @@ public sealed unsafe class SynthHelper : Window, IDisposable Addon = (AddonSynthesis*)Service.GameGui.GetAddonByName("Synthesis"); if (Addon == null) + { + RecipeData = null; return false; + } // Check if Synthesis addon is visible if (Addon->AtkUnitBase.WindowNode == null) @@ -198,7 +199,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable } } - if (RecipeData?.RecipeId != agent->ActiveCraftRecipeId) + if (RecipeData?.RecipeId != recipeId) OnStartCrafting(recipeId); if (IsRecalculateQueued) diff --git a/Simulator/SimulationState.cs b/Simulator/SimulationState.cs index 2fdc631..44ad75a 100644 --- a/Simulator/SimulationState.cs +++ b/Simulator/SimulationState.cs @@ -24,9 +24,9 @@ public record struct SimulationState 17, 18, 18, 18, 19, 19, 20, 20, 21, 22, 23, 24, 26, 28, 31, 34, 38, 42, 47, 52, 58, 64, 68, 71, 74, 76, 78, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 94, 96, 98, 100 ]; - public readonly int HQPercent => HQPercentTable[(int)Math.Clamp((float)Quality / Input.Recipe.MaxQuality * 100, 0, 100)]; + public readonly int HQPercent => HQPercentTable[(int)Math.Clamp((float)Quality / (Input?.Recipe.MaxQuality ?? 1) * 100, 0, 100)]; public readonly int Collectability => Math.Max(Quality / 10, 1); - public readonly int MaxCollectability => Math.Max(Input.Recipe.MaxQuality / 10, 1); + public readonly int MaxCollectability => Math.Max((Input?.Recipe.MaxQuality ?? 1) / 10, 1); public readonly bool IsFirstStep => StepCount == 0;