From 1039c1eb8a6bdbc4b7a8f8a53e6f22e8bcf38564 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Sat, 2 Dec 2023 10:22:07 +0900 Subject: [PATCH] Cleanup --- Dalamud/Game/Inventory/GameInventory.cs | 20 +--------- Dalamud/Game/Inventory/GameInventoryItem.cs | 38 +++++++++++++++++++ .../InventoryItemMovedArgs.cs | 3 -- .../Internal/Windows/ConsoleWindow.cs | 3 ++ Dalamud/Plugin/Services/IGameInventory.cs | 8 +++- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Dalamud/Game/Inventory/GameInventory.cs b/Dalamud/Game/Inventory/GameInventory.cs index 36e6756bf..b8e81ced7 100644 --- a/Dalamud/Game/Inventory/GameInventory.cs +++ b/Dalamud/Game/Inventory/GameInventory.cs @@ -9,8 +9,6 @@ using Dalamud.IoC.Internal; using Dalamud.Logging.Internal; using Dalamud.Plugin.Services; -using FFXIVClientStructs.FFXIV.Client.Game; - using Serilog.Events; namespace Dalamud.Game.Inventory; @@ -94,22 +92,6 @@ internal class GameInventory : IDisposable, IServiceType, IGameInventory this.framework.Update -= this.OnFrameworkUpdate; } - /// - /// Gets a view of s, wrapped as . - /// - /// The inventory type. - /// The span. - private static unsafe ReadOnlySpan GetItemsForInventory(GameInventoryType type) - { - var inventoryManager = InventoryManager.Instance(); - if (inventoryManager is null) return default; - - var inventory = inventoryManager->GetInventoryContainer((InventoryType)type); - if (inventory is null) return default; - - return new ReadOnlySpan(inventory->Items, (int)inventory->Size); - } - private static void InvokeSafely( IGameInventory.InventoryChangelogDelegate? cb, IReadOnlyCollection data) @@ -140,7 +122,7 @@ internal class GameInventory : IDisposable, IServiceType, IGameInventory { for (var i = 0; i < this.inventoryTypes.Length; i++) { - var newItems = GetItemsForInventory(this.inventoryTypes[i]); + var newItems = GameInventoryItem.GetReadOnlySpanOfInventory(this.inventoryTypes[i]); if (newItems.IsEmpty) continue; diff --git a/Dalamud/Game/Inventory/GameInventoryItem.cs b/Dalamud/Game/Inventory/GameInventoryItem.cs index 4958574aa..1e71f6914 100644 --- a/Dalamud/Game/Inventory/GameInventoryItem.cs +++ b/Dalamud/Game/Inventory/GameInventoryItem.cs @@ -106,6 +106,28 @@ public unsafe struct GameInventoryItem : IEquatable public ReadOnlySpan MateriaGrade => new(Unsafe.AsPointer(ref Unsafe.AsRef(in this.InternalItem.MateriaGrade[0])), 5); + /// + /// Gets the address of native inventory item in the game.
+ /// Can be 0 if this instance of does not point to a valid set of container type and slot. + ///
+ public nint NativeAddress + { + get + { + var s = GetReadOnlySpanOfInventory(this.ContainerType); + if (s.IsEmpty) + return 0; + + foreach (ref readonly var i in s) + { + if (i.InventorySlot == this.InventorySlot) + return (nint)Unsafe.AsPointer(ref Unsafe.AsRef(in i)); + } + + return 0; + } + } + /// /// Gets the color used for this item. /// @@ -160,4 +182,20 @@ public unsafe struct GameInventoryItem : IEquatable this.IsEmpty ? "empty" : $"item({this.ItemId}@{this.ContainerType}#{this.InventorySlot})"; + + /// + /// Gets a view of s, wrapped as . + /// + /// The inventory type. + /// The span. + internal static ReadOnlySpan GetReadOnlySpanOfInventory(GameInventoryType type) + { + var inventoryManager = InventoryManager.Instance(); + if (inventoryManager is null) return default; + + var inventory = inventoryManager->GetInventoryContainer((InventoryType)type); + if (inventory is null) return default; + + return new ReadOnlySpan(inventory->Items, (int)inventory->Size); + } } diff --git a/Dalamud/Game/Inventory/InventoryChangeArgsTypes/InventoryItemMovedArgs.cs b/Dalamud/Game/Inventory/InventoryChangeArgsTypes/InventoryItemMovedArgs.cs index ac33acd0d..6a59d1304 100644 --- a/Dalamud/Game/Inventory/InventoryChangeArgsTypes/InventoryItemMovedArgs.cs +++ b/Dalamud/Game/Inventory/InventoryChangeArgsTypes/InventoryItemMovedArgs.cs @@ -15,9 +15,6 @@ public sealed class InventoryItemMovedArgs : InventoryComplexEventArgs { } - // /// - // public override string ToString() => $"{this.Type}({this.SourceEvent}, {this.TargetEvent})"; - /// public override string ToString() => $"{this.Type}(item({this.Item.ItemId}) from {this.SourceInventory}#{this.SourceSlot} to {this.TargetInventory}#{this.TargetSlot})"; diff --git a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs index b285520d4..89dd153cc 100644 --- a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs @@ -679,6 +679,9 @@ internal class ConsoleWindow : Window, IDisposable private bool IsFilterApplicable(LogEntry entry) { + if (this.regexError) + return false; + try { // If this entry is below a newly set minimum level, fail it diff --git a/Dalamud/Plugin/Services/IGameInventory.cs b/Dalamud/Plugin/Services/IGameInventory.cs index a6f4b4adf..6e84e780a 100644 --- a/Dalamud/Plugin/Services/IGameInventory.cs +++ b/Dalamud/Plugin/Services/IGameInventory.cs @@ -26,7 +26,11 @@ public interface IGameInventory public delegate void InventoryChangedDelegate(GameInventoryEvent type, InventoryEventArgs data); /// - /// Event that is fired when the inventory has been changed. + /// Event that is fired when the inventory has been changed.
+ /// Note that some events, such as , , and + /// currently is subject to reinterpretation as , , and + /// .
+ /// Use if you do not want such reinterpretation. ///
public event InventoryChangelogDelegate InventoryChanged; @@ -34,7 +38,7 @@ public interface IGameInventory /// Event that is fired when the inventory has been changed, without trying to interpret two inventory slot changes /// as a move event as appropriate.
/// In other words, , , and - /// do not fire in this event. + /// currently do not fire in this event. /// public event InventoryChangelogDelegate InventoryChangedRaw;