Decompiled source of LoaderTrials v1.0.1

LoaderTrials.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HG;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.ConVar;
using RoR2.ExpansionManagement;
using RoR2.Navigation;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("LoaderTrials")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LoaderTrials")]
[assembly: AssemblyTitle("LoaderTrials")]
[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 LoaderTrials
{
	public class GameMode
	{
		public class LoaderRunButton : MonoBehaviour
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static UnityAction <>9__1_0;

				internal void <Start>b__1_0()
				{
					Util.PlaySound("Play_UI_menuClick", ((Component)RoR2Application.instance).gameObject);
					Console.instance.SubmitCmd((NetworkUser)null, "transition_command \"gamemode xLoaderRun; host 0; \"", false);
				}
			}

			public HGButton hgButton;

			public void Start()
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Expected O, but got Unknown
				hgButton = ((Component)this).GetComponent<HGButton>();
				((Button)hgButton).onClick = new ButtonClickedEvent();
				ButtonClickedEvent onClick = ((Button)hgButton).onClick;
				object obj = <>c.<>9__1_0;
				if (obj == null)
				{
					UnityAction val = delegate
					{
						Util.PlaySound("Play_UI_menuClick", ((Component)RoR2Application.instance).gameObject);
						Console.instance.SubmitCmd((NetworkUser)null, "transition_command \"gamemode xLoaderRun; host 0; \"", false);
					};
					<>c.<>9__1_0 = val;
					obj = (object)val;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj);
			}
		}

		public class LoaderRunButtonAdder : MonoBehaviour
		{
			public void Start()
			{
				GameObject obj = Object.Instantiate<GameObject>(((Component)((Component)this).transform.Find("GenericMenuButton (Eclipse)")).gameObject, ((Component)this).transform);
				obj.AddComponent<LoaderRunButton>();
				obj.GetComponent<LanguageTextMeshController>().token = "Loader Trials";
				obj.GetComponent<HGButton>().hoverToken = "Play a gamemode that tests your abilities as The Loader.";
			}
		}

		public class LavaController : MonoBehaviour
		{
			private CharacterBody body;

			private float delay = 5f;

			private float stopwatch;

			private void Start()
			{
				body = ((Component)this).gameObject.GetComponent<CharacterBody>();
			}

			private void FixedUpdate()
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Expected O, but got Unknown
				stopwatch += Time.deltaTime;
				if (!((double)stopwatch < (double)delay) && body.characterMotor.isGrounded)
				{
					body.healthComponent.TakeDamage(new DamageInfo
					{
						damage = 5f,
						rejected = false
					});
				}
			}
		}

		public class PortalCollision : MonoBehaviour
		{
			public GameObject effectPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/moon/MoonExitArenaOrbEffect.prefab").WaitForCompletion();

			private void OnTriggerEnter(Collider other)
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Expected O, but got Unknown
				CharacterBody component = ((Component)other).GetComponent<CharacterBody>();
				if (!Object.op_Implicit((Object)(object)component) && ((Object)component).name != "LoaderBody(Clone)")
				{
					return;
				}
				EffectManager.SpawnEffect(effectPrefab, new EffectData
				{
					origin = ((Component)this).transform.position
				}, false);
				Object.Destroy((Object)(object)((Component)this).gameObject);
				LoaderRun component2 = ((Component)Run.instance).gameObject.GetComponent<LoaderRun>();
				if (component2.portalsPassed == component2.portalsRequiredToPass - 1)
				{
					if (Run.instance.stageClearCount == 2)
					{
						Run.instance.BeginGameOver(loaderRunEnding);
						return;
					}
					Run.instance.PickNextStageSceneFromCurrentSceneDestinations();
					Run.instance.AdvanceStage(Run.instance.nextStageScene);
				}
			}
		}

		public class LoaderRun : Run
		{
			public SpawnCard portalSpawnCard = ScriptableObject.CreateInstance<SpawnCard>();

			public GameObject portalPrefab = loaderRunPortal;

			public string trial;

			private List<string> trialList = new List<string> { "portal", "punch", "lava" };

			private bool activatedIndicators;

			public uint portalCount = 6u;

			public uint portalsRequiredToPass = 6u;

			private List<OnDestroyCallback> portalActiveList = new List<OnDestroyCallback>();

			public int enemyCount;

			public uint portalsPassed => (uint)(portalCount - portalActiveList.Count);

			public override void Start()
			{
				SceneDirector.onPrePopulateSceneServer += onPrePopulateSceneServer;
				SceneDirector.onPostPopulateSceneServer += onPostPopulateSceneServer;
				Reflection.GetFieldValue<BoolConVar>(typeof(CombatDirector), "cvDirectorCombatDisable").SetBool(true);
				((Run)this).Start();
				CreateSpawnCard();
				ObjectivePanelController.collectObjectiveSources += ReportObjective;
			}

			public override void FixedUpdate()
			{
				((Run)this).FixedUpdate();
				if (!activatedIndicators)
				{
					activatedIndicators = true;
					AddIndicators();
					if (trial == "portal" || trial == "lava")
					{
						AddPortalIndicators();
					}
				}
			}

			public override void OnDestroy()
			{
				((Run)this).OnDestroy();
				SceneDirector.onPrePopulateSceneServer -= onPrePopulateSceneServer;
				SceneDirector.onPostPopulateSceneServer -= onPostPopulateSceneServer;
				ObjectivePanelController.collectObjectiveSources -= ReportObjective;
				Reflection.GetFieldValue<BoolConVar>(typeof(CombatDirector), "cvDirectorCombatDisable").SetBool(false);
			}

			private void CreateSpawnCard()
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				portalSpawnCard.prefab = portalPrefab;
				portalSpawnCard.hullSize = (HullClassification)0;
				portalSpawnCard.nodeGraphType = (GraphType)1;
				portalSpawnCard.requiredFlags = (NodeFlags)0;
				portalSpawnCard.forbiddenFlags = (NodeFlags)4;
			}

			private void AddPortalIndicators()
			{
				List<GameObject> list = new List<GameObject>();
				GameObject[] array = Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[];
				foreach (GameObject val in array)
				{
					if (((Object)val).name == "LoaderRunPortal(Clone)")
					{
						list.Add(val);
					}
				}
				foreach (GameObject item in list)
				{
					Object.Instantiate<GameObject>(positionIndicator, item.transform).GetComponent<PositionIndicator>().targetTransform = item.transform;
				}
			}

			private void AddIndicators()
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				TeamIndex val = (TeamIndex)2;
				TeamComponent[] array = Object.FindObjectsOfType<TeamComponent>();
				foreach (TeamComponent val2 in array)
				{
					if (val2.teamIndex == val)
					{
						val2.RequestDefaultIndicator(positionIndicator);
					}
				}
			}

			public void onPrePopulateSceneServer(SceneDirector director)
			{
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Expected O, but got Unknown
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Expected O, but got Unknown
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Expected O, but got Unknown
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Expected O, but got Unknown
				activatedIndicators = false;
				director.teleporterSpawnCard = null;
				director.interactableCredit = 0;
				trial = trialList.ElementAt(Run.instance.stageClearCount);
				switch (trial)
				{
				case "lava":
				{
					director.monsterCredit = 0;
					DirectorPlacementRule val2 = new DirectorPlacementRule();
					val2.placementMode = (PlacementMode)4;
					for (int j = 0; j < portalCount; j++)
					{
						portalActiveList.Add(OnDestroyCallback.AddCallback(DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(portalSpawnCard, val2, base.stageRng)), (Action<OnDestroyCallback>)delegate(OnDestroyCallback component)
						{
							portalActiveList.Remove(component);
						}));
					}
					break;
				}
				case "punch":
					Reflection.GetFieldValue<BoolConVar>(typeof(CombatDirector), "cvDirectorCombatDisable").SetBool(false);
					director.monsterCredit = 100;
					break;
				case "portal":
				{
					director.monsterCredit = 0;
					DirectorPlacementRule val = new DirectorPlacementRule();
					val.placementMode = (PlacementMode)4;
					for (int i = 0; i < portalCount; i++)
					{
						portalActiveList.Add(OnDestroyCallback.AddCallback(DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(portalSpawnCard, val, base.stageRng)), (Action<OnDestroyCallback>)delegate(OnDestroyCallback component)
						{
							portalActiveList.Remove(component);
						}));
					}
					break;
				}
				}
			}

			public void onPostPopulateSceneServer(SceneDirector director)
			{
				if (trial == "punch")
				{
					Reflection.GetFieldValue<BoolConVar>(typeof(CombatDirector), "cvDirectorCombatDisable").SetBool(true);
					enemyCount = GetLiveMonsters();
				}
			}

			public void ReportObjective(CharacterMaster master, List<ObjectiveSourceDescriptor> output)
			{
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				switch (trial)
				{
				case "lava":
					if (portalsPassed != portalCount)
					{
						output.Add(new ObjectiveSourceDescriptor
						{
							source = (Object)(object)this,
							master = master,
							objectiveType = typeof(DestroyTimeCrystals)
						});
					}
					break;
				case "punch":
					output.Add(new ObjectiveSourceDescriptor
					{
						source = (Object)(object)this,
						master = master,
						objectiveType = typeof(DestroyTimeCrystals)
					});
					break;
				case "portal":
					if (portalsPassed != portalCount)
					{
						output.Add(new ObjectiveSourceDescriptor
						{
							source = (Object)(object)this,
							master = master,
							objectiveType = typeof(DestroyTimeCrystals)
						});
					}
					break;
				}
			}
		}

		public static GameObject loaderRunPrefab;

		public static GameObject extraGameModeMenu;

		private static SurvivorDef loaderDef = Addressables.LoadAssetAsync<SurvivorDef>((object)"RoR2/Base/Loader/Loader.asset").WaitForCompletion();

		public static GameEndingDef loaderRunEnding = Addressables.LoadAssetAsync<GameEndingDef>((object)"RoR2/Base/WeeklyRun/PrismaticTrialEnding.asset").WaitForCompletion();

		public static GameObject loaderRunPortal = PrefabAPI.InstantiateClone(Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/moon/MoonExitArenaOrb.prefab").WaitForCompletion(), "LoaderRunPortal", false);

		public static GameObject positionIndicator = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/VoidCamp/VoidCampPositionIndicator.prefab").WaitForCompletion();

		public GameMode()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			loaderRunPortal.AddComponent<NetworkIdentity>();
			PrefabAPI.RegisterNetworkPrefab(loaderRunPortal);
			Object.Destroy((Object)(object)loaderRunPortal.GetComponent<MapZone>());
			loaderRunPortal.AddComponent<PortalCollision>();
			loaderRunPrefab = PrefabAPI.InstantiateClone(new GameObject("xLoaderRun"), "xLoaderRun", false);
			loaderRunPrefab.AddComponent<NetworkIdentity>();
			PrefabAPI.RegisterNetworkPrefab(loaderRunPrefab);
			Run component = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/ClassicRun/ClassicRun.prefab").WaitForCompletion().GetComponent<Run>();
			LoaderRun loaderRun = loaderRunPrefab.AddComponent<LoaderRun>();
			((Run)loaderRun).nameToken = "Loader Trials";
			((Run)loaderRun).userPickable = true;
			((Run)loaderRun).startingSceneGroup = component.startingSceneGroup;
			((Run)loaderRun).gameOverPrefab = component.gameOverPrefab;
			((Run)loaderRun).lobbyBackgroundPrefab = component.lobbyBackgroundPrefab;
			((Run)loaderRun).uiPrefab = component.uiPrefab;
			loaderRunPrefab.AddComponent<TeamManager>();
			loaderRunPrefab.AddComponent<RunCameraManager>();
			ContentAddition.AddGameMode(loaderRunPrefab);
			LanguageTextMeshController.Start += new hook_Start(LanguageTextMeshController_Start);
			GameModeCatalog.SetGameModes += new hook_SetGameModes(GameModeCatalog_SetGameModes);
			Run.OverrideRuleChoices += new hook_OverrideRuleChoices(Run_OverrideRuleChoices);
			CharacterSelectBarController.ShouldDisplaySurvivor += new hook_ShouldDisplaySurvivor(CharacterSelectBarController_ShouldDisplaySurvivor);
			CharacterSelectBarController.GetLocalUserExistingSurvivorPreference += new hook_GetLocalUserExistingSurvivorPreference(CharacterSelectBarController_GetLocalUserExistingSurvivorPreference);
			DestroyTimeCrystals.GenerateString += new hook_GenerateString(DestroyTimeCrystals_GenerateString);
			CharacterMaster.OnBodyStart += new hook_OnBodyStart(CharacterMaster_OnBodyStart);
			CharacterMaster.OnBodyDeath += new hook_OnBodyDeath(CharacterMaster_OnBodyDeath);
		}

		private void GameModeCatalog_SetGameModes(orig_SetGameModes orig, Run[] newGameModePrefabComponents)
		{
			Array.Sort(newGameModePrefabComponents, (Run a, Run b) => string.CompareOrdinal(((Object)a).name, ((Object)b).name));
			orig.Invoke(newGameModePrefabComponents);
		}

		private void Run_OverrideRuleChoices(orig_OverrideRuleChoices orig, Run self, RuleChoiceMask mustInclude, RuleChoiceMask mustExclude, ulong runSeed)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, mustInclude, mustExclude, runSeed);
			if (!Object.op_Implicit((Object)(object)PreGameController.instance) || PreGameController.instance.gameModeIndex != GameModeCatalog.FindGameModeIndex("xLoaderRun"))
			{
				return;
			}
			self.ForceChoice(mustInclude, mustExclude, "Difficulty.Hard");
			RuleDef obj = RuleCatalog.FindRuleDef("Misc.StageOrder");
			RuleChoiceDef val = ((obj != null) ? obj.FindChoice("Random") : null);
			if (val != null)
			{
				self.ForceChoice(mustInclude, mustExclude, val);
			}
			ItemIndex val2 = (ItemIndex)0;
			for (ItemIndex val3 = (ItemIndex)ItemCatalog.itemCount; val2 < val3; val2 = (ItemIndex)(val2 + 1))
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(val2);
				RuleDef obj2 = RuleCatalog.FindRuleDef("Items." + ((Object)itemDef).name);
				RuleChoiceDef val4 = ((obj2 != null) ? obj2.FindChoice(((Object)(object)itemDef.requiredExpansion == (Object)null) ? "On" : "Off") : null);
				if (val4 != null)
				{
					self.ForceChoice(mustInclude, mustExclude, val4);
				}
			}
			EquipmentIndex val5 = (EquipmentIndex)0;
			for (EquipmentIndex val6 = (EquipmentIndex)EquipmentCatalog.equipmentCount; val5 < val6; val5 = (EquipmentIndex)(val5 + 1))
			{
				EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(val5);
				RuleDef obj3 = RuleCatalog.FindRuleDef("Equipment." + ((Object)equipmentDef).name);
				RuleChoiceDef val7 = ((obj3 != null) ? obj3.FindChoice(((Object)(object)equipmentDef.requiredExpansion == (Object)null) ? "On" : "Off") : null);
				if (val7 != null)
				{
					self.ForceChoice(mustInclude, mustExclude, val7);
				}
			}
			Enumerator<ExpansionDef> enumerator = ExpansionCatalog.expansionDefs.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Object current = (Object)(object)enumerator.Current;
					RuleDef obj4 = RuleCatalog.FindRuleDef("Expansions." + current.name);
					RuleChoiceDef val8 = ((obj4 != null) ? obj4.FindChoice("Off") : null);
					if (val8 != null)
					{
						self.ForceChoice(mustInclude, mustExclude, val8);
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			ArtifactDef[] artifactDefs = ArtifactCatalog.artifactDefs;
			foreach (ArtifactDef val9 in artifactDefs)
			{
				RuleDef obj5 = RuleCatalog.FindRuleDef("Artifacts." + val9.cachedName);
				RuleChoiceDef val10 = ((obj5 != null) ? obj5.FindChoice("Off") : null);
				if (val10 != null)
				{
					self.ForceChoice(mustInclude, mustExclude, val10);
				}
			}
		}

		private bool CharacterSelectBarController_ShouldDisplaySurvivor(orig_ShouldDisplaySurvivor orig, CharacterSelectBarController self, SurvivorDef survivorDef)
		{
			if (!(((BaseConVar)GameModeConVar.instance).GetString() == "xLoaderRun"))
			{
				return orig.Invoke(self, survivorDef);
			}
			return survivorDef.cachedName == "Loader";
		}

		private SurvivorDef CharacterSelectBarController_GetLocalUserExistingSurvivorPreference(orig_GetLocalUserExistingSurvivorPreference orig, CharacterSelectBarController self)
		{
			if (!(((BaseConVar)GameModeConVar.instance).GetString() == "xLoaderRun"))
			{
				return orig.Invoke(self);
			}
			return loaderDef;
		}

		private void LanguageTextMeshController_Start(orig_Start orig, LanguageTextMeshController self)
		{
			orig.Invoke(self);
			if (self.token == "TITLE_ECLIPSE" && Object.op_Implicit((Object)(object)((Component)self).GetComponent<HGButton>()))
			{
				((Component)((Component)self).transform.parent).gameObject.AddComponent<LoaderRunButtonAdder>();
			}
		}

		private string DestroyTimeCrystals_GenerateString(orig_GenerateString orig, ObjectiveTracker self)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (Run.instance.gameModeIndex != GameModeCatalog.FindGameModeIndex("xLoaderRun"))
			{
				return orig.Invoke(self);
			}
			LoaderRun component = ((Component)Run.instance).gameObject.GetComponent<LoaderRun>();
			string[] array = new string[3] { "Enter <color=#30e7ff>Time Portals</color> ({0}/{1})", "Kill <color=#30e7ff>{0}</color> Monsters", "Enter <color=#30e7ff>Time Portals</color> ({0}/{1}) <color=#30e7ff>WITHOUT TOUCHING THE GROUND</color>" };
			string result = "something went wrong :(";
			switch (component.trial)
			{
			case "lava":
				result = string.Format(array[2], component.portalsPassed, component.portalsRequiredToPass);
				break;
			case "punch":
				result = string.Format(array[1], component.enemyCount);
				break;
			case "portal":
				result = string.Format(array[0], component.portalsPassed, component.portalsRequiredToPass);
				break;
			}
			return result;
		}

		private void CharacterMaster_OnBodyStart(orig_OnBodyStart orig, CharacterMaster self, CharacterBody body)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, body);
			if (NetworkServer.active && Run.instance.gameModeIndex == GameModeCatalog.FindGameModeIndex("xLoaderRun"))
			{
				LoaderRun component = ((Component)Run.instance).gameObject.GetComponent<LoaderRun>();
				ItemIndex val = ItemCatalog.itemNameToIndex["LunarDagger"];
				int itemCount = body.inventory.GetItemCount(val);
				if (itemCount > 0)
				{
					body.inventory.RemoveItem(val, itemCount);
				}
				if (body.isPlayerControlled && component.trial == "punch")
				{
					body.inventory.GiveItemString("LunarDagger", 10);
				}
				if (body.isPlayerControlled && component.trial == "lava")
				{
					((Component)body).gameObject.AddComponent<LavaController>();
					body.inventory.GiveItemString("AlienHead", 20);
					body.inventory.GiveItemString("SecondarySkillMagazine", 5);
				}
			}
		}

		private void CharacterMaster_OnBodyDeath(orig_OnBodyDeath orig, CharacterMaster self, CharacterBody body)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			orig.Invoke(self, body);
			if (!NetworkServer.active || Run.instance.gameModeIndex != GameModeCatalog.FindGameModeIndex("xLoaderRun") || !Object.op_Implicit((Object)(object)body.teamComponent) || (int)body.teamComponent.teamIndex != 2)
			{
				return;
			}
			LoaderRun component = ((Component)Run.instance).gameObject.GetComponent<LoaderRun>();
			component.enemyCount = GetLiveMonsters();
			if (component.enemyCount == 0)
			{
				if (Run.instance.stageClearCount == 2)
				{
					Run.instance.BeginGameOver(loaderRunEnding);
					return;
				}
				Run.instance.PickNextStageSceneFromCurrentSceneDestinations();
				Run.instance.AdvanceStage(Run.instance.nextStageScene);
			}
		}

		public static int GetLiveMonsters()
		{
			//IL_0001: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			TeamIndex val = (TeamIndex)2;
			int num = 0;
			CharacterMaster[] array = Object.FindObjectsOfType<CharacterMaster>();
			foreach (CharacterMaster val2 in array)
			{
				if (val2.teamIndex == val)
				{
					CharacterBody body = val2.GetBody();
					if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive)
					{
						num++;
					}
				}
			}
			return num;
		}
	}
	[BepInPlugin("com.Nuxlar.LoaderTrials", "LoaderTrials", "1.0.1")]
	public class LoaderTrials : BaseUnityPlugin
	{
		public void Awake()
		{
			new GameMode();
		}
	}
}