Decompiled source of EnhancedHotbar v1.0.0

plugins/enhancedHotbar.dll

Decompiled 3 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using enhancedHotbar.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("enhancedHotbar")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("enhancedHotbar")]
[assembly: AssemblyTitle("enhancedHotbar")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace enhancedHotbar
{
	[BepInPlugin("jukepilot.enhancedHotbar", "enhancedHotbar", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string modGUID = "jukepilot.enhancedHotbar";

		public const string modName = "enhancedHotbar";

		public const string modVersion = "1.0.0";

		private static Harmony _harmony = new Harmony("jukepilot.enhancedHotbar");

		internal static ManualLogSource mls = Logger.CreateLogSource("jukepilot.enhancedHotbar");

		public static ConfigEntry<double> scrollSpeed;

		public static ConfigEntry<bool> invertScroll;

		private void Awake()
		{
			scrollSpeed = ((BaseUnityPlugin)this).Config.Bind<double>("General", "Scroll Speed", 0.2, "The cooldown between switching ItemSlots.");
			invertScroll = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Invert Scroll", true, "The direction you scroll to switch ItemSlots.");
			mls.LogInfo((object)">>> EnhancedHotbar has been initialized!");
			PatchAll();
		}

		private static void PatchAll()
		{
			_harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace enhancedHotbar.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("ScrollMouse_performed")]
		[HarmonyPrefix]
		private static bool ScrollMousePerformedPrefix(PlayerControllerB __instance, CallbackContext context)
		{
			if (__instance.inTerminalMenu)
			{
				float num = ((CallbackContext)(ref context)).ReadValue<float>();
				Scrollbar terminalScrollVertical = __instance.terminalScrollVertical;
				terminalScrollVertical.value += num / 3f;
			}
			else if (((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer) && !((double)__instance.timeSinceSwitchingSlots < Plugin.scrollSpeed.Value) && !__instance.isGrabbingObjectAnimation && !__instance.quickMenuManager.isMenuOpen && !__instance.inSpecialInteractAnimation && !__instance.throwingObject && !__instance.isTypingChat && !__instance.twoHanded && !__instance.activatingItem && !__instance.jetpackControls && !__instance.disablingJetpackControls)
			{
				ShipBuildModeManager.Instance.CancelBuildMode(true);
				__instance.playerBodyAnimator.SetBool("GrabValidated", false);
				bool flag = ((CallbackContext)(ref context)).ReadValue<float>() > 0f;
				if (Plugin.invertScroll.Value)
				{
					flag = !flag;
				}
				__instance.SwitchToItemSlot(__instance.NextItemSlot(flag), (GrabbableObject)null);
				__instance.SwitchItemSlotsServerRpc(flag);
				if ((Object)(object)__instance.currentlyHeldObjectServer != (Object)null)
				{
					((Component)__instance.currentlyHeldObjectServer).gameObject.GetComponent<AudioSource>().PlayOneShot(__instance.currentlyHeldObjectServer.itemProperties.grabSFX, 0.6f);
				}
				__instance.timeSinceSwitchingSlots = 0f;
			}
			return false;
		}
	}
}