From 3c3d1441580f03ca6e0464b25c99043f99912d53 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Thu, 5 Oct 2023 21:56:12 +0200 Subject: [PATCH] Fix workshops not in Lavender Beds --- Workshoppa/Windows/MainWindow.cs | 18 ++++++++++++++---- Workshoppa/WorkshopPlugin.GameFunctions.cs | 9 ++++----- Workshoppa/WorkshopPlugin.cs | 8 ++++---- Workshoppa/Workshoppa.csproj | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Workshoppa/Windows/MainWindow.cs b/Workshoppa/Windows/MainWindow.cs index 0003cc6..3183ba4 100644 --- a/Workshoppa/Windows/MainWindow.cs +++ b/Workshoppa/Windows/MainWindow.cs @@ -94,8 +94,7 @@ internal sealed class MainWindow : Window $"Hold CTRL to remove this as craft. You have to manually use the fabrication station to cancel or finish this craft before you can continue using the queue."); ImGui.EndDisabled(); - if (!IsDiscipleOfHand) - ImGui.TextColored(ImGuiColors.DalamudRed, "You need to be a Disciple of the Hand to start crafting."); + ShowErrorConditions(); } else { @@ -119,8 +118,7 @@ internal sealed class MainWindow : Window State = ButtonState.Start; ImGui.EndDisabled(); - if (!IsDiscipleOfHand) - ImGui.TextColored(ImGuiColors.DalamudRed, "You need to be a Disciple of the Hand to start crafting."); + ShowErrorConditions(); } if (ImGui.BeginPopup(nameof(CheckMaterial))) @@ -262,6 +260,18 @@ internal sealed class MainWindow : Window completedForCurrentCraft[itemId] = quantity; } + private void ShowErrorConditions() + { + + if (!_plugin.WorkshopTerritories.Contains(_clientState.TerritoryType)) + ImGui.TextColored(ImGuiColors.DalamudRed, "You are not in the Company Workshop."); + else if (!NearFabricationStation) + ImGui.TextColored(ImGuiColors.DalamudRed, "You are not near a Farbrication Station."); + + if (!IsDiscipleOfHand) + ImGui.TextColored(ImGuiColors.DalamudRed, "You need to be a Disciple of the Hand to start crafting."); + } + public enum ButtonState { None, diff --git a/Workshoppa/WorkshopPlugin.GameFunctions.cs b/Workshoppa/WorkshopPlugin.GameFunctions.cs index 560ecd3..43774c3 100644 --- a/Workshoppa/WorkshopPlugin.GameFunctions.cs +++ b/Workshoppa/WorkshopPlugin.GameFunctions.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; -using System.Runtime.InteropServices; using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Memory; @@ -30,13 +29,13 @@ partial class WorkshopPlugin (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)obj.Address, false); } - private float GetDistanceToEventObject(int npcId, out GameObject? o) + private float GetDistanceToEventObject(IReadOnlyList npcIds, out GameObject? o) { foreach (var obj in _objectTable) { if (obj.ObjectKind == ObjectKind.EventObj) { - if (GetNpcId(obj) == npcId) + if (npcIds.Contains(GetNpcId(obj))) { o = obj; return Vector3.Distance(_clientState.LocalPlayer!.Position, obj.Position); @@ -48,9 +47,9 @@ partial class WorkshopPlugin return float.MaxValue; } - private int GetNpcId(GameObject obj) + private unsafe uint GetNpcId(GameObject obj) { - return Marshal.ReadInt32(obj.Address + 128); + return ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)obj.Address)->GetNpcID(); } private unsafe bool TryGetAddonByName(string addonName, out T* addonPtr) diff --git a/Workshoppa/WorkshopPlugin.cs b/Workshoppa/WorkshopPlugin.cs index b60a836..e996bec 100644 --- a/Workshoppa/WorkshopPlugin.cs +++ b/Workshoppa/WorkshopPlugin.cs @@ -16,8 +16,8 @@ namespace Workshoppa; [SuppressMessage("ReSharper", "UnusedType.Global")] public sealed partial class WorkshopPlugin : IDalamudPlugin { - private const int FabricationStationId = 0x1E98F4; - private readonly IReadOnlyList _workshopTerritories = new ushort[] { 423, 424, 425, 653, 984 }.AsReadOnly(); + private readonly IReadOnlyList FabricationStationIds = new uint[] { 2005236, 2005238, 2005240, 2007821, 2011588 }.AsReadOnly(); + internal readonly IReadOnlyList WorkshopTerritories = new ushort[] { 423, 424, 425, 653, 984 }.AsReadOnly(); private readonly WindowSystem _windowSystem = new WindowSystem(nameof(WorkshopPlugin)); private readonly DalamudPluginInterface _pluginInterface; @@ -84,9 +84,9 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin private void FrameworkUpdate(IFramework framework) { if (!_clientState.IsLoggedIn || - !_workshopTerritories.Contains(_clientState.TerritoryType) || + !WorkshopTerritories.Contains(_clientState.TerritoryType) || _condition[ConditionFlag.BoundByDuty] || - GetDistanceToEventObject(FabricationStationId, out var fabricationStation) >= 5f) + GetDistanceToEventObject(FabricationStationIds, out var fabricationStation) >= 5f) { _mainWindow.NearFabricationStation = false; } diff --git a/Workshoppa/Workshoppa.csproj b/Workshoppa/Workshoppa.csproj index fbe3d9f..5b19570 100644 --- a/Workshoppa/Workshoppa.csproj +++ b/Workshoppa/Workshoppa.csproj @@ -1,7 +1,7 @@ net7.0-windows - 2.0 + 2.1 11.0 enable true