Decompiled source of Game Speed Hotkeys v1.0.0

GameSpeedHotkeys.dll

Decompiled 7 hours ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace YourTeam.GameSpeedHotkeys;

[BepInPlugin("com.yourteam.gamespeedhotkeys", "Game Speed Hotkeys", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private ConfigEntry<KeyCode>[] keys;

	private ConfigEntry<float>[] speeds;

	private float current = 1f;

	private static readonly KeyCode[] DefaultKeys;

	private static readonly float[] DefaultSpeeds;

	private void Awake()
	{
		keys = new ConfigEntry<KeyCode>[DefaultKeys.Length];
		speeds = new ConfigEntry<float>[DefaultKeys.Length];
		for (int i = 0; i < DefaultKeys.Length; i++)
		{
			string text = "Preset " + (i + 1);
			keys[i] = ((BaseUnityPlugin)this).Config.Bind<KeyCode>(text, "Key", DefaultKeys[i], "Hotkey for this speed");
			speeds[i] = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Speed", DefaultSpeeds[i], "Time scale multiplier");
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Game Speed Hotkeys loaded");
	}

	private void Update()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < keys.Length; i++)
		{
			if (Input.GetKeyDown(keys[i].Value))
			{
				current = ((!Mathf.Approximately(current, speeds[i].Value)) ? speeds[i].Value : 1f);
				Time.timeScale = current;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Time scale: " + current));
			}
		}
	}

	static Plugin()
	{
		KeyCode[] array = new KeyCode[7];
		RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		DefaultKeys = (KeyCode[])(object)array;
		DefaultSpeeds = new float[7] { 0.25f, 1f, 2f, 5f, 10f, 15f, 0.001f };
	}
}