From 01d3da1e8cca949994a51e8897b33a546d3e8f5e Mon Sep 17 00:00:00 2001 From: Yui Date: Wed, 23 Oct 2024 12:07:04 -0300 Subject: [PATCH] feat: added custom item hashing --- Plugin/Extensions/ItemExtensions.cs | 9 +++++---- Plugin/Patches/TooltipPatch.cs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Plugin/Extensions/ItemExtensions.cs b/Plugin/Extensions/ItemExtensions.cs index 1df3fda..9a3b3dd 100644 --- a/Plugin/Extensions/ItemExtensions.cs +++ b/Plugin/Extensions/ItemExtensions.cs @@ -24,17 +24,18 @@ namespace LootValueEX.Extensions return -1f; } } - internal static string CustomHash(this Item? item) + internal static string GetCustomHash(this Item? item) { if (item == null) return string.Empty; StringBuilder prehashString = new StringBuilder(); if (item.IsContainer) { - return "0"; + Plugin.Log.LogDebug($"Loop called on {item.LocalizedName()}"); + item.GetAllItems().Where(prop => !prop.Equals(item)).ExecuteForEach(prop => prehashString.Append(prop.GetCustomHash())); } - string itemHashTemplate = string.Format("{0}|{1}|{2}|{3}", item.TemplateId, item.GetDurability(), item.GetUses(), item.StackObjectsCount); - return "0"; + string itemHashTemplate = string.Format("{0}|{1}|{2}|{3}", prehashString.ToString(), item.TemplateId, item.GetDurability(), item.GetUses()); + return Utils.HashingUtils.ConvertToSha256(itemHashTemplate); } #if DEBUG internal static string AttributesToString(this Item? item) diff --git a/Plugin/Patches/TooltipPatch.cs b/Plugin/Patches/TooltipPatch.cs index 45f7e2c..f694949 100644 --- a/Plugin/Patches/TooltipPatch.cs +++ b/Plugin/Patches/TooltipPatch.cs @@ -23,7 +23,7 @@ namespace LootValueEX.Patches Plugin.Log.LogDebug("Stacktrace of tooltip call: \n" + stackTrace.ToString()); if (GridItemTooltipPatch.PatchTooltip) { - text += $"
TemplateID: {GridItemTooltipPatch.HoveredItem?.TemplateId}
Template: {GridItemTooltipPatch.HoveredItem?.Template}
Item hashsum: {GridItemTooltipPatch.HoveredItem?.GetHashSum()}
Item durability: {GridItemTooltipPatch.HoveredItem?.GetDurability()}
Item uses: {GridItemTooltipPatch.HoveredItem?.GetUses()}
GridItemView"; + text += $"
TemplateID: {GridItemTooltipPatch.HoveredItem?.TemplateId}
Template: {GridItemTooltipPatch.HoveredItem?.Template}
Item hashsum: {GridItemTooltipPatch.HoveredItem?.GetHashSum()}
Custom hash: {GridItemTooltipPatch.HoveredItem?.GetCustomHash()}
Item durability: {GridItemTooltipPatch.HoveredItem?.GetDurability()}
Item uses: {GridItemTooltipPatch.HoveredItem?.GetUses()}
GridItemView"; Plugin.Log.LogDebug(GridItemTooltipPatch.HoveredItem?.AttributesToString()); } if (InsuranceSlotPatch.PatchTooltip)