Decompiled source of Movement Speed Controller v1.0.0

Movement_Speed_Controller.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Main")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Main")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0398ef00-60d2-4cc9-a164-429cea88a28c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PeakSpeedMod;

[BepInPlugin("TropicalFrog3.SpeedMod", "Peak Speed Mod", "1.0.0.0")]
public class SpeedMod : BaseUnityPlugin
{
	public const string modGUID = "TropicalFrog3.SpeedMod";

	public const string modName = "Peak Speed Mod";

	public const string modVersion = "1.0.0.0";

	private readonly Harmony harmony = new Harmony("TropicalFrog3.SpeedMod");

	public static float speedMultiplier = 1f;

	private static float speedChangeAmount = 1f;

	private bool isIncreasingHeld;

	private bool isDecreasingHeld;

	private float increaseHoldTimer;

	private float decreaseHoldTimer;

	private float repeatInterval = 0.1f;

	private float firstRepeatDelay = 0.25f;

	private Key increaseKey;

	private Key decreaseKey;

	private Canvas speedCanvas;

	private Text speedText;

	private float displayDuration = 2f;

	private float displayTimer;

	public static bool isInARun = false;

	private ConfigEntry<float> configSpeedChangeAmount;

	private ConfigEntry<Key> configIncreaseKey;

	private ConfigEntry<Key> configDecreaseKey;

	private void Awake()
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"TropicalFrog3.SpeedMod loaded successfully.");
		configSpeedChangeAmount = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SpeedChangeAmount", 1f, "Amount by which the speed multiplier changes when adjusting speed");
		configIncreaseKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Keybinds", "IncreaseSpeedKey", (Key)14, "Key to increase speed multiplier");
		configDecreaseKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Keybinds", "DecreaseSpeedKey", (Key)13, "Key to decrease speed multiplier");
		speedChangeAmount = configSpeedChangeAmount.Value;
		increaseKey = configIncreaseKey.Value;
		decreaseKey = configDecreaseKey.Value;
		harmony.PatchAll(typeof(CharacterSpeed));
		harmony.PatchAll(typeof(RunManagerPatch));
		harmony.PatchAll(typeof(EndGamePatch));
		CreateSpeedDisplayUI();
	}

	private void Update()
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)speedText == (Object)null)
		{
			return;
		}
		if (displayTimer > 0f)
		{
			displayTimer -= Time.deltaTime;
			if (displayTimer <= 0f)
			{
				((Component)speedText).gameObject.SetActive(false);
			}
		}
		if (((ButtonControl)Keyboard.current[increaseKey]).wasPressedThisFrame)
		{
			speedMultiplier += speedChangeAmount;
			ShowSpeedTextTemporarily();
			isIncreasingHeld = true;
			increaseHoldTimer = 0f;
		}
		if (((ButtonControl)Keyboard.current[increaseKey]).wasReleasedThisFrame)
		{
			isIncreasingHeld = false;
		}
		if (isIncreasingHeld && ((ButtonControl)Keyboard.current[increaseKey]).isPressed)
		{
			increaseHoldTimer += Time.deltaTime;
			if (increaseHoldTimer > firstRepeatDelay)
			{
				float num = Mathf.Floor((increaseHoldTimer - firstRepeatDelay) / repeatInterval);
				if (num > 0f)
				{
					speedMultiplier += speedChangeAmount;
					ShowSpeedTextTemporarily();
					increaseHoldTimer -= repeatInterval * num;
				}
			}
		}
		if (((ButtonControl)Keyboard.current[decreaseKey]).wasPressedThisFrame)
		{
			speedMultiplier = Mathf.Max(1f, speedMultiplier - speedChangeAmount);
			ShowSpeedTextTemporarily();
			isDecreasingHeld = true;
			decreaseHoldTimer = 0f;
		}
		if (((ButtonControl)Keyboard.current[decreaseKey]).wasReleasedThisFrame)
		{
			isDecreasingHeld = false;
		}
		if (!isDecreasingHeld || !((ButtonControl)Keyboard.current[decreaseKey]).isPressed)
		{
			return;
		}
		decreaseHoldTimer += Time.deltaTime;
		if (decreaseHoldTimer > firstRepeatDelay)
		{
			float num2 = Mathf.Floor((decreaseHoldTimer - firstRepeatDelay) / repeatInterval);
			if (num2 > 0f)
			{
				speedMultiplier = Mathf.Max(1f, speedMultiplier - speedChangeAmount);
				ShowSpeedTextTemporarily();
				decreaseHoldTimer -= repeatInterval * num2;
			}
		}
	}

	private void CreateSpeedDisplayUI()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("SpeedDisplayCanvas");
		speedCanvas = val.AddComponent<Canvas>();
		speedCanvas.renderMode = (RenderMode)0;
		val.AddComponent<CanvasScaler>();
		val.AddComponent<GraphicRaycaster>();
		Object.DontDestroyOnLoad((Object)(object)val);
		GameObject val2 = new GameObject("SpeedText");
		val2.transform.SetParent(val.transform);
		speedText = val2.AddComponent<Text>();
		speedText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
		speedText.fontSize = 24;
		speedText.alignment = (TextAnchor)7;
		RectTransform component = ((Component)speedText).GetComponent<RectTransform>();
		component.anchorMin = new Vector2(0.5f, 0f);
		component.anchorMax = new Vector2(0.5f, 0f);
		component.pivot = new Vector2(0.5f, 0f);
		component.anchoredPosition = new Vector2(0f, 10f);
		component.sizeDelta = new Vector2(300f, 30f);
		((Graphic)speedText).color = Color.white;
		speedText.text = $"Speed: {speedMultiplier:F2}x";
		((Component)speedText).gameObject.SetActive(false);
	}

	private void ShowSpeedTextTemporarily()
	{
		if ((Object)(object)speedText != (Object)null && isInARun)
		{
			((Component)speedText).gameObject.SetActive(true);
			speedText.text = $"Speed: {speedMultiplier:F2}x";
			displayTimer = displayDuration;
		}
	}
}
[HarmonyPatch(typeof(CharacterMovement))]
[HarmonyPatch("GetMovementForce")]
internal class CharacterSpeed
{
	[HarmonyPostfix]
	private static void Postfix(ref float ___movementModifier)
	{
		___movementModifier = SpeedMod.speedMultiplier;
	}
}
[HarmonyPatch(typeof(RunManager))]
[HarmonyPatch("StartRun")]
internal class RunManagerPatch
{
	[HarmonyPostfix]
	private static void Postfix()
	{
		SpeedMod.speedMultiplier = 1f;
		SpeedMod.isInARun = true;
	}
}
[HarmonyPatch(typeof(RunManager))]
[HarmonyPatch("EndGame")]
internal class EndGamePatch
{
	[HarmonyPostfix]
	private static void Postfix()
	{
		SpeedMod.isInARun = false;
		SpeedMod.speedMultiplier = 1f;
	}
}