Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of HotbarScroll v1.0.2
HotbarScroll.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("HotbarScroll")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Azumatt")] [assembly: AssemblyProduct("HotbarScroll")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")] [assembly: AssemblyFileVersion("1.0.2")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.2.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace HotbarScroll { [BepInPlugin("Azumatt.HotbarScroll", "HotbarScroll", "1.0.2")] public class HotbarScrollPlugin : BaseUnityPlugin { public enum Toggle { On = 1, Off = 0 } private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [UsedImplicitly] public string? Category; [UsedImplicitly] public Action<ConfigEntryBase>? CustomDrawer; } private class AcceptableShortcuts : AcceptableValueBase { public AcceptableShortcuts() : base(typeof(KeyboardShortcut)) { } public override object Clamp(object value) { return value; } public override bool IsValid(object value) { return true; } public override string ToDescriptionString() { return "# Acceptable values: " + string.Join(", ", UnityInput.Current.SupportedKeyCodes); } } internal const string ModName = "HotbarScroll"; internal const string ModVersion = "1.0.2"; internal const string Author = "Azumatt"; private const string ModGUID = "Azumatt.HotbarScroll"; private static string ConfigFileName = "Azumatt.HotbarScroll.cfg"; private static string ConfigFileFullPath; private readonly Harmony _harmony = new Harmony("Azumatt.HotbarScroll"); public static readonly ManualLogSource HotbarScrollLogger; internal static ConfigEntry<KeyboardShortcut> ModifierKey; internal static ConfigEntry<Toggle> InvertedScroll; public void Awake() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown ModifierKey = config<KeyboardShortcut>("1 - General", "Modifier Key", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), new ConfigDescription("The key that must be held to scroll the hotbar.", (AcceptableValueBase)(object)new AcceptableShortcuts(), Array.Empty<object>())); InvertedScroll = config("1 - General", "Inverted Scroll", Toggle.Off, "Invert the scroll direction of the hotbar."); Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); SetupWatcher(); } private void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } private void SetupWatcher() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName); fileSystemWatcher.Changed += ReadConfigValues; fileSystemWatcher.Created += ReadConfigValues; fileSystemWatcher.Renamed += ReadConfigValues; fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; } private void ReadConfigValues(object sender, FileSystemEventArgs e) { if (!File.Exists(ConfigFileFullPath)) { return; } try { HotbarScrollLogger.LogDebug((object)"ReadConfigValues called"); ((BaseUnityPlugin)this).Config.Reload(); } catch { HotbarScrollLogger.LogError((object)("There was an issue loading your " + ConfigFileName)); HotbarScrollLogger.LogError((object)"Please check your config entries for spelling and format!"); } } private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description) { return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, description); } private ConfigEntry<T> config<T>(string group, string name, T value, string description) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>())); } static HotbarScrollPlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; HotbarScrollLogger = Logger.CreateLogSource("HotbarScroll"); ModifierKey = null; InvertedScroll = null; } } public static class KeyboardExtensions { public static bool IsKeyDown(this KeyboardShortcut shortcut) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey)) { return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey); } return false; } public static bool IsKeyHeld(this KeyboardShortcut shortcut) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKey(((KeyboardShortcut)(ref shortcut)).MainKey)) { return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey); } return false; } } [HarmonyPatch(typeof(Menu), "IsVisible")] internal static class MenuIsVisiblePatch { private static void Postfix(Menu __instance, ref bool __result) { if (HudUpdatePatch.ShouldBlockCameraScroll) { __result = true; } } } [HarmonyPatch(typeof(HotkeyBar), "OnEnable")] internal static class HotkeyBarOnEnablePatch { public const string HotbarScrollSelection = "HotbarScrollSelection"; private static void Postfix(HotkeyBar __instance) { HudUpdatePatch.CreateSelectionObjects(__instance); } } [HarmonyPatch(typeof(HotkeyBar), "Update")] internal static class HudUpdatePatch { public static bool ShouldBlockCameraScroll; [HarmonyPriority(700)] private static void Prefix(HotkeyBar __instance) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) if (((Object)__instance).name != "HotKeyBar" || __instance.m_elements.Count == 0 || (Object)(object)Player.m_localPlayer == (Object)null || InventoryGui.IsVisible() || GameCamera.InFreeFly() || Minimap.IsOpen() || Hud.IsPieceSelectionVisible() || StoreGui.IsVisible() || Console.IsVisible() || Chat.instance.HasFocus() || PlayerCustomizaton.IsBarberGuiVisible() || Hud.InRadial()) { return; } if (HotbarScrollPlugin.ModifierKey.Value.IsKeyHeld()) { float num = ZInput.GetMouseScrollWheel(); if (HotbarScrollPlugin.InvertedScroll.Value == HotbarScrollPlugin.Toggle.On) { num *= -1f; } if (num != 0f) { ScrollHotbar(__instance, num); Input.ResetInputAxes(); ShouldBlockCameraScroll = true; } } else { KeyboardShortcut value = HotbarScrollPlugin.ModifierKey.Value; if (((KeyboardShortcut)(ref value)).IsUp()) { ShouldBlockCameraScroll = false; UseSelectedItem(__instance); } } } private static void ScrollHotbar(HotkeyBar hotkeyBar, float scrollDelta) { int num = hotkeyBar.m_selected + ((scrollDelta > 0f) ? 1 : (-1)); if (num >= hotkeyBar.m_elements.Count) { num = 0; } else if (num < 0) { num = hotkeyBar.m_elements.Count - 1; } hotkeyBar.m_selected = num; UpdateSelection(hotkeyBar, num); } private static void UseSelectedItem(HotkeyBar hotkeyBar) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && hotkeyBar.m_selected >= 0 && hotkeyBar.m_selected < hotkeyBar.m_elements.Count) { localPlayer.UseHotbarItem(hotkeyBar.m_selected + 1); DeactivateSelection(hotkeyBar, hotkeyBar.m_selected); } } private static void UpdateSelection(HotkeyBar hotkeyBar, int index) { bool flag = false; for (int i = 0; i < hotkeyBar.m_elements.Count; i++) { Transform obj = hotkeyBar.m_elements[i].m_go.transform.Find("HotbarScrollSelection"); if (!((Object)(object)((obj != null) ? ((Component)obj).gameObject : null) != (Object)null)) { flag = true; break; } } if (flag) { CreateSelectionObjects(hotkeyBar); } for (int j = 0; j < hotkeyBar.m_elements.Count; j++) { ((Component)hotkeyBar.m_elements[j].m_go.transform.Find("HotbarScrollSelection")).gameObject.SetActive(j == index); } } public static void CreateSelectionObjects(HotkeyBar hotkeyBar) { if (hotkeyBar.m_elements.Count > 0 && !((Object)(object)hotkeyBar.m_elements[0].m_selection == (Object)null)) { GameObject selection = hotkeyBar.m_elements[0].m_selection; for (int i = 0; i < hotkeyBar.m_elements.Count; i++) { ElementData val = hotkeyBar.m_elements[i]; GameObject obj = Object.Instantiate<GameObject>(selection, val.m_go.transform); ((Object)obj).name = "HotbarScrollSelection"; obj.SetActive(false); } } } private static void DeactivateSelection(HotkeyBar hotkeyBar, int index) { Transform obj = hotkeyBar.m_elements[index].m_go.transform.Find("HotbarScrollSelection"); GameObject val = ((obj != null) ? ((Component)obj).gameObject : null); if ((Object)(object)val != (Object)null) { val.SetActive(false); } } } }