Decompiled source of QuickRestart v1.1.2

QRestart.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Linq;
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 Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[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("QRestart")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyProduct("Quick Restart")]
[assembly: AssemblyTitle("QRestart")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.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 QRestart
{
	[BepInPlugin("QRestart", "Quick Restart", "1.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		private static int restartComboCounter = 0;

		private static float reset = 0f;

		private static TextMeshProUGUI comboText;

		private const KeyCode defaultComboKey = 114;

		private static readonly string[] sceneBlacklist = new string[2] { "Intro", "Main-Menu" };

		private ConfigEntry<KeyCode> configComboKey;

		private ConfigEntry<int> configMaxCounter;

		private ConfigEntry<float> configResetMaxTime;

		private ConfigEntry<bool> configHoldInstead;

		private void Awake()
		{
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogMessage((object)"Plugin Quick Restart has loaded!");
			configComboKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybind", "RestartBind", (KeyCode)114, "The keybind for quick restart.");
			configMaxCounter = ((BaseUnityPlugin)this).Config.Bind<int>("Keybind", "KeyPresses", 3, "How many times do you need to press RestartBind to restart");
			configResetMaxTime = ((BaseUnityPlugin)this).Config.Bind<float>("Keybind", "TimeToReset", 1.5f, "How long after last RestartBind press to reset the counter");
			configHoldInstead = ((BaseUnityPlugin)this).Config.Bind<bool>("Keybind", "HoldInstead", false, "If enabled, TimeToReset instead acts as how long you need to hold RestartBind to restart. Makes KeyPresses have no effect. You should adjust the time.");
			SceneManager.sceneLoaded += OnSceneLoad;
		}

		private void OnSceneLoad(Scene scene, LoadSceneMode mode)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (!sceneBlacklist.Contains(((Scene)(ref scene)).name))
			{
				CL_UIManager uiMan = CL_GameManager.gMan.uiMan;
				GameObject val = Object.Instantiate<GameObject>(((Component)uiMan.timer).gameObject, ((Component)((Component)((Component)uiMan.timer).gameObject.transform.parent).transform.parent).transform);
				((Object)val).name = "Combo Counter";
				val.SetActive(false);
				comboText = val.GetComponent<TextMeshProUGUI>();
				((TMP_Text)comboText).horizontalAlignment = (HorizontalAlignmentOptions)2;
				((TMP_Text)comboText).text = "";
				((Graphic)comboText).color = Color.white;
			}
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			string[] source = sceneBlacklist;
			Scene activeScene = SceneManager.GetActiveScene();
			if (source.Contains(((Scene)(ref activeScene)).name))
			{
				ResetCounter();
				return;
			}
			bool value = configHoldInstead.Value;
			bool flag = ((!value) ? (restartComboCounter > 0) : (reset > 0f));
			if (flag)
			{
				if (!value)
				{
					((TMP_Text)comboText).text = string.Concat(Enumerable.Repeat($"[{configComboKey.Value}] ", restartComboCounter));
					reset += Time.unscaledDeltaTime;
				}
				else
				{
					((TMP_Text)comboText).text = $"Resetting in {Mathf.Max(configResetMaxTime.Value - reset, 0f):F4}...";
				}
			}
			if (reset >= configResetMaxTime.Value && !value)
			{
				ResetCounter();
			}
			if (!CL_GameManager.gMan.lockPlayerInput)
			{
				bool flag2 = ((!value) ? Input.GetKeyDown(configComboKey.Value) : Input.GetKey(configComboKey.Value));
				if (flag2)
				{
					restartComboCounter++;
					reset = ((!value) ? 0f : (reset + Time.unscaledDeltaTime));
				}
				else if (!flag2 && value)
				{
					reset = 0f;
				}
			}
			if (flag != ((Component)comboText).gameObject.activeSelf)
			{
				((Component)comboText).gameObject.transform.SetPositionAndRotation(new Vector3((float)(Screen.width / 2), (float)(Screen.height / 2 - 64), 0f), ((Component)comboText).gameObject.transform.rotation);
				((Component)comboText).gameObject.SetActive(flag);
			}
			if (!((!value) ? (restartComboCounter < configMaxCounter.Value) : (reset < configResetMaxTime.Value)))
			{
				CL_GameManager.ChangeState("restart");
				ResetCounter();
			}
		}

		private void ResetCounter()
		{
			reset = 0f;
			restartComboCounter = 0;
			if ((Object)(object)comboText != (Object)null && ((Component)comboText).gameObject.activeSelf)
			{
				((Component)comboText).gameObject.SetActive(false);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "QRestart";

		public const string PLUGIN_NAME = "Quick Restart";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}