From 9e44ef243e4fbc6ace8e1e187a726691f52526ea Mon Sep 17 00:00:00 2001 From: warpersan Date: Tue, 13 Jan 2026 20:07:48 -0500 Subject: [PATCH 1/8] Removed unnecessary nullability --- src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs index 12b83e1..267209a 100644 --- a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs +++ b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs @@ -8,7 +8,7 @@ namespace ShipInventoryUpdated.Helpers.API; internal static class ItemIdentifier { private const string INVALID_ITEM_ID = "InvalidItem"; - private static readonly Dictionary ItemToHash = new(); + private static readonly Dictionary ItemToHash = new(); private static readonly Dictionary HashToItem = new(); /// From 5b915ba01fb2e4e13ca13afa648552679ddcd4cf Mon Sep 17 00:00:00 2001 From: warpersan Date: Tue, 13 Jan 2026 20:13:37 -0500 Subject: [PATCH 2/8] Added `TryAdd()` instead of `Add()` This is for future-proof. It isn't necessary, but it is a nice to have --- src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs index 267209a..c3ebf36 100644 --- a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs +++ b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs @@ -36,7 +36,7 @@ public static string GetID(Item? item) hashedId = Encoding.Default.GetString(hashedData); hashedId = new FixedString32Bytes(hashedId).ToString(); - ItemToHash.Add(item, hashedId); + ItemToHash.TryAdd(item, hashedId); HashToItem.TryAdd(hashedId, item); return hashedId; @@ -65,7 +65,7 @@ public static string GetID(Item? item) if (item == null) return null; - HashToItem.Add(id, item); + HashToItem.TryAdd(id, item); ItemToHash.TryAdd(item, id); return item; From 5a6de55b797d0b73b288e19f1e9d660f60f666e9 Mon Sep 17 00:00:00 2001 From: warpersan Date: Tue, 13 Jan 2026 20:14:02 -0500 Subject: [PATCH 3/8] Fixed doc --- src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs index c3ebf36..6711e75 100644 --- a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs +++ b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs @@ -12,7 +12,7 @@ internal static class ItemIdentifier private static readonly Dictionary HashToItem = new(); /// - /// Fetches the generic ID of the given item + /// Fetches the hashed ID of the given item /// public static string GetID(Item? item) { From 6a11b967b6ccf898d9854c27b09477fb5701e9af Mon Sep 17 00:00:00 2001 From: warpersan Date: Tue, 13 Jan 2026 20:14:13 -0500 Subject: [PATCH 4/8] Fixed doc --- src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs index 6711e75..0bb179f 100644 --- a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs +++ b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs @@ -43,7 +43,7 @@ public static string GetID(Item? item) } /// - /// Fetches the item associated with the given ID + /// Fetches the item associated with the given hashed ID /// public static Item? GetItem(string id) { From 5b8a82af047bc2f97e9d459efd6f36be3ec4841d Mon Sep 17 00:00:00 2001 From: warpersan Date: Tue, 13 Jan 2026 20:14:33 -0500 Subject: [PATCH 5/8] Created `GetGenericID()` and `GetItemFromHashedID()` --- .../Helpers/API/ItemIdentifier.cs | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs index 0bb179f..215d5ce 100644 --- a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs +++ b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs @@ -7,6 +7,7 @@ namespace ShipInventoryUpdated.Helpers.API; internal static class ItemIdentifier { + // TODO: Check if the INVALID_ITEM is something necessary private const string INVALID_ITEM_ID = "InvalidItem"; private static readonly Dictionary ItemToHash = new(); private static readonly Dictionary HashToItem = new(); @@ -22,12 +23,7 @@ public static string GetID(Item? item) if (ItemToHash.TryGetValue(item, out var hashedId)) return hashedId; - string? id = null; - - if (Dependency.Enabled) - id = Dependency.GetID(item); - - id ??= item.itemName; + var id = GetGenericID(item); using var sha256Hash = SHA256.Create(); @@ -53,6 +49,37 @@ public static string GetID(Item? item) if (HashToItem.TryGetValue(id, out var item)) return item; + item = GetItemFromHashedID(id); + + if (item == null) + return null; + + HashToItem.TryAdd(id, item); + ItemToHash.TryAdd(item, id); + + return item; + } + + /// + /// Fetches the generic ID of the given item + /// + private static string GetGenericID(Item item) + { + string? id = null; + + if (Dependency.Enabled) + id = Dependency.GetID(item); + + return id ?? item.itemName; + } + + /// + /// Fetches the item associated with the given hashed ID + /// + private static Item? GetItemFromHashedID(string id) + { + Item? item = null; + if (Dependency.Enabled) item = Dependency.GetItem(id); @@ -62,12 +89,6 @@ public static string GetID(Item? item) item = itemList.FirstOrDefault(i => GetID(i) == id); } - if (item == null) - return null; - - HashToItem.TryAdd(id, item); - ItemToHash.TryAdd(item, id); - return item; } } \ No newline at end of file From ed3618a9453bff6a9cfb9cc791ad1f17bf581189 Mon Sep 17 00:00:00 2001 From: warpersan Date: Tue, 13 Jan 2026 20:15:01 -0500 Subject: [PATCH 6/8] Fixed `LethalLib.GetItem()` --- .../Dependencies/LethalLib/Dependency.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ShipInventoryUpdated/Dependencies/LethalLib/Dependency.cs b/src/ShipInventoryUpdated/Dependencies/LethalLib/Dependency.cs index 40e6a12..15d5ddc 100644 --- a/src/ShipInventoryUpdated/Dependencies/LethalLib/Dependency.cs +++ b/src/ShipInventoryUpdated/Dependencies/LethalLib/Dependency.cs @@ -1,4 +1,5 @@ using System.Runtime.CompilerServices; +using ShipInventoryUpdated.Helpers.API; namespace ShipInventoryUpdated.Dependencies.LethalLib; @@ -47,13 +48,24 @@ private static void LoadModdedItems() } /// - /// Fetches the modded item associated with the given ID + /// Fetches the modded item associated with the given hashed ID /// [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static Item? GetItem(string id) { LoadModdedItems(); - return _cachedModdedItems?.GetValueOrDefault(id); + if (_cachedModdedItems == null) + return null; + + foreach ((_, var moddedItem) in _cachedModdedItems) + { + var hashedId = ItemIdentifier.GetID(moddedItem); + + if (hashedId == id) + return moddedItem; + } + + return null; } } \ No newline at end of file From 9fc9e057b79f71bb93c75736055b81484c1d9030 Mon Sep 17 00:00:00 2001 From: warpersan Date: Tue, 13 Jan 2026 20:20:20 -0500 Subject: [PATCH 7/8] Removed nullability from `ItemData.ctor()` --- src/ShipInventoryUpdated/Objects/ItemData.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ShipInventoryUpdated/Objects/ItemData.cs b/src/ShipInventoryUpdated/Objects/ItemData.cs index 4135de5..89dee9f 100644 --- a/src/ShipInventoryUpdated/Objects/ItemData.cs +++ b/src/ShipInventoryUpdated/Objects/ItemData.cs @@ -34,17 +34,15 @@ public struct ItemData : INetworkSerializable, IEquatable /// public bool PERSISTED_THROUGH_ROUNDS; - public ItemData() : this(null) { } - - public ItemData(GrabbableObject? item) + public ItemData(GrabbableObject item) { - ID = ItemIdentifier.GetID(item?.itemProperties); - SCRAP_VALUE = item?.scrapValue ?? 0; + ID = ItemIdentifier.GetID(item.itemProperties); + SCRAP_VALUE = item.scrapValue; - if (item?.itemProperties != null && item.itemProperties.saveItemVariable) + if (item.itemProperties.saveItemVariable) SAVE_DATA = item.GetItemDataToSave(); - PERSISTED_THROUGH_ROUNDS = item?.scrapPersistedThroughRounds ?? false; + PERSISTED_THROUGH_ROUNDS = item.scrapPersistedThroughRounds; } /// From 4325bf11f01a248521f955e88851f19d9da8328f Mon Sep 17 00:00:00 2001 From: warpersan Date: Tue, 13 Jan 2026 20:20:34 -0500 Subject: [PATCH 8/8] Removed `INVALID_ITEM` support --- src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs index 215d5ce..3473062 100644 --- a/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs +++ b/src/ShipInventoryUpdated/Helpers/API/ItemIdentifier.cs @@ -7,19 +7,14 @@ namespace ShipInventoryUpdated.Helpers.API; internal static class ItemIdentifier { - // TODO: Check if the INVALID_ITEM is something necessary - private const string INVALID_ITEM_ID = "InvalidItem"; private static readonly Dictionary ItemToHash = new(); private static readonly Dictionary HashToItem = new(); /// /// Fetches the hashed ID of the given item /// - public static string GetID(Item? item) + public static string GetID(Item item) { - if (item == null) - return INVALID_ITEM_ID; - if (ItemToHash.TryGetValue(item, out var hashedId)) return hashedId; @@ -43,9 +38,6 @@ public static string GetID(Item? item) /// public static Item? GetItem(string id) { - if (id == INVALID_ITEM_ID) - return null; - if (HashToItem.TryGetValue(id, out var item)) return item;