Decompiled source of QuickRestart v1.0.0

plugins/QuickRestart.dll

Decompiled 31 minutes ago
using System;
using System.Collections.Generic;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("QuickRestart")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f8176e13c8719152ae4a91eed8ab492e079ae0ec")]
[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]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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
{
	[HarmonyPatch(typeof(DeathScreen))]
	internal static class DeathScreenPatches
	{
		private static bool _loggedLayout;

		private static readonly HashSet<int> _wiredButtons = new HashSet<int>();

		internal static DeathScreen Current { get; private set; }

		[HarmonyPrefix]
		[HarmonyPatch("StartDeathScreen")]
		private static void BeforeStartDeathScreen(DeathScreen __instance)
		{
			Current = __instance;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnDestroy")]
		private static void BeforeOnDestroy(DeathScreen __instance)
		{
			if ((Object)(object)Current != (Object)null && ((Il2CppObjectBase)Current).Pointer == ((Il2CppObjectBase)__instance).Pointer)
			{
				Current = null;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ShowStats")]
		private static void AfterShowStats(DeathScreen __instance)
		{
			ShowRestart(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("HideVictoryScreen")]
		private static void AfterHideVictoryScreen(DeathScreen __instance)
		{
			ShowRestart(__instance);
		}

		private static void ShowRestart(DeathScreen screen)
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				GameObject restartBtn = screen.restartBtn;
				if ((Object)(object)restartBtn == (Object)null)
				{
					Plugin.Logger.LogWarning((object)"DeathScreen.restartBtn is null; game UI may have changed.");
					return;
				}
				if (!restartBtn.activeSelf)
				{
					restartBtn.SetActive(true);
				}
				EnsureClickHandler(screen, restartBtn);
				SelectionArrowPatches.PrepositionOnSummary(screen);
				if (!_loggedLayout)
				{
					_loggedLayout = true;
					Transform parent = restartBtn.transform.parent;
					ManualLogSource logger = Plugin.Logger;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(39, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Restart button shown: '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Path(restartBtn.transform));
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' (sibling ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(restartBtn.transform.GetSiblingIndex());
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" of ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Object.op_Implicit((Object)(object)parent) ? parent.childCount : 0);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
					}
					logger.LogInfo(val);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = Plugin.Logger;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to show restart button: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				logger2.LogError(val2);
			}
		}

		private static void EnsureClickHandler(DeathScreen screen, GameObject btn)
		{
			Button val = btn.GetComponent<Button>();
			if ((Object)(object)val == (Object)null)
			{
				val = btn.GetComponentInChildren<Button>(true);
			}
			if (!((Object)(object)val == (Object)null) && ((UnityEventBase)val.onClick).GetPersistentEventCount() <= 0 && _wiredButtons.Add(((Object)val).GetInstanceID()))
			{
				DeathScreen target = screen;
				Action action = delegate
				{
					target.Restart();
				};
				((UnityEvent)val.onClick).AddListener(DelegateSupport.ConvertDelegate<UnityAction>((Delegate)action));
				Plugin.Logger.LogInfo((object)"Restart button had no click handler; wired it to DeathScreen.Restart.");
			}
		}

		private static string Path(Transform t)
		{
			string text = ((Object)t).name;
			while ((Object)(object)(t = t.parent) != (Object)null)
			{
				text = ((Object)t).name + "/" + text;
			}
			return text;
		}
	}
	[BepInPlugin("com.quickrestart.megabonk", "Quick Restart", "1.0.0")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "com.quickrestart.megabonk";

		public const string Name = "Quick Restart";

		public const string Version = "1.0.0";

		internal static ManualLogSource Logger;

		public override void Load()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Harmony val = new Harmony("com.quickrestart.megabonk");
			val.PatchAll(typeof(DeathScreenPatches));
			val.PatchAll(typeof(SelectionArrowPatches));
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(8, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Quick Restart");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded");
			}
			log.LogInfo(val2);
		}
	}
	[HarmonyPatch]
	internal static class SelectionArrowPatches
	{
		private static MyButton _pending;

		private static bool _logged;

		internal static void PrepositionOnSummary(DeathScreen screen)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			try
			{
				Window val = (((Object)(object)screen.restartBtn != (Object)null) ? screen.restartBtn.GetComponentInParent<Window>() : null);
				MyButton val2 = (((Object)(object)val != (Object)null) ? val.startBtn : null);
				if ((Object)(object)val2 == (Object)null)
				{
					Plugin.Logger.LogWarning((object)"Summary window or its start button not found; cursor left to the game.");
					return;
				}
				_pending = val2;
				Point(SelectionArrow.Instance, val2);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Cursor pre-positioning failed: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val3);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SelectionArrow), "Update")]
		private static void AfterArrowUpdate(SelectionArrow __instance)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if ((Object)(object)_pending == (Object)null)
			{
				return;
			}
			MyButton pending = _pending;
			_pending = null;
			bool flag = default(bool);
			try
			{
				if ((Object)(object)DeathScreenPatches.Current == (Object)null || !((Component)pending).gameObject.activeInHierarchy)
				{
					return;
				}
				Point(__instance, pending);
				if (!_logged)
				{
					_logged = true;
					ManualLogSource logger = Plugin.Logger;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(48, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Cursor moved to '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)pending).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' as the summary window opened.");
					}
					logger.LogInfo(val);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = Plugin.Logger;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Cursor pre-positioning failed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				logger2.LogError(val2);
			}
		}

		private static void Point(SelectionArrow arrow, MyButton target)
		{
			if (!((Object)(object)arrow == (Object)null) && !((Object)(object)target == (Object)null) && (!((Object)(object)arrow.selectedRect != (Object)null) || !(((Il2CppObjectBase)arrow.selectedRect).Pointer == ((Il2CppObjectBase)((Component)target).transform).Pointer)))
			{
				arrow.OnButtonHover(target);
			}
		}
	}
}