Decompiled source of HotbarTweaks v1.0.1

BepInEx/plugins/HotbarTweaks.dll

Decompiled 12 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using HotbarTweaks.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("FastScrolling")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FastScrolling")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8d060420-bc91-44d4-8aeb-9c4ef14230b7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HotbarTweaks
{
	[BepInPlugin("HotbarTweaks", "Hotbar Tweaks", "1.0.0")]
	public class ModBase : BaseUnityPlugin
	{
		private const string modGUID = "HotbarTweaks";

		private const string modName = "Hotbar Tweaks";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("HotbarTweaks");

		internal ManualLogSource mls;

		public static ConfigEntry<float> ScrollSpeedConfig { get; private set; }

		public static ConfigEntry<bool> InvertDirectionConfig { get; private set; }

		private void Awake()
		{
			ScrollSpeedConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScrollSpeed", 0.3f, "Change the speed when you scroll through the hotbar. The lower the value is, the faster the scroll will be");
			InvertDirectionConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "InvertDirection", false, "Invert the direction of the scroll with the hotbar");
			mls = Logger.CreateLogSource("HotbarTweaks");
			mls.LogInfo((object)"The mod is working!");
			harmony.PatchAll(typeof(ModBase));
			harmony.PatchAll(typeof(ScrollBPatch));
			if (InvertDirectionConfig.Value)
			{
				harmony.PatchAll(typeof(DirectionBPatch));
			}
		}
	}
}
namespace HotbarTweaks.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class DirectionBPatch
	{
		[HarmonyPatch("SwitchItem_performed")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> InvertControlsSwitchItemPerformed(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return new CodeMatcher(instructions, (ILGenerator)null).SearchForward((Func<CodeInstruction, bool>)delegate(CodeInstruction instruction)
			{
				string name = instruction.opcode.Name;
				OpCode ble_Un = OpCodes.Ble_Un;
				return name == ble_Un.Name;
			}).ThrowIfInvalid("Could not find instruction").SetOpcodeAndAdvance(OpCodes.Bge_Un_S)
				.InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	[HarmonyPatch("SwitchItem_performed")]
	internal class ScrollBPatch
	{
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldc_R4 && (float)instruction.operand == 0.3f)
				{
					instruction.operand = ModBase.ScrollSpeedConfig.Value;
				}
				yield return instruction;
			}
		}
	}
}
namespace InputAction
{
	internal class CallbackContext
	{
	}
}