Decompiled source of QuickTerminalRestart v1.0.3

BepInEx/plugins/QuickTerminalRestart.dll

Decompiled a year ago
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
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: AssemblyTitle("QuickTerminalRestart")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("QuickTerminalRestart")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f32963bd-f9b5-4391-b4eb-297bb52a3b24")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace QuickTerminalRestart;

[BepInPlugin("QuickTerminalRestart", "QuickTerminalRestart", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private const string PLUGIN_GUID = "QuickTerminalRestart";

	private const string PLUGIN_NAME = "QuickTerminalRestart";

	private const string PLUGIN_VERSION = "1.0.0";

	public static Plugin Instance;

	internal ManualLogSource logger;

	private Harmony harmony;

	public bool awaitingRestartConfirmation = false;

	private void Awake()
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
			logger = Logger.CreateLogSource("QuickTerminalRestart");
			logger.LogInfo((object)"Plugin QuickTerminalRestart is loaded!");
			harmony = new Harmony("QuickTerminalRestart");
			harmony.PatchAll();
		}
	}

	public void RequestRestart(StartOfRound playersManager, float delay)
	{
		((MonoBehaviour)this).StartCoroutine(RestartAfterDelay(playersManager, delay));
	}

	private IEnumerator RestartAfterDelay(StartOfRound playersManager, float delay)
	{
		yield return (object)new WaitForSeconds(delay);
		PerformRestart(playersManager);
	}

	public static void PerformRestart(StartOfRound manager)
	{
		Instance.awaitingRestartConfirmation = false;
		int[] array = new int[4]
		{
			manager.gameStats.daysSpent,
			manager.gameStats.scrapValueCollected,
			manager.gameStats.deaths,
			manager.gameStats.allStepsTaken
		};
		manager.FirePlayersAfterDeadlineClientRpc(array);
	}
}
[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
public static class TerminalParsePlayerSentencePatch
{
	public static bool Prefix(Terminal __instance, ref TerminalNode __result)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		string[] array = __instance.screenText.text.Split(new char[1] { '\n' });
		if (array.Length == 0)
		{
			return true;
		}
		string[] array2 = array.Last().Trim().ToLower()
			.Split(new char[1] { ' ' });
		PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
		if ((Object)localPlayerController == (Object)null)
		{
			return true;
		}
		StartOfRound playersManager = localPlayerController.playersManager;
		if ((Object)playersManager == (Object)null)
		{
			return true;
		}
		if (array2[0] == "restart")
		{
			if (!GameNetworkManager.Instance.isHostingGame)
			{
				__result = CreateTerminalNode("Only the host can restart.");
				return false;
			}
			if (!playersManager.inShipPhase || playersManager.travellingToNewLevel)
			{
				__result = CreateTerminalNode("Cannot restart, ship must be in orbit.");
				return false;
			}
			if (array2.Length <= 1)
			{
				__result = CreateTerminalNode("Restart requested. Please CONFIRM or DENY.");
				Plugin.Instance.awaitingRestartConfirmation = true;
				return false;
			}
			if (array2[1] == "o" || array2[1] == "override")
			{
				__result = CreateTerminalNode("Restart override detected. Processing the requested restart...");
				Plugin.Instance.RequestRestart(playersManager, 2f);
				return false;
			}
			if (Plugin.Instance.awaitingRestartConfirmation)
			{
				if (array2[1] == "c" || array2[1] == "confirm")
				{
					__result = CreateTerminalNode("Restart confirmed. Processing the requested restart...");
					Plugin.Instance.RequestRestart(playersManager, 2f);
					return false;
				}
				if (array2[1] == "d" || array2[1] == "deny")
				{
					Plugin.Instance.awaitingRestartConfirmation = false;
					__result = CreateTerminalNode("Restart aborted.");
					return false;
				}
			}
		}
		else if (Plugin.Instance.awaitingRestartConfirmation)
		{
			if (array2[0] == "c" || array2[0] == "confirm")
			{
				__result = CreateTerminalNode("Restart confirmed. Processing the requested restart...");
				Plugin.Instance.RequestRestart(playersManager, 2f);
				return false;
			}
			if (array2[0] == "d" || array2[0] == "deny")
			{
				Plugin.Instance.awaitingRestartConfirmation = false;
				__result = CreateTerminalNode("Restart aborted.");
				return false;
			}
			Plugin.Instance.awaitingRestartConfirmation = false;
		}
		return true;
	}

	private static TerminalNode CreateTerminalNode(string message)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		return new TerminalNode
		{
			displayText = message,
			clearPreviousText = true
		};
	}
}