Decompiled source of QuickestRestart v1.0.1

plugins/QuickestRestart.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("QuickestRestart")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("One button restart or quit. R and Q by default.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("QuickestRestart")]
[assembly: AssemblyTitle("QuickestRestart")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace QuickestRestart;

[BepInPlugin("QuickestRestart", "QuickestRestart", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(GameController), "Update")]
	public static class GameControllerUpdatePatches
	{
		public static void Postfix(GameController __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.retrying && !actuallyQuitting)
			{
				if (Input.GetKey(RestartKey.Value) && !IsConnectedToMultiplayer())
				{
					__instance.quitting = true;
					__instance.pauseRetryLevel();
				}
				else if (Input.GetKey(QuitKey.Value) && !IsConnectedToMultiplayer())
				{
					__instance.quitting = true;
					__instance.pauseQuitLevel();
				}
			}
		}
	}

	[HarmonyPatch(typeof(GameController), "Start")]
	public static class GameControllerStartPatches
	{
		public static void Postfix()
		{
			actuallyQuitting = false;
		}
	}

	[HarmonyPatch(typeof(GameController), "pauseQuitLevel")]
	public static class GameControllerPauseQuitLevelPatches
	{
		public static void Prefix()
		{
			actuallyQuitting = true;
		}
	}

	private const KeyCode DEFAULT_RESTART_KEY = 114;

	private const KeyCode DEFAULT_QUIT_KEY = 113;

	private static bool actuallyQuitting;

	public static ConfigEntry<KeyCode> RestartKey { get; set; }

	public static ConfigEntry<KeyCode> QuitKey { get; set; }

	public void Awake()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		RestartKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("KeyBinds", "RestartKey", (KeyCode)114, (ConfigDescription)null);
		QuitKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("KeyBinds", "QuitKey", (KeyCode)113, (ConfigDescription)null);
		new Harmony("QuickestRestart").PatchAll();
	}

	public static bool IsConnectedToMultiplayer()
	{
		Type type = Type.GetType("TootTallyMultiplayer.MultiplayerManager, TootTallyMultiplayer");
		return type != null && (bool)type.GetProperty("IsConnectedToMultiplayer").GetValue(type, null);
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "QuickestRestart";

	public const string PLUGIN_NAME = "QuickestRestart";

	public const string PLUGIN_VERSION = "1.0.1";
}