diff --git a/ARDiscard/ARDiscard.csproj b/ARDiscard/ARDiscard.csproj index ed6ae10..bd0faaf 100644 --- a/ARDiscard/ARDiscard.csproj +++ b/ARDiscard/ARDiscard.csproj @@ -1,7 +1,7 @@ net7.0-windows - 2.5 + 3.0 11.0 enable true @@ -17,7 +17,7 @@ $(appdata)\XIVLauncher\addon\Hooks\dev\ - $(appdata)\XIVLauncher\installedPlugins\AutoRetainer\4.1.2.3\ + $(appdata)\XIVLauncher\installedPlugins\AutoRetainer\4.2.0.2\ @@ -25,8 +25,8 @@ - - + + @@ -38,10 +38,6 @@ $(DalamudLibPath)ImGui.NET.dll false - - $(DalamudLibPath)ImGuiScene.dll - false - $(DalamudLibPath)Lumina.dll false @@ -58,10 +54,6 @@ $(DalamudLibPath)FFXIVClientStructs.dll false - - $(DalamudLibPath)FFXIVClientStructs.dll - false - $(AutoRetainerLibPath)AutoRetainerAPI.dll diff --git a/ARDiscard/AutoDiscardPlogon.cs b/ARDiscard/AutoDiscardPlogon.cs index 4c754bf..7b1a238 100644 --- a/ARDiscard/AutoDiscardPlogon.cs +++ b/ARDiscard/AutoDiscardPlogon.cs @@ -5,18 +5,13 @@ using ARDiscard.GameData; using ARDiscard.Windows; using AutoRetainerAPI; using ClickLib.Clicks; -using Dalamud.Data; -using Dalamud.Game.ClientState; -using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.Command; -using Dalamud.Game.Gui; using Dalamud.Interface.Windowing; -using Dalamud.Logging; using Dalamud.Memory; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using ECommons; using ECommons.Automation; -using ECommons.DalamudServices; using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Component.GUI; @@ -32,9 +27,11 @@ public class AutoDiscardPlogon : IDalamudPlugin private readonly DiscardWindow _discardWindow; private readonly DalamudPluginInterface _pluginInterface; - private readonly ChatGui _chatGui; - private readonly ClientState _clientState; - private readonly CommandManager _commandManager; + private readonly IChatGui _chatGui; + private readonly IClientState _clientState; + private readonly IPluginLog _pluginLog; + private readonly IGameGui _gameGui; + private readonly ICommandManager _commandManager; private readonly InventoryUtils _inventoryUtils; private readonly AutoRetainerApi _autoRetainerApi; private readonly TaskManager _taskManager; @@ -42,8 +39,8 @@ public class AutoDiscardPlogon : IDalamudPlugin private DateTime _cancelDiscardAfter = DateTime.MaxValue; - public AutoDiscardPlogon(DalamudPluginInterface pluginInterface, CommandManager commandManager, ChatGui chatGui, - DataManager dataManager, ClientState clientState, Condition condition) + public AutoDiscardPlogon(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui, + IDataManager dataManager, IClientState clientState, ICondition condition, IPluginLog pluginLog, IGameGui gameGui) { ItemCache itemCache = new ItemCache(dataManager); @@ -51,6 +48,8 @@ public class AutoDiscardPlogon : IDalamudPlugin _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); _chatGui = chatGui; _clientState = clientState; + _pluginLog = pluginLog; + _gameGui = gameGui; _commandManager = commandManager; _commandManager.AddHandler("/discardconfig", new CommandInfo(OpenConfig) { @@ -64,7 +63,7 @@ public class AutoDiscardPlogon : IDalamudPlugin { HelpMessage = "Show what will be discarded with your current configuration", }); - _inventoryUtils = new InventoryUtils(_configuration, itemCache); + _inventoryUtils = new InventoryUtils(_configuration, itemCache, _pluginLog); _pluginInterface.UiBuilder.Draw += _windowSystem.Draw; _pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi; @@ -84,7 +83,7 @@ public class AutoDiscardPlogon : IDalamudPlugin ECommonsMain.Init(_pluginInterface, this); _autoRetainerApi = new(); _taskManager = new(); - _contextMenuIntegration = new(_configuration, _configWindow); + _contextMenuIntegration = new(_pluginInterface, _configuration, _configWindow); _clientState.Login += _discardWindow.Login; _clientState.Logout += _discardWindow.Logout; @@ -94,8 +93,6 @@ public class AutoDiscardPlogon : IDalamudPlugin _autoRetainerApi.OnCharacterReadyToPostProcess += DoCharacterPostProcess; } - public string Name => "Discard after AutoRetainer"; - private void CheckRetainerPostProcess(string retainerName) => CheckPostProcessInternal(PostProcessType.Retainer, retainerName, _configuration.RunAfterVenture); @@ -106,19 +103,19 @@ public class AutoDiscardPlogon : IDalamudPlugin { if (!enabled) { - PluginLog.Information($"Not running post-venture tasks for {name}, disabled globally"); + _pluginLog.Information($"Not running post-venture tasks for {name}, disabled globally"); } else if (_configuration.ExcludedCharacters.Any(x => x.LocalContentId == _clientState.LocalContentId)) { - PluginLog.Information($"Not running post-venture tasks for {name}, disabled for current character"); + _pluginLog.Information($"Not running post-venture tasks for {name}, disabled for current character"); } else if (_inventoryUtils.GetNextItemToDiscard(ItemFilter.None) == null) { - PluginLog.Information($"Not running post-venture tasks for {name}, no items to discard"); + _pluginLog.Information($"Not running post-venture tasks for {name}, no items to discard"); } else { - PluginLog.Information($"Requesting post-processing for {name}"); + _pluginLog.Information($"Requesting post-processing for {name}"); if (type == PostProcessType.Retainer) _autoRetainerApi.RequestRetainerPostprocess(); else if (type == PostProcessType.Character) @@ -155,20 +152,20 @@ public class AutoDiscardPlogon : IDalamudPlugin private unsafe void DiscardNextItem(PostProcessType type, ItemFilter? itemFilter) { - PluginLog.Information($"DiscardNextItem (type = {type})"); + _pluginLog.Information($"DiscardNextItem (type = {type})"); _discardWindow.Locked = true; InventoryItem* nextItem = _inventoryUtils.GetNextItemToDiscard(itemFilter); if (nextItem == null) { - PluginLog.Information($"No item to discard found"); + _pluginLog.Information($"No item to discard found"); FinishDiscarding(type); } else { var (inventoryType, slot) = (nextItem->Container, nextItem->Slot); - PluginLog.Information( + _pluginLog.Information( $"Discarding itemId {nextItem->ItemID} in slot {nextItem->Slot} of container {nextItem->Container}."); _inventoryUtils.Discard(nextItem); _cancelDiscardAfter = DateTime.Now.AddSeconds(15); @@ -184,7 +181,7 @@ public class AutoDiscardPlogon : IDalamudPlugin var addon = GetDiscardAddon(); if (addon != null) { - PluginLog.Information("Addon is visible, clicking 'yes'"); + _pluginLog.Information("Addon is visible, clicking 'yes'"); ((AddonSelectYesno*)addon)->YesButton->AtkComponentBase.SetEnabledState(true); ClickSelectYesNo.Using((nint)addon).Yes(); @@ -196,19 +193,19 @@ public class AutoDiscardPlogon : IDalamudPlugin InventoryItem* nextItem = _inventoryUtils.GetNextItemToDiscard(itemFilter); if (nextItem == null) { - PluginLog.Information("Addon is not visible, but next item is also no longer set"); + _pluginLog.Information("Addon is not visible, but next item is also no longer set"); FinishDiscarding(type); } else if (nextItem->Container == inventoryType && nextItem->Slot == slot) { - PluginLog.Information( + _pluginLog.Information( $"Addon is not (yet) visible, still trying to discard item in slot {slot} in inventory {inventoryType}"); _taskManager.DelayNext(100); _taskManager.Enqueue(() => ConfirmDiscardItem(type, itemFilter, inventoryType, slot)); } else { - PluginLog.Information( + _pluginLog.Information( $"Addon is not (yet) visible, but slot or inventory type changed, retrying from start"); _taskManager.DelayNext(100); _taskManager.Enqueue(() => DiscardNextItem(type, itemFilter)); @@ -222,26 +219,26 @@ public class AutoDiscardPlogon : IDalamudPlugin InventoryItem* nextItem = _inventoryUtils.GetNextItemToDiscard(itemFilter); if (nextItem == null) { - PluginLog.Information($"Continuing after discard: no next item (type = {type})"); + _pluginLog.Information($"Continuing after discard: no next item (type = {type})"); FinishDiscarding(type); } else if (nextItem->Container == inventoryType && nextItem->Slot == slot) { if (_cancelDiscardAfter < DateTime.Now) { - PluginLog.Information("No longer waiting for plugin to pop up, assume discard failed"); + _pluginLog.Information("No longer waiting for plugin to pop up, assume discard failed"); FinishDiscarding(type, "Discarding probably failed due to an error."); } else { - PluginLog.Information($"ContinueAfterDiscard: Waiting for server response until {_cancelDiscardAfter}"); + _pluginLog.Information($"ContinueAfterDiscard: Waiting for server response until {_cancelDiscardAfter}"); _taskManager.DelayNext(20); _taskManager.Enqueue(() => ContinueAfterDiscard(type, itemFilter, inventoryType, slot)); } } else { - PluginLog.Information($"ContinueAfterDiscard: Discovered different item to discard"); + _pluginLog.Information($"ContinueAfterDiscard: Discovered different item to discard"); _taskManager.EnqueueImmediate(() => DiscardNextItem(type, itemFilter)); } } @@ -284,19 +281,19 @@ public class AutoDiscardPlogon : IDalamudPlugin _commandManager.RemoveHandler("/discardconfig"); } - private static unsafe AtkUnitBase* GetDiscardAddon() + private unsafe AtkUnitBase* GetDiscardAddon() { for (int i = 1; i < 100; i++) { try { - var addon = (AtkUnitBase*)Svc.GameGui.GetAddonByName("SelectYesno", i); + var addon = (AtkUnitBase*)_gameGui.GetAddonByName("SelectYesno", i); if (addon == null) return null; if (addon->IsVisible && addon->UldManager.LoadedState == AtkLoadState.Loaded) { var textNode = addon->UldManager.NodeList[15]->GetAsAtkTextNode(); var text = MemoryHelper.ReadSeString(&textNode->NodeText).ExtractText(); - PluginLog.Information($"YesNo prompt: {text}"); + _pluginLog.Information($"YesNo prompt: {text}"); if (text.StartsWith("Discard")) { return addon; diff --git a/ARDiscard/ContextMenuIntegration.cs b/ARDiscard/ContextMenuIntegration.cs index c36037f..1fc861f 100644 --- a/ARDiscard/ContextMenuIntegration.cs +++ b/ARDiscard/ContextMenuIntegration.cs @@ -6,6 +6,7 @@ using ARDiscard.Windows; using Dalamud.ContextMenu; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; +using Dalamud.Plugin; using FFXIVClientStructs.FFXIV.Client.UI.Agent; namespace ARDiscard; @@ -18,7 +19,7 @@ internal sealed class ContextMenuIntegration : IDisposable private readonly InventoryContextMenuItem _removeItem; private readonly DalamudContextMenu _dalamudContextMenu; - public ContextMenuIntegration(Configuration configuration, ConfigWindow configWindow) + public ContextMenuIntegration(DalamudPluginInterface pluginInterface, Configuration configuration, ConfigWindow configWindow) { _configuration = configuration; _configWindow = configWindow; @@ -33,7 +34,7 @@ internal sealed class ContextMenuIntegration : IDisposable .Append(new UIForegroundPayload(0)).Append("Remove from Auto Discard List"), RemoveFromDiscardList); - _dalamudContextMenu = new(); + _dalamudContextMenu = new(pluginInterface); _dalamudContextMenu.OnOpenInventoryContextMenu += OpenInventoryContextMenu; } diff --git a/ARDiscard/GameData/InventoryUtils.cs b/ARDiscard/GameData/InventoryUtils.cs index 5c2756c..1196aff 100644 --- a/ARDiscard/GameData/InventoryUtils.cs +++ b/ARDiscard/GameData/InventoryUtils.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Dalamud.Logging; -using Dalamud.Utility.Signatures; +using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Client.UI.Misc; @@ -38,18 +37,13 @@ internal sealed class InventoryUtils private readonly Configuration _configuration; private readonly ItemCache _itemCache; + private readonly IPluginLog _pluginLog; - private unsafe delegate void DiscardItemDelegate(AgentInventoryContext* inventoryManager, InventoryItem* itemSlot, - InventoryType inventory, int slot, uint addonId, int position = -1); - - [Signature("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 85 C0 74 ?? 0F B7 48")] - private DiscardItemDelegate _discardItem = null!; - - public InventoryUtils(Configuration configuration, ItemCache itemCache) + public InventoryUtils(Configuration configuration, ItemCache itemCache, IPluginLog pluginLog) { _configuration = configuration; _itemCache = itemCache; - SignatureHelper.Initialise(this); + _pluginLog = pluginLog; } public unsafe List GetAllItemsToDiscard() @@ -129,7 +123,7 @@ internal sealed class InventoryUtils //PluginLog.Verbose($"{i} → {item->ItemID}"); if (_configuration.DiscardingItems.Contains(item->ItemID)) { - PluginLog.Information( + _pluginLog.Information( $"Found item {item->ItemID} to discard in inventory {inventoryType} in slot {i}"); toDiscard.Add(new ItemWrapper { InventoryItem = item }); } @@ -168,7 +162,7 @@ internal sealed class InventoryUtils gearset->Neck, gearset->Wrists, gearset->RingRight, - gearset->RightLeft, // why is this called RightLeft + gearset->RingLeft, }; foreach (var gearsetItem in gearsetItems) { @@ -186,7 +180,7 @@ internal sealed class InventoryUtils if (InternalConfiguration.BlacklistedItems.Contains(item->ItemID)) throw new Exception($"Can't discard {item->ItemID}"); - _discardItem(AgentInventoryContext.Instance(), item, item->Container, item->Slot, 0); + AgentInventoryContext.Instance()->DiscardItem(item, item->Container, item->Slot, 0); } public sealed unsafe class ItemWrapper diff --git a/ARDiscard/GameData/ItemCache.cs b/ARDiscard/GameData/ItemCache.cs index df1cebd..0a4f9e4 100644 --- a/ARDiscard/GameData/ItemCache.cs +++ b/ARDiscard/GameData/ItemCache.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Dalamud.Data; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; namespace ARDiscard.GameData; @@ -8,7 +8,7 @@ internal sealed class ItemCache { private readonly Dictionary _items = new(); - public ItemCache(DataManager dataManager) + public ItemCache(IDataManager dataManager) { foreach (var item in dataManager.GetExcelSheet()!) { diff --git a/ARDiscard/Windows/ConfigWindow.cs b/ARDiscard/Windows/ConfigWindow.cs index 96afaf6..02734a7 100644 --- a/ARDiscard/Windows/ConfigWindow.cs +++ b/ARDiscard/Windows/ConfigWindow.cs @@ -3,15 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; using ARDiscard.GameData; -using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Conditions; -using Dalamud.Interface; using Dalamud.Interface.Colors; +using Dalamud.Interface.Utility; using Dalamud.Interface.Windowing; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using ECommons; using ImGuiNET; -using Condition = Dalamud.Game.ClientState.Conditions.Condition; namespace ARDiscard.Windows; @@ -20,8 +19,8 @@ internal sealed class ConfigWindow : Window private readonly DalamudPluginInterface _pluginInterface; private readonly Configuration _configuration; private readonly ItemCache _itemCache; - private readonly ClientState _clientState; - private readonly Condition _condition; + private readonly IClientState _clientState; + private readonly ICondition _condition; private string _itemName = string.Empty; private List<(uint ItemId, string Name)> _searchResults = new(); @@ -33,7 +32,7 @@ internal sealed class ConfigWindow : Window public event EventHandler? ConfigSaved; public ConfigWindow(DalamudPluginInterface pluginInterface, Configuration configuration, ItemCache itemCache, - ClientState clientState, Condition condition) + IClientState clientState, ICondition condition) : base("Auto Discard###AutoDiscardConfig") { _pluginInterface = pluginInterface; diff --git a/ARDiscard/Windows/DiscardWindow.cs b/ARDiscard/Windows/DiscardWindow.cs index 826d5c9..531d362 100644 --- a/ARDiscard/Windows/DiscardWindow.cs +++ b/ARDiscard/Windows/DiscardWindow.cs @@ -2,10 +2,10 @@ using System.Collections.Generic; using System.Linq; using ARDiscard.GameData; -using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Conditions; -using Dalamud.Interface; +using Dalamud.Interface.Utility; using Dalamud.Interface.Windowing; +using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Common.Math; using ImGuiNET; @@ -15,16 +15,16 @@ internal sealed class DiscardWindow : Window { private readonly InventoryUtils _inventoryUtils; private readonly ItemCache _itemCache; - private readonly ClientState _clientState; - private readonly Condition _condition; + private readonly IClientState _clientState; + private readonly ICondition _condition; private List _displayedItems = new(); public event EventHandler? OpenConfigurationClicked; public event EventHandler? DiscardAllClicked; - public DiscardWindow(InventoryUtils inventoryUtils, ItemCache itemCache, ClientState clientState, - Condition condition) + public DiscardWindow(InventoryUtils inventoryUtils, ItemCache itemCache, IClientState clientState, + ICondition condition) : base("Discard Items") { _inventoryUtils = inventoryUtils; @@ -140,7 +140,7 @@ internal sealed class DiscardWindow : Window } } - public void Login(object? sender, EventArgs e) => RefreshInventory(false); + public void Login() => RefreshInventory(false); - public void Logout(object? sender, EventArgs e) => _displayedItems.Clear(); + public void Logout() => _displayedItems.Clear(); } diff --git a/ARDiscard/packages.lock.json b/ARDiscard/packages.lock.json index 6bf9223..537ed1a 100644 --- a/ARDiscard/packages.lock.json +++ b/ARDiscard/packages.lock.json @@ -4,15 +4,15 @@ "net7.0-windows7.0": { "Dalamud.ContextMenu": { "type": "Direct", - "requested": "[1.2.3, )", - "resolved": "1.2.3", - "contentHash": "ydemplF7DNcA/LLeongDVzWUD/JV0Fw3EwA2+P0jYq3Le2ZYSt4U8qyJq4FyoChqt0lFG8BxYCAzfeWp4Jmnqw==" + "requested": "[1.3.1, )", + "resolved": "1.3.1", + "contentHash": "ptAxut5PiLnzZ4G/KQdHJVcyklC/BF3otHJ7zYVUPiKBjsOCoF0n/6h2jK7e+8ev2Y1yAY3Wtx2GuXLFQgt9Uw==" }, "DalamudPackager": { "type": "Direct", - "requested": "[2.1.11, )", - "resolved": "2.1.11", - "contentHash": "9qlAWoRRTiL/geAvuwR/g6Bcbrd/bJJgVnB/RurBiyKs6srsP0bvpoo8IK+Eg8EA6jWeM6/YJWs66w4FIAzqPw==" + "requested": "[2.1.12, )", + "resolved": "2.1.12", + "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" } } }