Decompiled source of SpeedToggle v1.0.0

SpeedToggle.dll

Decompiled 4 hours ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using LethalCompanyInputUtils.BindingPathEnums;
using SpeedToggle.Patches;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SpeedToggle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SpeedToggle")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("35917f0b-5256-439c-bd34-f92e55748b3a")]
[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 SpeedToggle
{
	[BepInPlugin("Overmusician.Speedmod", "Speed Toggle", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class SpeedBase : BaseUnityPlugin
	{
		private const string modGUID = "Overmusician.Speedmod";

		private const string modName = "Speed Toggle";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Overmusician.Speedmod");

		private static SpeedBase Instance;

		internal ManualLogSource mls;

		internal static MyExampleInputClass InputActionsInstance;

		private KeyHandler kh = new KeyHandler();

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Overmusician.Speedmod");
			mls.LogInfo((object)"The test mod has awakened");
			kh.SetupKeybindCallbacks();
			harmony.PatchAll(typeof(SpeedBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
	public class MyExampleInputClass : LcInputActions
	{
		public static readonly MyExampleInputClass Instance = new MyExampleInputClass();

		public InputAction fastKey => ((LcInputActions)this).Asset["Fastkey"];

		public InputAction slowKey => ((LcInputActions)this).Asset["Slowkey"];

		public override void CreateInputActions(in InputActionMapBuilder builder)
		{
			builder.NewActionBinding().WithActionId("Fastkey").WithActionType((InputActionType)1)
				.WithKeyboardControl((KeyboardControl)28)
				.WithBindingName("SpeedUp")
				.Finish();
			builder.NewActionBinding().WithActionId("Slowkey").WithActionType((InputActionType)1)
				.WithKeyboardControl((KeyboardControl)30)
				.WithBindingName("SlowDown")
				.Finish();
		}
	}
}
namespace SpeedToggle.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static KeyHandler kh = new KeyHandler();

		private static float mult = 5f;

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void Speedchanger(ref float ___movementSpeed, ref bool ___isSprinting, ref float ___sprintMeter)
		{
			___movementSpeed = mult;
			if (mult == 15f)
			{
				if (___isSprinting)
				{
					___sprintMeter -= 0.001f;
				}
				if (!___isSprinting)
				{
					___movementSpeed = 5f;
				}
			}
			else if (mult == 2.5f)
			{
				if (___isSprinting)
				{
					___sprintMeter += 0.00025f;
				}
				if (!___isSprinting)
				{
					___sprintMeter += 0.0005f;
				}
			}
		}

		public static void numr(float speedmult)
		{
			mult = speedmult;
		}
	}
	public class KeyHandler
	{
		internal ManualLogSource mls;

		private float Speedmult { get; set; } = 5f;


		public float getSpeedmult()
		{
			return Speedmult;
		}

		public void SetupKeybindCallbacks()
		{
			MyExampleInputClass.Instance.fastKey.performed += speedup;
			MyExampleInputClass.Instance.slowKey.performed += slowdown;
		}

		public void speedup(CallbackContext speedup)
		{
			if (((CallbackContext)(ref speedup)).performed)
			{
				if (Speedmult < 5f)
				{
					Speedmult = 5f;
				}
				else
				{
					Speedmult = 15f;
				}
				PlayerControllerBPatch.numr(Speedmult);
			}
		}

		public void slowdown(CallbackContext slowdown)
		{
			if (((CallbackContext)(ref slowdown)).performed)
			{
				if (Speedmult > 5f)
				{
					Speedmult = 5f;
				}
				else
				{
					Speedmult = 2.5f;
				}
				PlayerControllerBPatch.numr(Speedmult);
			}
		}
	}
}