Decompiled source of CGRetry v1.0.1

CGRetry.dll

Decompiled 4 months ago
using System;
using System.Collections;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("CGRetry")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+be27bc9df1cf25fb67601fa30b662497fc307cf3")]
[assembly: AssemblyProduct("CGRetry")]
[assembly: AssemblyTitle("CGRetry")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CGR
{
	[BepInPlugin("51.CGRetry", "CGRetry", "1.0.0")]
	internal class Plugin : BaseUnityPlugin
	{
		private class ConfigManager
		{
			public static ConfigEntry<int> retryStartRank;

			public static ConfigEntry<float> retryStartupTime;

			public static void Initialize(ConfigFile file)
			{
				retryStartRank = file.Bind<int>("Options", "Retry Start Rank", 6, "The rank you get at the start of a retried wave\n0: Destructive\n1: Chaotic\n2: Brutal\n3: Anarchic\n4: Supreme\n5: SSadistic\n6: SSShitstorm\n7: ULTRAKILL");
				retryStartupTime = file.Bind<float>("Options", "Retry Startup Time", 1f, "How long you wait before the retried wave reloads");
			}
		}

		private class RNG
		{
			private static Random rng = new Random();

			public static void SetSeed(int seed)
			{
				rng = new Random(seed);
			}

			public static int RangeInt(int min, int max)
			{
				return rng.Next(min, max);
			}

			public static float RangeFloat(float min, float max)
			{
				return (float)(rng.NextDouble() * (double)(max - min) + (double)min);
			}
		}

		private class DialogManager
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static UnityAction <>9__4_0;

				public static UnityAction <>9__4_1;

				public static UnityAction <>9__4_2;

				internal void <Initialize>b__4_0()
				{
				}

				internal void <Initialize>b__4_1()
				{
					RetryWave();
					SetMouseVisibility(show: false);
				}

				internal void <Initialize>b__4_2()
				{
					hasRefusedRetryOnDeath = true;
					FinalCyberRank val = Object.FindObjectOfType<FinalCyberRank>();
					((MonoBehaviour)val).StopAllCoroutines();
					val.Appear();
				}
			}

			public static GameObject pauseMenu;

			private static GameObject quitDialog;

			public static GameObject gameOverDialog;

			public static GameObject retryDialog;

			public static void Initialize()
			{
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Expected O, but got Unknown
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: Expected O, but got Unknown
				//IL_0132: 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_013d: Expected O, but got Unknown
				//IL_0151: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_015c: Expected O, but got Unknown
				if ((Object)(object)MonoSingleton<EndlessGrid>.Instance == (Object)null)
				{
					return;
				}
				pauseMenu = MonoSingleton<OptionsManager>.Instance.pauseMenu;
				if ((Object)(object)MonoSingleton<OptionsManager>.Instance.pauseMenu == (Object)null)
				{
					return;
				}
				Transform parent = pauseMenu.transform.parent;
				GameObject val = null;
				for (int i = 0; i < parent.childCount; i++)
				{
					GameObject gameObject = ((Component)parent.GetChild(i)).gameObject;
					if (((Object)gameObject).name == "PauseMenuDialogs")
					{
						val = gameObject;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				quitDialog = ((Component)val.transform.Find("Quit Confirm")).gameObject;
				UnityAction val2 = RetryWave;
				object obj = <>c.<>9__4_0;
				if (obj == null)
				{
					UnityAction val3 = delegate
					{
					};
					<>c.<>9__4_0 = val3;
					obj = (object)val3;
				}
				retryDialog = CloneDialog("Retry Confirm", "<color=green>RETRY</color>", "CANCEL", "Are you sure you want to\n<color=green>RETRY</color> this wave?", val2, (UnityAction)obj);
				object obj2 = <>c.<>9__4_1;
				if (obj2 == null)
				{
					UnityAction val4 = delegate
					{
						RetryWave();
						SetMouseVisibility(show: false);
					};
					<>c.<>9__4_1 = val4;
					obj2 = (object)val4;
				}
				object obj3 = <>c.<>9__4_2;
				if (obj3 == null)
				{
					UnityAction val5 = delegate
					{
						hasRefusedRetryOnDeath = true;
						FinalCyberRank val6 = Object.FindObjectOfType<FinalCyberRank>();
						((MonoBehaviour)val6).StopAllCoroutines();
						val6.Appear();
					};
					<>c.<>9__4_2 = val5;
					obj3 = (object)val5;
				}
				gameOverDialog = CloneDialog("Game Over Confirm", "<color=green>RETRY</color>", "NO", "Do you want to\n<color=green>RETRY</color> this wave?", (UnityAction)obj2, (UnityAction)obj3);
			}

			public static void ShowDialog(GameObject dialog)
			{
				SetMouseVisibility(show: true);
				dialog.GetComponent<BasicConfirmationDialog>().ShowDialog();
			}

			private static void SetMouseVisibility(bool show)
			{
				Cursor.visible = show;
				Cursor.lockState = (CursorLockMode)((!show) ? 1 : 0);
			}

			public static GameObject CloneDialog(string name, string confirmText, string cancelText, string text, UnityAction confirmEvent, UnityAction cancelEvent)
			{
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Expected O, but got Unknown
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Expected O, but got Unknown
				GameObject dialog = Object.Instantiate<GameObject>(quitDialog, quitDialog.transform.parent);
				((Object)dialog).name = name;
				Transform val = dialog.transform.Find("Panel");
				GameObject gameObject = ((Component)val.Find("Cancel")).gameObject;
				Button component = gameObject.GetComponent<Button>();
				((UnityEvent)component.onClick).AddListener(cancelEvent);
				TextMeshProUGUI component2 = ((Component)((Component)component).transform.Find("Text")).GetComponent<TextMeshProUGUI>();
				((TMP_Text)component2).text = cancelText;
				GameObject gameObject2 = ((Component)val.Find("Confirm")).gameObject;
				Button component3 = gameObject2.GetComponent<Button>();
				component3.onClick = new ButtonClickedEvent();
				((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
				{
					((Component)dialog.transform.parent.Find("Blocker")).gameObject.SetActive(false);
					MonoSingleton<OptionsManager>.Instance.UnPause();
					dialog.SetActive(false);
					SetMouseVisibility(show: false);
				});
				((UnityEvent)component3.onClick).AddListener(confirmEvent);
				TextMeshProUGUI component4 = ((Component)((Component)component3).transform.Find("Text")).GetComponent<TextMeshProUGUI>();
				((TMP_Text)component4).text = confirmText;
				TextMeshProUGUI component5 = ((Component)val.Find("Text (2)")).gameObject.GetComponent<TextMeshProUGUI>();
				((TMP_Text)component5).text = text;
				((Component)((Component)val.Find("Text (1)")).gameObject.GetComponent<TextMeshProUGUI>()).gameObject.SetActive(false);
				return dialog;
			}
		}

		private class EndlessGridState
		{
			private int seed;

			private int points;

			private int maxPoints;

			private int specialAntiBuffer;

			private int massAntiBuffer;

			private float uncommonAntiBuffer;

			private int currentWave;

			private int currentPatternNum;

			private ArenaPattern[] patterns;

			private ArenaPattern[] customPatterns;

			private int incompleteBlocks;

			private int incompletePrefabs;

			private List<Vector2> meleePositions;

			private int usedMeleePositions;

			private List<Vector2> projectilePositions;

			private int usedProjectilePositions;

			private int hideousMasses;

			public void Save(EndlessGrid grid)
			{
				Logger.LogInfo((object)"Saved EndlessGrid state");
				seed = Random.Range(0, int.MaxValue);
				RNG.SetSeed(seed);
				currentWave = grid.currentWave;
				points = MonoSingleton<EndlessGrid>.Instance.points;
				maxPoints = MonoSingleton<EndlessGrid>.Instance.maxPoints;
				specialAntiBuffer = MonoSingleton<EndlessGrid>.Instance.specialAntiBuffer;
				massAntiBuffer = MonoSingleton<EndlessGrid>.Instance.massAntiBuffer;
				uncommonAntiBuffer = MonoSingleton<EndlessGrid>.Instance.uncommonAntiBuffer;
				currentPatternNum = MonoSingleton<EndlessGrid>.Instance.currentPatternNum;
				patterns = (ArenaPattern[])MonoSingleton<EndlessGrid>.Instance.patterns.Clone();
				customPatterns = (ArenaPattern[])MonoSingleton<EndlessGrid>.Instance.customPatterns.Clone();
				incompleteBlocks = MonoSingleton<EndlessGrid>.Instance.incompleteBlocks;
				usedMeleePositions = MonoSingleton<EndlessGrid>.Instance.usedMeleePositions;
				usedProjectilePositions = MonoSingleton<EndlessGrid>.Instance.usedProjectilePositions;
				incompletePrefabs = MonoSingleton<EndlessGrid>.Instance.incompletePrefabs;
				hideousMasses = MonoSingleton<EndlessGrid>.Instance.hideousMasses;
				meleePositions = new List<Vector2>(MonoSingleton<EndlessGrid>.Instance.meleePositions);
				projectilePositions = new List<Vector2>(MonoSingleton<EndlessGrid>.Instance.projectilePositions);
			}

			public void Load(EndlessGrid grid)
			{
				Logger.LogInfo((object)"Loaded EndlessGrid state");
				RNG.SetSeed(seed);
				grid.currentWave = currentWave;
				MonoSingleton<EndlessGrid>.Instance.points = points;
				MonoSingleton<EndlessGrid>.Instance.maxPoints = maxPoints;
				MonoSingleton<EndlessGrid>.Instance.specialAntiBuffer = specialAntiBuffer;
				MonoSingleton<EndlessGrid>.Instance.massAntiBuffer = massAntiBuffer;
				MonoSingleton<EndlessGrid>.Instance.uncommonAntiBuffer = uncommonAntiBuffer;
				MonoSingleton<EndlessGrid>.Instance.currentPatternNum = currentPatternNum;
				MonoSingleton<EndlessGrid>.Instance.patterns = (ArenaPattern[])patterns.Clone();
				MonoSingleton<EndlessGrid>.Instance.customPatterns = (ArenaPattern[])customPatterns.Clone();
				MonoSingleton<EndlessGrid>.Instance.incompleteBlocks = incompleteBlocks;
				MonoSingleton<EndlessGrid>.Instance.usedMeleePositions = usedMeleePositions;
				MonoSingleton<EndlessGrid>.Instance.usedProjectilePositions = usedProjectilePositions;
				MonoSingleton<EndlessGrid>.Instance.incompletePrefabs = incompletePrefabs;
				MonoSingleton<EndlessGrid>.Instance.hideousMasses = hideousMasses;
				MonoSingleton<EndlessGrid>.Instance.meleePositions = new List<Vector2>(meleePositions);
				MonoSingleton<EndlessGrid>.Instance.projectilePositions = new List<Vector2>(projectilePositions);
			}
		}

		[HarmonyPatch(typeof(EndlessGrid))]
		private class EndlessGridPatch
		{
			[HarmonyPrefix]
			[HarmonyPatch("NextWave")]
			private static bool NextWavePrefix()
			{
				if (!hasCbStarted)
				{
					Logger.LogInfo((object)"Cybergrind started");
					hasCbStarted = true;
				}
				if (!isRetrying)
				{
					endlessGridState.Save(MonoSingleton<EndlessGrid>.Instance);
					return true;
				}
				if (isStartup)
				{
					isStartup = false;
					isRetrying = false;
					return true;
				}
				((MonoBehaviour)MonoSingleton<EndlessGrid>.Instance).StopAllCoroutines();
				((MonoBehaviour)MonoSingleton<EndlessGrid>.Instance).StartCoroutine(WaitAndCall(ConfigManager.retryStartupTime.Value, delegate
				{
					endlessGridState.Load(MonoSingleton<EndlessGrid>.Instance);
					isStartup = true;
					MonoSingleton<EndlessGrid>.Instance.NextWave();
				}));
				return false;
			}

			[HarmonyTranspiler]
			[HarmonyPatch("GetEnemies")]
			private static IEnumerable<CodeInstruction> GetEnemiesTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				TranspileRandom(instructions);
				return instructions;
			}

			[HarmonyTranspiler]
			[HarmonyPatch("GetNextEnemy")]
			private static IEnumerable<CodeInstruction> GetNextEnemyTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				TranspileRandom(instructions);
				return instructions;
			}

			[HarmonyTranspiler]
			[HarmonyPatch("ShuffleDecks")]
			private static IEnumerable<CodeInstruction> ShuffleDecksTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				TranspileRandom(instructions);
				return instructions;
			}

			[HarmonyTranspiler]
			[HarmonyPatch("SpawnUncommons")]
			private static IEnumerable<CodeInstruction> SpawnUncommonsTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				TranspileRandom(instructions);
				return instructions;
			}
		}

		[HarmonyPatch(typeof(FinalCyberRank))]
		private class FinalCyberRankPatch
		{
			[HarmonyPrefix]
			[HarmonyPatch("GameOver")]
			private static bool GameOverPrefix(FinalCyberRank __instance)
			{
				if (!hasRefusedRetryOnDeath && hasCbStarted)
				{
					((MonoBehaviour)__instance).StopAllCoroutines();
					((MonoBehaviour)__instance).StartCoroutine(WaitAndCall(1f, delegate
					{
						DialogManager.ShowDialog(DialogManager.gameOverDialog);
					}));
				}
				return true;
			}

			[HarmonyPrefix]
			[HarmonyPatch("Appear")]
			private static bool AppearPrefix(FinalCyberRank __instance)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (hasRefusedRetryOnDeath || !hasCbStarted)
				{
					Scene activeScene = SceneManager.GetActiveScene();
					GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
					GameObject[] array = rootGameObjects;
					foreach (GameObject val in array)
					{
						if (((Object)val).name == "EndMusic")
						{
							val.SetActive(true);
						}
					}
					return true;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(OptionsManager))]
		private class OptionsManagerPatch
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static UnityAction <>9__1_0;

				internal void <StartPostfix>b__1_0()
				{
					FinalCyberRank val = Object.FindObjectOfType<FinalCyberRank>();
					if (MonoSingleton<CheatsController>.Instance.cheatsEnabled || val.gameOver)
					{
						MonoSingleton<OptionsManager>.Instance.UnPause();
						RetryWave();
					}
					else
					{
						DialogManager.ShowDialog(DialogManager.retryDialog);
					}
				}
			}

			private static GameObject buttonObject;

			[HarmonyPostfix]
			[HarmonyPatch("Start")]
			private static void StartPostfix()
			{
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Expected O, but got Unknown
				//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Expected O, but got Unknown
				DialogManager.Initialize();
				if ((Object)(object)DialogManager.pauseMenu == (Object)null)
				{
					return;
				}
				Button componentInChildren = DialogManager.pauseMenu.GetComponentInChildren<Button>(true);
				buttonObject = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject, ((Component)componentInChildren).transform.parent);
				((Object)buttonObject).name = "CGRetryWave Button";
				Button component = buttonObject.GetComponent<Button>();
				component.onClick = new ButtonClickedEvent();
				ButtonClickedEvent onClick = component.onClick;
				object obj = <>c.<>9__1_0;
				if (obj == null)
				{
					UnityAction val = delegate
					{
						FinalCyberRank val2 = Object.FindObjectOfType<FinalCyberRank>();
						if (MonoSingleton<CheatsController>.Instance.cheatsEnabled || val2.gameOver)
						{
							MonoSingleton<OptionsManager>.Instance.UnPause();
							RetryWave();
						}
						else
						{
							DialogManager.ShowDialog(DialogManager.retryDialog);
						}
					};
					<>c.<>9__1_0 = val;
					obj = (object)val;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj);
				RectTransform component2 = buttonObject.GetComponent<RectTransform>();
				component2.anchoredPosition += new Vector2(0f, -60f);
			}

			[HarmonyPostfix]
			[HarmonyPatch("Pause")]
			private static void PausePostfix()
			{
				if ((Object)(object)MonoSingleton<EndlessGrid>.Instance == (Object)null)
				{
					return;
				}
				if (Object.op_Implicit((Object)(object)buttonObject))
				{
					buttonObject.SetActive(hasCbStarted);
					TextMeshProUGUI componentInChildren = buttonObject.GetComponentInChildren<TextMeshProUGUI>(true);
					Button component = buttonObject.GetComponent<Button>();
					if (MonoSingleton<EndlessGrid>.Instance.incompleteBlocks == 0 && MonoSingleton<EndlessGrid>.Instance.incompletePrefabs == 0)
					{
						((TMP_Text)componentInChildren).text = "<color=green>RETRY WAVE</color>";
						((Behaviour)component).enabled = true;
					}
					else
					{
						((TMP_Text)componentInChildren).text = "<color=red>LOADING WAVE</color>";
						((Behaviour)component).enabled = false;
					}
				}
				if ((Object)(object)MonoSingleton<OptionsManager>.Instance.pauseMenu == (Object)null)
				{
					return;
				}
				Button[] componentsInChildren = MonoSingleton<OptionsManager>.Instance.pauseMenu.GetComponentsInChildren<Button>();
				Button[] array = componentsInChildren;
				foreach (Button val in array)
				{
					TextMeshProUGUI componentInChildren2 = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
					if ((Object)(object)componentInChildren2 != (Object)null && ((TMP_Text)componentInChildren2).text.ToUpper() == "CHECKPOINT")
					{
						((Component)val).gameObject.SetActive(!hasCbStarted);
					}
				}
			}
		}

		[HarmonyPatch(typeof(NewMovement))]
		private class NewMovementPatch
		{
			[HarmonyPrefix]
			[HarmonyPatch("Start")]
			private static void StartPrefix()
			{
				hasCbStarted = false;
				hasRefusedRetryOnDeath = false;
			}
		}

		[HarmonyPatch(typeof(BasicConfirmationDialog))]
		private class BasicConfirmationDialogPatch
		{
			[HarmonyPrefix]
			[HarmonyPatch("Update")]
			private static bool UpdatePrefix(BasicConfirmationDialog __instance)
			{
				if (((Object)((Component)__instance).gameObject).name == "Game Over Confirm")
				{
					return false;
				}
				return true;
			}
		}

		private const string ID = "51.CGRetry";

		private const string NAME = "CGRetry";

		private const string VERSION = "1.0.0";

		private static ManualLogSource Logger;

		private static EndlessGridState endlessGridState = new EndlessGridState();

		private static bool isRetrying = false;

		private static bool isStartup = false;

		private static bool hasCbStarted = false;

		private static bool hasRefusedRetryOnDeath = false;

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			Harmony val = new Harmony("CGRetry");
			val.PatchAll();
			Logger.LogInfo((object)"CGRetry loaded");
		}

		private static void TranspileRandom(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(Random), "Range", new Type[2]
			{
				typeof(int),
				typeof(int)
			}, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(Random), "Range", new Type[2]
			{
				typeof(float),
				typeof(float)
			}, (Type[])null);
			MethodInfo operand = AccessTools.Method(typeof(RNG), "RangeInt", new Type[2]
			{
				typeof(int),
				typeof(int)
			}, (Type[])null);
			MethodInfo operand2 = AccessTools.Method(typeof(RNG), "RangeFloat", new Type[2]
			{
				typeof(float),
				typeof(float)
			}, (Type[])null);
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, methodInfo))
				{
					instruction.operand = operand;
				}
				if (CodeInstructionExtensions.Calls(instruction, methodInfo2))
				{
					instruction.operand = operand2;
				}
			}
		}

		private static void RetryWave()
		{
			MonoSingleton<CheatsController>.Instance.ActivateCheats();
			ResetGame();
			isRetrying = true;
			MonoSingleton<EndlessGrid>.Instance.NextWave();
		}

		private static void ResetGame()
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			hasRefusedRetryOnDeath = false;
			GameObject currentWeapon = MonoSingleton<GunControl>.Instance.currentWeapon;
			if ((Object)(object)currentWeapon != (Object)null)
			{
				ShotgunHammer component = currentWeapon.GetComponent<ShotgunHammer>();
				if ((Object)(object)component != (Object)null)
				{
					component.launchPlayer = false;
				}
			}
			MonoSingleton<EndlessGrid>.Instance.incompleteBlocks = 999;
			MonoSingleton<EndlessGrid>.Instance.anw.deadEnemies = 0;
			((MonoBehaviour)MonoSingleton<EndlessGrid>.Instance).CancelInvoke();
			((Behaviour)MonoSingleton<NewMovement>.Instance).enabled = true;
			if ((Object)(object)MonoSingleton<NewMovement>.Instance.ridingRocket != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)MonoSingleton<NewMovement>.Instance.ridingRocket).gameObject);
				MonoSingleton<NewMovement>.Instance.ridingRocket = null;
			}
			MonoSingleton<NewMovement>.Instance.StopSlide();
			MonoSingleton<NewMovement>.Instance.Respawn();
			MonoSingleton<NewMovement>.Instance.rb.position = new Vector3(0.01f, 100f, 62.5f);
			MonoSingleton<NewMovement>.Instance.rb.velocity = Vector3.zero;
			MonoSingleton<StyleHUD>.Instance.ResetAllFreshness();
			MonoSingleton<StyleHUD>.Instance.rankIndex = ConfigManager.retryStartRank.Value;
			MonoSingleton<StyleHUD>.Instance.currentMeter = (float)MonoSingleton<StyleHUD>.Instance.currentRank.maxMeter - 0.01f;
			MonoSingleton<StyleHUD>.Instance.AscendRank();
			MonoSingleton<CameraController>.Instance.activated = true;
			MonoSingleton<CameraController>.Instance.StopShake();
			MonoSingleton<CameraController>.Instance.rotationX = 0f;
			MonoSingleton<CameraController>.Instance.rotationY = 0f;
			MonoSingleton<StatsManager>.Instance.StartTimer();
			MonoSingleton<StatsManager>.Instance.UnhideShit();
			FinalCyberRank val = Object.FindObjectOfType<FinalCyberRank>();
			val.gameOver = false;
			val.i = 0;
			((Component)((Component)((Component)val.friendContainer.transform.parent).gameObject.transform.parent).gameObject.transform.parent).gameObject.SetActive(false);
			((Component)val.globalContainer.transform.parent).gameObject.SetActive(false);
			GameObject[] toAppear = val.toAppear;
			foreach (GameObject val2 in toAppear)
			{
				val2.SetActive(false);
			}
			val.complete = false;
			val.countTime = false;
			val.countWaves = false;
			val.countKills = false;
			val.countStyle = false;
			((MonoBehaviour)val).StopAllCoroutines();
			MonoSingleton<TimeController>.Instance.controlTimeScale = true;
			DestroyAll<Projectile>();
			DestroyAll<ContinuousBeam>();
			DestroyAll<GroundWave>();
			DestroyAll<Magnet>();
			DestroyAll<VirtueInsignia>();
			DestroyAll<Pincer>();
			List<GameObject> spawnedEnemies = MonoSingleton<EndlessGrid>.Instance.spawnedEnemies;
			for (int num = spawnedEnemies.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)spawnedEnemies[num] != (Object)null)
				{
					Object.Destroy((Object)(object)spawnedEnemies[num]);
				}
			}
			spawnedEnemies.Clear();
			val.wasPaused = false;
			MonoSingleton<AudioMixerController>.Instance.allSound.SetFloat("allVolume", MonoSingleton<AudioMixerController>.Instance.CalculateVolume(MonoSingleton<AudioMixerController>.Instance.sfxVolume));
			MonoSingleton<AudioMixerController>.Instance.musicSound.SetFloat("allVolume", MonoSingleton<AudioMixerController>.Instance.CalculateVolume(MonoSingleton<AudioMixerController>.Instance.musicVolume));
			Scene activeScene = SceneManager.GetActiveScene();
			GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
			GameObject[] array = rootGameObjects;
			foreach (GameObject val3 in array)
			{
				if (((Object)val3).name == "EndMusic")
				{
					val3.SetActive(false);
				}
			}
		}

		private static void DestroyAll<T>() where T : Component
		{
			T[] array = Object.FindObjectsOfType<T>();
			if (array.Length == 0)
			{
				return;
			}
			T[] array2 = array;
			foreach (T val in array2)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}

		private static IEnumerator WaitAndCall(float time, Action work)
		{
			yield return (object)new WaitForSecondsRealtime(time);
			work();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}