From b5cc69520d7d133f45f073cc4e47d62bf2436afb Mon Sep 17 00:00:00 2001 From: peinwastaken Date: Thu, 26 Feb 2026 10:20:28 +0200 Subject: [PATCH 1/3] fixed custom items messing up sort order --- .../Patches/FixCustomItemSortingOrderPatch.cs | 42 +++++++++++++++++++ WTT-ClientCommonLib/WTTClientCommonLib.cs | 3 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 WTT-ClientCommonLib/Patches/FixCustomItemSortingOrderPatch.cs diff --git a/WTT-ClientCommonLib/Patches/FixCustomItemSortingOrderPatch.cs b/WTT-ClientCommonLib/Patches/FixCustomItemSortingOrderPatch.cs new file mode 100644 index 0000000..31cbca8 --- /dev/null +++ b/WTT-ClientCommonLib/Patches/FixCustomItemSortingOrderPatch.cs @@ -0,0 +1,42 @@ +using EFT.InventoryLogic; +using HarmonyLib; +using SPT.Reflection.Patching; +using System; +using System.Reflection; + +namespace WTTClientCommonLib.Patches +{ + public class FixCustomItemSortingOrderPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(GClass3380), nameof(GClass3380.GetIndexOfItemType)); + } + + [PatchPrefix] + public static bool PatchPrefix(GClass3380 __instance, ref int __result, Item i) + { + Type type = i.GetType(); + + int index = GClass3381.IndexOf(type); + if (index >= 0) + { + __result = index; + return false; + } + + for (Type type2 = type; type2 != null; type2 = type2.BaseType) + { + index = GClass3381.IndexOf(type2); + if (index >= 0) + { + __result = index; + return false; + } + } + + __result = int.MaxValue; + return false; + } + } +} diff --git a/WTT-ClientCommonLib/WTTClientCommonLib.cs b/WTT-ClientCommonLib/WTTClientCommonLib.cs index e7b5088..0200be4 100644 --- a/WTT-ClientCommonLib/WTTClientCommonLib.cs +++ b/WTT-ClientCommonLib/WTTClientCommonLib.cs @@ -72,7 +72,8 @@ private void Awake() new ClothingBundleRendererPatch().Enable(); new HideoutCustomizationIconPatch().Enable(); new HideoutCustomizationTexturesPatch().Enable(); - + new FixCustomItemSortingOrderPatch().Enable(); + var resourceLoader = new ResourceLoader(Logger, AssetLoader); resourceLoader.LoadAllResourcesFromServer(); } From df9ff4bff15462347a8c5acfdc34c635a57ac0a5 Mon Sep 17 00:00:00 2001 From: peinwastaken Date: Thu, 26 Feb 2026 10:32:56 +0200 Subject: [PATCH 2/3] create sort order helper --- WTT-ClientCommonLib/Helpers/SortHelper.cs | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 WTT-ClientCommonLib/Helpers/SortHelper.cs diff --git a/WTT-ClientCommonLib/Helpers/SortHelper.cs b/WTT-ClientCommonLib/Helpers/SortHelper.cs new file mode 100644 index 0000000..7081af8 --- /dev/null +++ b/WTT-ClientCommonLib/Helpers/SortHelper.cs @@ -0,0 +1,31 @@ +using System; +using ItemSortOrderManager = GClass3381; + +namespace WTTClientCommonLib.Helpers +{ + public static class SortHelper + { + public static void AddToSortOrder(this Type itemType, Type itemToInsertAfter, int offset = 1) + { + InsertAfter(itemType, itemToInsertAfter, offset); + } + + public static void Insert(int sortIndex, Type itemType) + { + ItemSortOrderManager.List_0.Insert(sortIndex, itemType); + } + + public static void InsertAfter(Type itemType, Type itemToInsertAfter, int offset = 1) + { + if (!ItemSortOrderManager.List_0.ContainsElement(itemToInsertAfter)) + { + LogHelper.LogWarn($"failed to add item type {itemType} to sort order because item type {itemToInsertAfter} doesn't exist in sort order list"); + return; + } + + int itemIndex = ItemSortOrderManager.IndexOf(itemToInsertAfter); + + ItemSortOrderManager.List_0.Insert(itemIndex + offset, itemType); + } + } +} From 7532c90d3c34fb86fdd354b52c4afa06a5b11eea Mon Sep 17 00:00:00 2001 From: peinwastaken Date: Thu, 26 Feb 2026 10:52:08 +0200 Subject: [PATCH 3/3] bunch of overkill sorthelper stuff --- WTT-ClientCommonLib/Helpers/SortHelper.cs | 40 ++++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/WTT-ClientCommonLib/Helpers/SortHelper.cs b/WTT-ClientCommonLib/Helpers/SortHelper.cs index 7081af8..db765fa 100644 --- a/WTT-ClientCommonLib/Helpers/SortHelper.cs +++ b/WTT-ClientCommonLib/Helpers/SortHelper.cs @@ -1,13 +1,20 @@ +using EFT.InventoryLogic; using System; +using System.Collections.Generic; using ItemSortOrderManager = GClass3381; namespace WTTClientCommonLib.Helpers { public static class SortHelper { - public static void AddToSortOrder(this Type itemType, Type itemToInsertAfter, int offset = 1) + public static void AddToSortOrder(this Type itemType, Type itemTypeToInsertAfter, int offset = 1) { - InsertAfter(itemType, itemToInsertAfter, offset); + InsertAfter(itemType, itemTypeToInsertAfter, offset); + } + + public static int GetSortOrder(this Type itemType) + { + return ItemSortOrderManager.List_0.IndexOf(itemType); } public static void Insert(int sortIndex, Type itemType) @@ -15,16 +22,39 @@ public static void Insert(int sortIndex, Type itemType) ItemSortOrderManager.List_0.Insert(sortIndex, itemType); } - public static void InsertAfter(Type itemType, Type itemToInsertAfter, int offset = 1) + public static void SetIndex(int newIndex, Type itemType) { - if (!ItemSortOrderManager.List_0.ContainsElement(itemToInsertAfter)) + List list = ItemSortOrderManager.List_0; + int oldIndex = list.IndexOf(itemType); + + if (oldIndex < 0) { - LogHelper.LogWarn($"failed to add item type {itemType} to sort order because item type {itemToInsertAfter} doesn't exist in sort order list"); + LogHelper.LogWarn($"failed to set sort index for item {itemType} because it does not exist in sort order list"); return; } + newIndex = Math.Clamp(newIndex, 0, list.Count - 1); + + list.RemoveAt(oldIndex); + + if (newIndex > oldIndex) + { + newIndex--; + } + + list.Insert(newIndex, itemType); + } + + public static void InsertAfter(Type itemType, Type itemToInsertAfter, int offset = 1) + { int itemIndex = ItemSortOrderManager.IndexOf(itemToInsertAfter); + if (itemIndex < 0) + { + LogHelper.LogWarn($"failed to add item type {itemType} to sort order because item type {itemToInsertAfter} doesn't exist in sort order list"); + return; + } + ItemSortOrderManager.List_0.Insert(itemIndex + offset, itemType); } }