Added replacement method for Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel to improve scroll wheel speed.

This commit is contained in:
GrahamM 2021-03-06 11:11:17 +00:00
parent 8919fbcfe4
commit 42418c2d6f

View file

@ -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;
}
}
}