diff --git a/CLre/Fixes/InventoryPanelScrollEngineFix.cs b/CLre/Fixes/InventoryPanelScrollEngineFix.cs new file mode 100644 index 0000000..37448bc --- /dev/null +++ b/CLre/Fixes/InventoryPanelScrollEngineFix.cs @@ -0,0 +1,39 @@ +using System; + +using HarmonyLib; +using System.Reflection; +using UnityEngine; + +namespace CLre.Fixes +{ + [Bugfix(name = "ScrollSpeedImprovement", + description = "Improve mouse wheel scroll speed in inventory", + more = "https://trello.com/c/elL8IVdn/4-scroll-menus-are-insensitive", + component = BugfixType.HarmonyPatch, id = 4)] + [HarmonyPatch] + class InventoryPanelScrollEngine_ScrollPanelByMouseWheel_Patch + { + [HarmonyPrefix] + public static bool BeforeMethodCall(ref object panelScrollComponent, ref float scrollValue) + { + if (panelScrollComponent == null) return true; // If it's null, we don't try to handle it. + // We, perhaps dangerously, assume that we'll only get a panelScrollComponent. + PropertyInfo scrollbar = panelScrollComponent.GetType().GetProperty("scrollbar", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + UnityEngine.UI.Scrollbar sb = scrollbar.GetValue(panelScrollComponent) as UnityEngine.UI.Scrollbar; + float num = -scrollValue * (sb.size * 0.3f); + float num2 = sb.value; + num2 = Mathf.Clamp01(num2 + num); + sb.value = num2; + return false; // Tell harmony not to invoke the original method + } + + + [HarmonyTargetMethod] + public static MethodBase Target() + { + MethodInfo methodtopatch = AccessTools.Method("Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel"); + if (null == methodtopatch) API.Utility.Logging.MetaLog("Intercepting Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel() failed"); + return methodtopatch; + } + } +}