Decompiled source of QuickRestart v1.2.0

QuickRestart.dll

Decompiled 11 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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("QuickRestart")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a395cfe8aac0ee2687d75817f75fae451f729511")]
[assembly: AssemblyProduct("QuickRestart")]
[assembly: AssemblyTitle("QuickRestart")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 QuickRestart
{
	[BepInPlugin("QuickRestart", "QuickRestart", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static bool verifying;

		private ConfigEntry<bool> overrideConfirmation;

		public static bool bypassConfirm;

		private Harmony harmony;

		private static MethodInfo chat;

		private void Awake()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			overrideConfirmation = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "Override Confirmation", false, "Ignore the confirmation step of restarting.");
			bypassConfirm = overrideConfirmation.Value;
			harmony = new Harmony("QuickRestart");
			harmony.PatchAll();
			chat = AccessTools.Method(typeof(HUDManager), "AddChatMessage", (Type[])null, (Type[])null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"QuickRestart loaded!");
		}

		public static void SendChatMessage(string message)
		{
			chat?.Invoke(HUDManager.Instance, new object[2] { message, "" });
			HUDManager.Instance.lastChatMessage = "";
		}

		public static void ConfirmRestart()
		{
			verifying = true;
			SendChatMessage("Are you sure? Type CONFIRM or DENY.");
		}

		public static void AcceptRestart(StartOfRound manager)
		{
			SendChatMessage("Restart confirmed.");
			verifying = false;
			int[] array = new int[4]
			{
				manager.gameStats.daysSpent,
				manager.gameStats.scrapValueCollected,
				manager.gameStats.deaths,
				manager.gameStats.allStepsTaken
			};
			manager.FirePlayersAfterDeadlineClientRpc(array, false);
		}

		public static void DeclineRestart()
		{
			SendChatMessage("Restart aborted.");
			verifying = false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "QuickRestart";

		public const string PLUGIN_NAME = "QuickRestart";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace QuickRestart.Patches
{
	[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
	public class SubmitChat
	{
		private static bool Prefix(HUDManager __instance, ref CallbackContext context)
		{
			if (!((CallbackContext)(ref context)).performed)
			{
				return true;
			}
			if (string.IsNullOrEmpty(__instance.chatTextField.text))
			{
				return true;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null)
			{
				return true;
			}
			StartOfRound playersManager = localPlayerController.playersManager;
			if ((Object)(object)playersManager == (Object)null)
			{
				return true;
			}
			string text = __instance.chatTextField.text;
			if (Plugin.verifying)
			{
				if (text.ToLower() == "confirm")
				{
					ResetTextbox(__instance, localPlayerController);
					if (!localPlayerController.isInHangarShipRoom || !playersManager.inShipPhase || playersManager.travellingToNewLevel)
					{
						Plugin.SendChatMessage("Cannot restart, ship must be in orbit.");
						return false;
					}
					Plugin.AcceptRestart(playersManager);
					return false;
				}
				if (text.ToLower() == "deny")
				{
					ResetTextbox(__instance, localPlayerController);
					Plugin.DeclineRestart();
					return false;
				}
				return true;
			}
			if (text == "/restart")
			{
				ResetTextbox(__instance, localPlayerController);
				if (!GameNetworkManager.Instance.isHostingGame)
				{
					Plugin.SendChatMessage("Only the host can restart.");
					return false;
				}
				if (!localPlayerController.isInHangarShipRoom || !playersManager.inShipPhase || playersManager.travellingToNewLevel)
				{
					Plugin.SendChatMessage("Cannot restart, ship must be in orbit.");
					return false;
				}
				if (Plugin.bypassConfirm)
				{
					Plugin.AcceptRestart(playersManager);
				}
				else
				{
					Plugin.ConfirmRestart();
				}
				return false;
			}
			return true;
		}

		private static void ResetTextbox(HUDManager manager, PlayerControllerB local)
		{
			local.isTypingChat = false;
			manager.chatTextField.text = "";
			EventSystem.current.SetSelectedGameObject((GameObject)null);
			manager.PingHUDElement(manager.Chat, 2f, 1f, 0.2f);
			((Behaviour)manager.typingIndicator).enabled = false;
		}
	}
}