Decompiled source of ArcadeMode v1.0.1

ArcadeMode.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using PluginConfig.API;
using PluginConfig.API.Fields;
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: AssemblyTitle("ArcadeMode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ArcadeMode")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("690a5e05-30cc-49aa-a464-9bb590bbfb91")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ArcadeMode;

[BepInPlugin("thebluenebula.ArcadeMode", "ArcadeMode", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private enum DifficultyEnum
	{
		Harmless,
		Lenient,
		Standard,
		Violent,
		Brutal
	}

	private PluginConfigurator config;

	private AssetBundle arcade;

	private GameObject arcadeGUI;

	private IntField lifeInt;

	private EnumField<DifficultyEnum> difficultyField;

	private StatsManager StatsManagerObj;

	private TextMeshProUGUI GUIStyleText;

	private TextMeshProUGUI GUIKillsText;

	private TextMeshProUGUI GUILifesText;

	private const string modGUID = "thebluenebula.ArcadeMode";

	private const string modName = "ArcadeMode";

	private const string modVersion = "1.0.0";

	public static bool CurrentlyInArcadeMode = false;

	public int lifeCount = 5;

	public bool DeadLastTick = false;

	public int CurrentStyle = 0;

	public int SavedStyle = 0;

	public int FinalStyle = 0;

	public int CurrentKills = 0;

	public int SavedKills = 0;

	public int FinalKills = 0;

	private static readonly Harmony Harmony = new Harmony("thebluenebula.ArcadeMode");

	public static GameObject FindObjectEvenIfDisabled(string rootName, string objPath = null, int childNum = 0, bool useChildNum = false)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = null;
		Scene activeScene = SceneManager.GetActiveScene();
		GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
		bool flag = false;
		GameObject[] array = rootGameObjects;
		foreach (GameObject val2 in array)
		{
			if (((Object)val2).name == rootName)
			{
				val = val2;
				flag = true;
			}
		}
		if (flag)
		{
			GameObject val3 = val;
			if (objPath != null)
			{
				val3 = ((Component)val.transform.Find(objPath)).gameObject;
				if (!useChildNum)
				{
					val = val3;
				}
			}
			if (useChildNum)
			{
				GameObject gameObject = ((Component)val3.transform.GetChild(childNum)).gameObject;
				val = gameObject;
			}
		}
		return val;
	}

	private void Awake()
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		config = PluginConfigurator.Create("Arcade Mode", "thebluenebula.ArcadeMode");
		config.SetIconWithURL("https://gcdn.thunderstore.io/live/repository/icons/thebluenebula-ArcadeMode-1.0.0.png.128x128_q95.jpg");
		lifeInt = new IntField(config.rootPanel, "Lifes", "lifes", 5);
		difficultyField = new EnumField<DifficultyEnum>(config.rootPanel, "Difficulty", "field_guid", DifficultyEnum.Brutal);
		Debug.Log((object)"Mod ArcadeMode version 1.0.0 is loading...");
		Harmony.PatchAll();
		Debug.Log((object)"Mod ArcadeMode version 1.0.0 is loaded!");
		SceneManager.sceneLoaded += OnSceneLoaded;
		difficultyField.onValueChange += SetArcadeButtonDifficulty;
		arcade = Loader.LoadTerminal();
	}

	private void SetArcadeButtonDifficulty(EnumValueChangeEvent<DifficultyEnum> data)
	{
		GameObject val = FindObjectEvenIfDisabled("Canvas", "Difficulty Select (1)/V1 Must Die");
		if (Object.op_Implicit((Object)(object)val))
		{
			if (difficultyField.value == DifficultyEnum.Harmless)
			{
				val.GetComponent<DifficultySelectButton>().difficulty = 1;
			}
			if (difficultyField.value == DifficultyEnum.Lenient)
			{
				val.GetComponent<DifficultySelectButton>().difficulty = 2;
			}
			if (difficultyField.value == DifficultyEnum.Standard)
			{
				val.GetComponent<DifficultySelectButton>().difficulty = 3;
			}
			if (difficultyField.value == DifficultyEnum.Violent)
			{
				val.GetComponent<DifficultySelectButton>().difficulty = 4;
			}
			if (difficultyField.value == DifficultyEnum.Brutal)
			{
				val.GetComponent<DifficultySelectButton>().difficulty = 5;
			}
		}
		if (data != null)
		{
			SceneHelper.LoadScene("Main Menu", false);
		}
	}

	private void EnterArcadeMode()
	{
		CurrentlyInArcadeMode = true;
		lifeCount = lifeInt.value;
		SavedStyle = 0;
		CurrentStyle = 0;
		FinalStyle = 0;
		SavedKills = 0;
		CurrentKills = 0;
		FinalKills = 0;
		SceneHelper.LoadScene("Level 0-1", false);
		FindObjectEvenIfDisabled("Canvas", "Chapter Select").SetActive(false);
	}

	private void SetupArcadeModeButton()
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		Debug.Log((object)"Test");
		FindObjectEvenIfDisabled("Canvas", "Difficulty Select (1)/Under Construction").SetActive(false);
		((TMP_Text)FindObjectEvenIfDisabled("Canvas", "Difficulty Select (1)/V1 Must Die/Name").GetComponent<TextMeshProUGUI>()).text = "ARCADE MODE";
		((Graphic)FindObjectEvenIfDisabled("Canvas", "Difficulty Select (1)/V1 Must Die/Name").GetComponent<TextMeshProUGUI>()).color = Color.white;
		FindObjectEvenIfDisabled("Canvas", "Difficulty Select (1)/V1 Must Die/Progress").SetActive(false);
		FindObjectEvenIfDisabled("Canvas", "Difficulty Select (1)/V1 Must Die/RankPanel").SetActive(false);
		((Selectable)FindObjectEvenIfDisabled("Canvas", "Difficulty Select (1)/V1 Must Die").GetComponent<Button>()).interactable = true;
		SetArcadeButtonDifficulty(null);
		((UnityEvent)FindObjectEvenIfDisabled("Canvas", "Difficulty Select (1)/V1 Must Die").GetComponent<Button>().onClick).AddListener(new UnityAction(EnterArcadeMode));
	}

	private void IntermissionContinueFromAct()
	{
		if (SceneHelper.CurrentScene.EndsWith("1"))
		{
			SceneHelper.LoadScene("Level 4-1", false);
		}
		if (SceneHelper.CurrentScene.EndsWith("2"))
		{
			SceneHelper.LoadScene("Level 7-1", false);
		}
	}

	private void IntermissionConfirmationShow()
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Expected O, but got Unknown
		((Component)((Component)arcadeGUI.transform.GetChild(2)).transform.GetChild(4)).gameObject.SetActive(true);
		((Component)((Component)arcadeGUI.transform.GetChild(2)).transform.GetChild(2)).gameObject.SetActive(false);
		((UnityEvent)((Component)((Component)((Component)arcadeGUI.transform.GetChild(2)).transform.GetChild(4)).transform.GetChild(0)).GetComponent<Button>().onClick).AddListener(new UnityAction(IntermissionConfirmationYes));
		((UnityEvent)((Component)((Component)((Component)arcadeGUI.transform.GetChild(2)).transform.GetChild(4)).transform.GetChild(1)).GetComponent<Button>().onClick).AddListener(new UnityAction(IntermissionConfirmationNo));
	}

	private void IntermissionConfirmationYes()
	{
		if (Object.op_Implicit((Object)(object)arcadeGUI))
		{
			((Component)arcadeGUI.transform.GetChild(1)).gameObject.SetActive(true);
		}
	}

	private void SetFinalResults(bool dead)
	{
		((TMP_Text)((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(3)).GetComponent<TextMeshProUGUI>()).text = "<b>STYLE:</b>" + (SavedStyle + CurrentStyle);
		((TMP_Text)((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(4)).GetComponent<TextMeshProUGUI>()).text = "<b>KILLS:</b>" + (SavedKills + CurrentKills);
		((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(1)).gameObject.SetActive(false);
		((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(5)).gameObject.SetActive(false);
		if (dead)
		{
			((Component)arcadeGUI.transform.GetChild(1)).GetComponent<AudioSource>().playOnAwake = false;
			((TMP_Text)((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(6)).GetComponent<TextMeshProUGUI>()).text = "Press [<color=orange>R</color>] to try again";
			if (lifeCount < 1)
			{
				GameProgressSaver.AddMoney(SavedStyle + CurrentStyle);
			}
		}
		else
		{
			GameProgressSaver.AddMoney(SavedStyle + CurrentStyle);
			((TMP_Text)((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(6)).GetComponent<TextMeshProUGUI>()).text = "Press [<color=orange>ESC</color>] to continue";
		}
		((TMP_Text)((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(7)).GetComponent<TextMeshProUGUI>()).text = "<b>PROFIT:</b> " + (SavedStyle + CurrentStyle) + "<color=orange>P";
	}

	private void IntermissionConfirmationNo()
	{
		((Component)((Component)arcadeGUI.transform.GetChild(2)).transform.GetChild(4)).gameObject.SetActive(false);
		((Component)arcadeGUI.transform.GetChild(2)).gameObject.SetActive(true);
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Expected O, but got Unknown
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Expected O, but got Unknown
		bool flag = SceneHelper.CurrentScene == "Bootstrap" || SceneHelper.CurrentScene == "Intro";
		if (SceneHelper.CurrentScene == "Main Menu" || SceneHelper.CurrentScene == "Endless" || SceneHelper.CurrentScene == "Sandbox")
		{
			CurrentlyInArcadeMode = false;
			if (SceneHelper.CurrentScene == "Main Menu")
			{
				SetupArcadeModeButton();
			}
		}
		else if (!flag && CurrentlyInArcadeMode)
		{
			SavedStyle = FinalStyle;
			SavedKills = FinalKills;
			CurrentStyle = 0;
			GameObject val = arcade.LoadAsset<GameObject>("ArcadeGUI.prefab");
			arcadeGUI = Object.Instantiate<GameObject>(val);
			arcadeGUI.GetComponent<CanvasScaler>().scaleFactor = 2f;
			((Component)arcadeGUI.transform.GetChild(0)).gameObject.SetActive(true);
			((Selectable)FindObjectEvenIfDisabled("Canvas", "PauseMenu/Restart Checkpoint").GetComponent<Button>()).interactable = false;
			((Selectable)FindObjectEvenIfDisabled("Canvas", "PauseMenu/Restart Mission").GetComponent<Button>()).interactable = false;
		}
		if (SceneHelper.CurrentScene.StartsWith("Intermission") && CurrentlyInArcadeMode)
		{
			FindObjectEvenIfDisabled("Canvas", "PowerUpVignette/Panel").SetActive(false);
			((Component)arcadeGUI.transform.GetChild(2)).gameObject.SetActive(true);
			((UnityEvent)((Component)((Component)arcadeGUI.transform.GetChild(2)).transform.GetChild(1)).GetComponent<Button>().onClick).AddListener(new UnityAction(IntermissionContinueFromAct));
			((UnityEvent)((Component)((Component)arcadeGUI.transform.GetChild(2)).transform.GetChild(2)).GetComponent<Button>().onClick).AddListener(new UnityAction(IntermissionConfirmationShow));
		}
		if (SceneHelper.CurrentScene == "EarlyAccessEnd" && CurrentlyInArcadeMode)
		{
			FindObjectEvenIfDisabled("Canvas", "UnderwaterOverlay/Panel").SetActive(false);
			((TMP_Text)((Component)((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(0)).transform.GetChild(1)).GetComponent<TextMeshProUGUI>()).text = "-- COMPLETED RUN --";
			SetFinalResults(dead: false);
			((Component)arcadeGUI.transform.GetChild(0)).gameObject.SetActive(false);
			((Component)arcadeGUI.transform.GetChild(1)).gameObject.SetActive(true);
		}
	}

	private void Update()
	{
		//IL_046c: Unknown result type (might be due to invalid IL or missing references)
		config.interactable = !CurrentlyInArcadeMode;
		bool flag = SceneHelper.CurrentScene == "Bootstrap" || SceneHelper.CurrentScene == "Intro";
		GameObject val = null;
		GameObject val2 = null;
		if ((!Object.op_Implicit((Object)(object)StatsManagerObj) && !flag) & (SceneHelper.CurrentScene != "Main Menu"))
		{
			StatsManagerObj = Object.FindObjectOfType<StatsManager>();
		}
		if (Input.GetKeyDown((KeyCode)27) & (SceneHelper.CurrentScene == "EarlyAccessEnd"))
		{
			SceneHelper.LoadScene("Main Menu", false);
			FindObjectEvenIfDisabled("Canvas", "PauseMenu").SetActive(false);
		}
		if (!flag && SceneHelper.CurrentScene != "Main Menu")
		{
			CurrentStyle = StatsManagerObj.stylePoints;
			CurrentKills = StatsManagerObj.kills;
		}
		if ((Object)(object)arcadeGUI != (Object)null)
		{
			if (!Object.op_Implicit((Object)(object)GUIStyleText))
			{
				GUIStyleText = ((Component)((Component)arcadeGUI.transform.GetChild(0)).gameObject.transform.GetChild(1)).GetComponent<TextMeshProUGUI>();
			}
			if (!Object.op_Implicit((Object)(object)GUIKillsText))
			{
				GUIKillsText = ((Component)((Component)arcadeGUI.transform.GetChild(0)).gameObject.transform.GetChild(3)).GetComponent<TextMeshProUGUI>();
			}
			if (!Object.op_Implicit((Object)(object)GUILifesText))
			{
				GUILifesText = ((Component)((Component)arcadeGUI.transform.GetChild(0)).gameObject.transform.GetChild(2)).GetComponent<TextMeshProUGUI>();
			}
			((TMP_Text)GUILifesText).text = lifeCount + "/" + lifeInt.value;
			((TMP_Text)GUIStyleText).text = "<color=#999999>STYLE:</color> " + (SavedStyle + CurrentStyle);
			((TMP_Text)GUIKillsText).text = "<color=#999999>KILLS:</color> " + (SavedKills + CurrentKills);
			((Component)((Component)arcadeGUI.transform.GetChild(0)).gameObject.transform.GetChild(4)).gameObject.SetActive(false);
		}
		FinalStyle = SavedStyle + CurrentStyle;
		FinalKills = SavedKills + CurrentKills;
		if (flag)
		{
			return;
		}
		if (SceneHelper.CurrentScene != "Main Menu")
		{
			val = FindObjectEvenIfDisabled("Player", "Main Camera/HUD Camera/HUD/FinishCanvas/Panel/Title/Text (1)");
			val2 = FindObjectEvenIfDisabled("Canvas", "BlackScreen/YouDiedText");
		}
		if ((CurrentlyInArcadeMode & (SceneHelper.CurrentScene != "Main Menu")) && ((TMP_Text)val.GetComponent<TextMeshProUGUI>()).text != "-- ARCADE MODE --")
		{
			((TMP_Text)val.GetComponent<TextMeshProUGUI>()).text = "-- ARCADE MODE --";
		}
		if (!((Object)(object)MonoSingleton<NewMovement>.Instance != (Object)null))
		{
			return;
		}
		if (MonoSingleton<NewMovement>.Instance.dead)
		{
			if (!DeadLastTick)
			{
				DeadLastTick = true;
				lifeCount--;
				Debug.Log((object)("ARCADE MODE LIFES: " + lifeCount));
				if (SceneHelper.CurrentScene.StartsWith("Level P"))
				{
					((TMP_Text)((Component)((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(0)).transform.GetChild(1)).GetComponent<TextMeshProUGUI>()).text = "-- FAILED PRIME SANCTUM --";
				}
				else
				{
					((TMP_Text)((Component)((Component)((Component)arcadeGUI.transform.GetChild(1)).transform.GetChild(0)).transform.GetChild(1)).GetComponent<TextMeshProUGUI>()).text = "-- FAILED LEVEL --";
				}
				SetFinalResults(dead: true);
				((Transform)FindObjectEvenIfDisabled("Canvas", "BlackScreen").GetComponent<RectTransform>()).localScale = new Vector3(0f, 0f, 0f);
				((Component)arcadeGUI.transform.GetChild(1)).gameObject.SetActive(true);
			}
		}
		else if (DeadLastTick & CurrentlyInArcadeMode)
		{
			if (lifeCount > 0)
			{
				SceneHelper.LoadScene(SceneHelper.CurrentScene, false);
			}
			else
			{
				SceneHelper.LoadScene("Main Menu", false);
			}
			DeadLastTick = false;
		}
	}
}
public static class Scenes
{
	public static string MainMenu = "b3e7f2f8052488a45b35549efb98d902";

	public static string ZeroDashOne = "eb57c9574cb2e624799753de0f8ffcad";
}
public static class Loader
{
	public static AssetBundle LoadTerminal()
	{
		try
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string name = "ArcadeMode.Bundles.arcade.bundle";
			using Stream stream = executingAssembly.GetManifestResourceStream(name);
			if (stream == null)
			{
				Debug.LogError((object)"Resource 'arcade.bundle' not found in embedded resources.");
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return AssetBundle.LoadFromMemory(array);
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Error loading arcade: " + ex.Message));
			return null;
		}
	}
}