From 42418c2d6fd9c256c20cd151b0b4112a7f73eb5e Mon Sep 17 00:00:00 2001 From: GrahamM Date: Sat, 6 Mar 2021 11:11:17 +0000 Subject: [PATCH] Added replacement method for Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel to improve scroll wheel speed. --- CLre/Fixes/InventoryPanelScrollEngineFix.cs | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 CLre/Fixes/InventoryPanelScrollEngineFix.cs 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; + } + } +}