From 1c8ace3ce85d4b2fc79cd5c411aaa0d9da8a80d4 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:54:30 +0700 Subject: [PATCH] fix: queue index is now stable after an item addition --- MusicX/Patches/ItemContainerGeneratorIndexHook.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MusicX/Patches/ItemContainerGeneratorIndexHook.cs b/MusicX/Patches/ItemContainerGeneratorIndexHook.cs index 9a6eb72b..e1a377fe 100644 --- a/MusicX/Patches/ItemContainerGeneratorIndexHook.cs +++ b/MusicX/Patches/ItemContainerGeneratorIndexHook.cs @@ -52,12 +52,22 @@ public static void Apply() var itemRemovedMethod = typeof(ItemContainerGenerator).GetMethod("OnItemRemoved", BindingFlags.Instance | BindingFlags.NonPublic)!; + var itemAddedMethod = typeof(ItemContainerGenerator).GetMethod("OnItemAdded", + BindingFlags.Instance | BindingFlags.NonPublic)!; + Hooks.Add(new ILHook(generateNextMethod, GenerateNextManipulator)); Hooks.Add(new ILHook(unlinkContainerFromItemMethod, UnlinkContainerFromItemManipulator)); Hooks.Add(new ILHook(itemReplacedMethod, ItemReplacedManipulator)); Hooks.Add(new Hook(itemMovedMethod, ItemMovedHook)); Hooks.Add(new ILHook(itemMovedMethod, ItemMovedManipulator)); Hooks.Add(new Hook(itemRemovedMethod, ItemRemovedHook)); + Hooks.Add(new Hook(itemAddedMethod, ItemAddedHook)); + } + + private static void ItemAddedHook(Action original, ItemContainerGenerator self, object item, int itemIndex) + { + original(self, item, itemIndex); + UpdateContainerIndices(self, itemIndex); } private static void ItemRemovedHook(Action original,