Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.8KB

  1. using System;
  2. using HarmonyLib;
  3. using System.Reflection;
  4. using UnityEngine;
  5. namespace CLre.Fixes
  6. {
  7. [Bugfix(name = "ScrollSpeedImprovement",
  8. description = "Improve mouse wheel scroll speed in inventory",
  9. more = "https://trello.com/c/elL8IVdn/4-scroll-menus-are-insensitive",
  10. component = BugfixType.HarmonyPatch, id = 4)]
  11. [HarmonyPatch]
  12. class InventoryPanelScrollEngine_ScrollPanelByMouseWheel_Patch
  13. {
  14. [HarmonyPrefix]
  15. public static bool BeforeMethodCall(ref object panelScrollComponent, ref float scrollValue)
  16. {
  17. if (panelScrollComponent == null) return true; // If it's null, we don't try to handle it.
  18. // We, perhaps dangerously, assume that we'll only get a panelScrollComponent.
  19. PropertyInfo scrollbar = panelScrollComponent.GetType().GetProperty("scrollbar", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  20. UnityEngine.UI.Scrollbar sb = scrollbar.GetValue(panelScrollComponent) as UnityEngine.UI.Scrollbar;
  21. float num = -scrollValue * (sb.size * 0.3f);
  22. float num2 = sb.value;
  23. num2 = Mathf.Clamp01(num2 + num);
  24. sb.value = num2;
  25. return false; // Tell harmony not to invoke the original method
  26. }
  27. [HarmonyTargetMethod]
  28. public static MethodBase Target()
  29. {
  30. MethodInfo methodtopatch = AccessTools.Method("Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel");
  31. if (null == methodtopatch) API.Utility.Logging.MetaLog("Intercepting Game.UI.InventoryPanelScrollEngine:ScrollPanelByMouseWheel() failed");
  32. return methodtopatch;
  33. }
  34. }
  35. }