Browse Source

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

master
GrahamM 3 years ago
parent
commit
42418c2d6f
1 changed files with 39 additions and 0 deletions
  1. +39
    -0
      CLre/Fixes/InventoryPanelScrollEngineFix.cs

+ 39
- 0
CLre/Fixes/InventoryPanelScrollEngineFix.cs 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;
}
}
}

Loading…
Cancel
Save