From 77afc048ee5da6411c9ed7327e43030100835a61 Mon Sep 17 00:00:00 2001 From: Alex Gilbert Date: Tue, 23 Jun 2026 12:44:34 -0400 Subject: [PATCH] - Add GetItemId overloads, like we have for locations --- .../DataPackage/ItemInfoResolver.cs | 31 +++++++++++++++++++ .../Helpers/ReceivedItemsHelper.cs | 17 ++++++++++ 2 files changed, 48 insertions(+) diff --git a/Archipelago.MultiClient.Net/DataPackage/ItemInfoResolver.cs b/Archipelago.MultiClient.Net/DataPackage/ItemInfoResolver.cs index 485faa23..402a50b1 100644 --- a/Archipelago.MultiClient.Net/DataPackage/ItemInfoResolver.cs +++ b/Archipelago.MultiClient.Net/DataPackage/ItemInfoResolver.cs @@ -22,6 +22,20 @@ public interface IItemInfoResolver /// string GetItemName(long itemId, string game = null); + /// + /// Perform a lookup using the DataPackage sent as a source of truth to lookup a particular item name for a particular game. + /// + /// + /// Name of the item to lookup. + /// + /// + /// The game to lookup the item name for, if null will look in the game the local player is connected to. + /// + /// + /// The id of the item as a long, or -1 if no such item is found. + /// + long GetItemId(string itemName, string game = null); + /// /// Get the name of a location from its id. Useful when receiving a packet and it is necessary to find the name of the location. /// @@ -81,6 +95,23 @@ public string GetItemName(long itemId, string game = null) : null; } + /// + public long GetItemId(string itemName, string game = null) + { + if (game == null) + game = connectionInfoProvider.Game ?? "Archipelago"; + + if (string.IsNullOrEmpty(itemName)) + return -1; + + if (!cache.TryGetGameDataFromCache(game, out var dataPackage)) + return -1; + + return dataPackage.Items.TryGetValue(itemName, out var itemId) + ? itemId + : -1; + } + /// public string GetLocationName(long locationId, string game = null) { diff --git a/Archipelago.MultiClient.Net/Helpers/ReceivedItemsHelper.cs b/Archipelago.MultiClient.Net/Helpers/ReceivedItemsHelper.cs index 6cdbfaff..527e5238 100644 --- a/Archipelago.MultiClient.Net/Helpers/ReceivedItemsHelper.cs +++ b/Archipelago.MultiClient.Net/Helpers/ReceivedItemsHelper.cs @@ -31,6 +31,20 @@ public interface IReceivedItemsHelper /// string GetItemName(long id, string game = null); + /// + /// Perform a lookup using the DataPackage sent as a source of truth to lookup a particular item name for a particular game. + /// + /// + /// Name of the item to lookup. + /// + /// + /// The game to lookup the item name for, if null will look in the game the local player is connected to. + /// + /// + /// The id of the item as a string, or -1 if no such item is found. + /// + long GetItemId(string name, string game = null); + /// /// Total number of items received /// @@ -141,6 +155,9 @@ public ItemInfo DequeueItem() /// public string GetItemName(long id, string game = null) => itemInfoResolver.GetItemName(id, game); + /// + public long GetItemId(string name, string game = null) => itemInfoResolver.GetItemId(name, game); + void Socket_PacketReceived(ArchipelagoPacketBase packet) { switch (packet.PacketType)