Due to update 2.4.3, some mods may no longer function. FixedConfig may be necessary.
Decompiled source of AbilityScrollBar v1.0.1
AbilityScrollBar.dll
Decompiled 18 hours agousing System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AbilityScrollBar")] [assembly: AssemblyConfiguration("release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("AbilityScrollBar")] [assembly: AssemblyTitle("AbilityScrollBar")] [assembly: AssemblyVersion("1.0.0.0")] namespace AbilityScrollBar; [BepInPlugin("com.owen.bopl.abilityscrollbar", "Ability Scroll Bar", "1.0.1")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; private void Awake() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"AbilityScrollBar loading..."); new Harmony("com.owen.bopl.abilityscrollbar").PatchAll(); Log.LogInfo((object)"All patches applied."); } } public class ScrollState { public float entrySize; public int rows; public float scrollOffset; public float targetOffset; public float maxOffset; public Vector2[] originalPositions; public Rect visibleRect; } public static class ScrollTracker { public static Dictionary<int, ScrollState> States = new Dictionary<int, ScrollState>(); } [HarmonyPatch(typeof(AbilityGrid), "Awake")] public class AwakePatch { public static void Postfix(AbilityGrid __instance) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) AbilityGridEntry[] value = Traverse.Create((object)__instance).Field("grid").GetValue<AbilityGridEntry[]>(); RectTransform value2 = Traverse.Create((object)__instance).Field("recTrans").GetValue<RectTransform>(); float value3 = Traverse.Create((object)__instance).Field("entrySize").GetValue<float>(); int value4 = Traverse.Create((object)__instance).Field("rows").GetValue<int>(); if (value == null || value.Length == 0 || (Object)(object)value2 == (Object)null) { return; } Rect rect = value2.rect; float y = value[^1].rectTrans.anchoredPosition.y; float num = value3 * 0.5f; if (y - num >= ((Rect)(ref rect)).yMin) { return; } Plugin.Log.LogInfo((object)("[AbilityScrollBar] Overflow detected, adding scroll. " + $"entries={value.Length}, bottomY={y:F0}, rectYMin={((Rect)(ref rect)).yMin:F0}")); GameObject val = new GameObject("EntryClipArea"); RectTransform val2 = val.AddComponent<RectTransform>(); val.transform.SetParent((Transform)(object)value2, false); val2.anchorMin = Vector2.zero; val2.anchorMax = Vector2.one; val2.offsetMin = Vector2.zero; val2.offsetMax = Vector2.zero; val2.pivot = value2.pivot; val.AddComponent<RectMask2D>(); for (int i = 0; i < value.Length; i++) { ((Component)value[i]).transform.SetParent((Transform)(object)val2, false); } if ((Object)(object)__instance.selectionCircle != (Object)null) { ((Transform)__instance.selectionCircle).SetParent((Transform)(object)val2, false); } Vector2[] array = (Vector2[])(object)new Vector2[value.Length]; for (int j = 0; j < value.Length; j++) { array[j] = value[j].rectTrans.anchoredPosition; } float num2 = float.MaxValue; float num3 = float.MinValue; for (int k = 0; k < value.Length; k++) { float x = array[k].x; if (x < num2) { num2 = x; } if (x > num3) { num3 = x; } } float num4 = (num2 + num3) * 0.5f; float num5 = ((Rect)(ref rect)).center.x - num4; if (Mathf.Abs(num5) > 1f) { for (int l = 0; l < value.Length; l++) { array[l] = new Vector2(array[l].x + num5, array[l].y); value[l].rectTrans.anchoredPosition = array[l]; } } float maxOffset = Mathf.Max(0f, ((Rect)(ref rect)).yMin + num - y); int instanceID = ((Object)((Component)__instance).gameObject).GetInstanceID(); ScrollTracker.States[instanceID] = new ScrollState { entrySize = value3, rows = value4, scrollOffset = 0f, targetOffset = 0f, maxOffset = maxOffset, originalPositions = array, visibleRect = rect }; if ((Object)(object)((Component)__instance).GetComponent<WheelScroller>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<WheelScroller>().gridId = instanceID; } } } [HarmonyPatch(typeof(AbilityGrid), "Update")] public class UpdatePatch { public static void Postfix(AbilityGrid __instance) { //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) int instanceID = ((Object)((Component)__instance).gameObject).GetInstanceID(); if (!ScrollTracker.States.ContainsKey(instanceID)) { return; } ScrollState scrollState = ScrollTracker.States[instanceID]; AbilityGridEntry[] value = Traverse.Create((object)__instance).Field("grid").GetValue<AbilityGridEntry[]>(); if (value == null) { return; } int selectedIcon = __instance.SelectedIcon; if (selectedIcon < 0 || selectedIcon >= scrollState.originalPositions.Length) { return; } float y = scrollState.originalPositions[selectedIcon].y; float num = y + scrollState.scrollOffset; float num2 = scrollState.entrySize * 0.55f; float num3 = ((Rect)(ref scrollState.visibleRect)).yMax - num2; float num4 = ((Rect)(ref scrollState.visibleRect)).yMin + num2; if (num > num3) { scrollState.targetOffset = num3 - y; } else if (num < num4) { scrollState.targetOffset = num4 - y; } scrollState.targetOffset = Mathf.Clamp(scrollState.targetOffset, 0f, scrollState.maxOffset); scrollState.scrollOffset = Mathf.Lerp(scrollState.scrollOffset, scrollState.targetOffset, Time.deltaTime * 14f); for (int i = 0; i < value.Length && i < scrollState.originalPositions.Length; i++) { if ((Object)(object)value[i] != (Object)null && (Object)(object)value[i].rectTrans != (Object)null) { Vector2 anchoredPosition = scrollState.originalPositions[i]; anchoredPosition.y += scrollState.scrollOffset; value[i].rectTrans.anchoredPosition = anchoredPosition; } } if ((Object)(object)__instance.selectionCircle != (Object)null && selectedIcon < value.Length && (Object)(object)value[selectedIcon] != (Object)null) { __instance.selectionCircle.anchoredPosition = value[selectedIcon].rectTrans.anchoredPosition; } } } [HarmonyPatch(typeof(AbilityGrid), "Init")] public class InitPatch { public static void Postfix(AbilityGrid __instance, int startSelection) { int instanceID = ((Object)((Component)__instance).gameObject).GetInstanceID(); if (ScrollTracker.States.ContainsKey(instanceID)) { ScrollState scrollState = ScrollTracker.States[instanceID]; int num = startSelection - 1; if (num < 0 || num >= scrollState.originalPositions.Length) { num = 0; } float y = scrollState.originalPositions[num].y; float num2 = ((Rect)(ref scrollState.visibleRect)).yMin + scrollState.entrySize * 0.55f; if (y < num2) { scrollState.targetOffset = num2 - y; } else { scrollState.targetOffset = 0f; } scrollState.targetOffset = Mathf.Clamp(scrollState.targetOffset, 0f, scrollState.maxOffset); scrollState.scrollOffset = scrollState.targetOffset; } } } public class WheelScroller : MonoBehaviour { public int gridId; private void Update() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (!ScrollTracker.States.ContainsKey(gridId)) { return; } Mouse current = Mouse.current; if (current != null) { float y = ((InputControl<Vector2>)(object)current.scroll).ReadValue().y; if (!(Mathf.Abs(y) < 0.1f)) { ScrollState scrollState = ScrollTracker.States[gridId]; float num = y / 120f; scrollState.targetOffset -= num * scrollState.entrySize * 0.8f; scrollState.targetOffset = Mathf.Clamp(scrollState.targetOffset, 0f, scrollState.maxOffset); } } } }