Decompiled source of SimulacrumNormalStagesFix v1.1.0

SimulacrumNormalStagesFix.dll

Decompiled 6 months 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 BepInEx.Logging;
using HG.Reflection;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("SimulacrumNormalStagesFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SimulacrumNormalStagesFix")]
[assembly: AssemblyTitle("SimulacrumNormalStagesFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[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 SimulacrumNormalStagesFix
{
	public class EnumCollection
	{
		public enum StageEnum
		{
			None,
			TitanicPlains,
			DistantRoost,
			WetlandAspect,
			AbandonedAqueduct,
			RallypointDelta,
			ScorchedAcres,
			AbyssalDepths,
			SirensCall,
			GildedCoast,
			MomentFractured,
			Bazaar,
			VoidFields,
			MomentWhole,
			SkyMeadow,
			BullwarksAmbry,
			Commencement,
			SunderedGrove,
			VoidLocus,
			Planetarium,
			AphelianSanctuary,
			SimulacrumAbandonedAquaduct,
			SimulacrumAbyssalDepths,
			SimulacrumAphelianSanctuary,
			SimulacrumCommencement,
			SimulacrumRallypointDelta,
			SimulacrumSkyMeadow,
			SimulacrumTitanicPlains,
			SiphonedForest,
			SulfurPools
		}

		public static Dictionary<StageEnum, List<string>> SceneNames = new Dictionary<StageEnum, List<string>>
		{
			{
				StageEnum.TitanicPlains,
				new List<string> { "golemplains", "golemplains2", "golemplains trailer" }
			},
			{
				StageEnum.DistantRoost,
				new List<string> { "blackbeach", "blackbeach2", "blackbeachTest" }
			},
			{
				StageEnum.WetlandAspect,
				new List<string> { "foggyswamp" }
			},
			{
				StageEnum.AbandonedAqueduct,
				new List<string> { "goolake" }
			},
			{
				StageEnum.RallypointDelta,
				new List<string> { "frozenwall" }
			},
			{
				StageEnum.ScorchedAcres,
				new List<string> { "wispgraveyard" }
			},
			{
				StageEnum.AbyssalDepths,
				new List<string> { "dampcavesimple" }
			},
			{
				StageEnum.SirensCall,
				new List<string> { "shipgraveyard" }
			},
			{
				StageEnum.GildedCoast,
				new List<string> { "goldshores" }
			},
			{
				StageEnum.MomentFractured,
				new List<string> { "mysteryspace" }
			},
			{
				StageEnum.Bazaar,
				new List<string> { "bazaar" }
			},
			{
				StageEnum.VoidFields,
				new List<string> { "arena" }
			},
			{
				StageEnum.MomentWhole,
				new List<string> { "limbo" }
			},
			{
				StageEnum.SkyMeadow,
				new List<string> { "skymeadow" }
			},
			{
				StageEnum.BullwarksAmbry,
				new List<string> { "artifactworld" }
			},
			{
				StageEnum.Commencement,
				new List<string> { "moon", "moon2" }
			},
			{
				StageEnum.SunderedGrove,
				new List<string> { "rootjungle" }
			},
			{
				StageEnum.VoidLocus,
				new List<string> { "voidstage" }
			},
			{
				StageEnum.Planetarium,
				new List<string> { "voidraid" }
			},
			{
				StageEnum.AphelianSanctuary,
				new List<string> { "ancientloft" }
			},
			{
				StageEnum.SimulacrumAbandonedAquaduct,
				new List<string> { "itgoolake" }
			},
			{
				StageEnum.SimulacrumAbyssalDepths,
				new List<string> { "itdampcave" }
			},
			{
				StageEnum.SimulacrumAphelianSanctuary,
				new List<string> { "itancientloft" }
			},
			{
				StageEnum.SimulacrumCommencement,
				new List<string> { "itmoon" }
			},
			{
				StageEnum.SimulacrumRallypointDelta,
				new List<string> { "itfrozenwall" }
			},
			{
				StageEnum.SimulacrumSkyMeadow,
				new List<string> { "itskymeadow" }
			},
			{
				StageEnum.SimulacrumTitanicPlains,
				new List<string> { "itgolemplains" }
			},
			{
				StageEnum.SiphonedForest,
				new List<string> { "snowyforest" }
			},
			{
				StageEnum.SulfurPools,
				new List<string> { "sulfurpools" }
			}
		};

		private static SceneEntry createSceneEntry(StageEnum stageEnum, float weight = 1f)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			return createSceneEntry(((IEnumerable<SceneDef>)(object)SceneCatalog.allStageSceneDefs).Where((SceneDef s) => s.cachedName == GetStageName(stageEnum)).First(), weight);
		}

		private static SceneEntry createSceneEntry(string stageName, float weight = 1f)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			return createSceneEntry(((IEnumerable<SceneDef>)(object)SceneCatalog.allStageSceneDefs).Where((SceneDef s) => s.cachedName == stageName).First(), weight);
		}

		private static SceneEntry createSceneEntry(SceneDef sceneDef, float weight = 1f)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			SceneEntry result = default(SceneEntry);
			result.sceneDef = sceneDef;
			((SceneEntry)(ref result)).weight = weight;
			return result;
		}

		public static List<SceneEntry> GetNormalStagesList()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00c7: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			return new List<SceneEntry>
			{
				createSceneEntry("golemplains", 0.5f),
				createSceneEntry("golemplains2", 0.5f),
				createSceneEntry("blackbeach", 0.5f),
				createSceneEntry("blackbeach2", 0.5f),
				createSceneEntry(StageEnum.WetlandAspect),
				createSceneEntry(StageEnum.AbandonedAqueduct),
				createSceneEntry(StageEnum.RallypointDelta),
				createSceneEntry(StageEnum.ScorchedAcres),
				createSceneEntry(StageEnum.AbyssalDepths),
				createSceneEntry(StageEnum.SirensCall),
				createSceneEntry(StageEnum.SkyMeadow),
				createSceneEntry(StageEnum.SunderedGrove),
				createSceneEntry(StageEnum.AphelianSanctuary),
				createSceneEntry(StageEnum.SiphonedForest),
				createSceneEntry(StageEnum.SulfurPools),
				createSceneEntry("moon2")
			};
		}

		public static bool IsSimulacrumStage(string name)
		{
			if (GetStageName(StageEnum.SimulacrumAbandonedAquaduct) == name)
			{
				return true;
			}
			if (GetStageName(StageEnum.SimulacrumAbyssalDepths) == name)
			{
				return true;
			}
			if (GetStageName(StageEnum.SimulacrumAphelianSanctuary) == name)
			{
				return true;
			}
			if (GetStageName(StageEnum.SimulacrumCommencement) == name)
			{
				return true;
			}
			if (GetStageName(StageEnum.SimulacrumRallypointDelta) == name)
			{
				return true;
			}
			if (GetStageName(StageEnum.SimulacrumSkyMeadow) == name)
			{
				return true;
			}
			if (GetStageName(StageEnum.SimulacrumTitanicPlains) == name)
			{
				return true;
			}
			return false;
		}

		public static string GetStageName(StageEnum stageEnum)
		{
			return SceneNames[stageEnum].First();
		}
	}
	internal static class Log
	{
		internal static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void LogDebug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void LogError(object data)
		{
			_logSource.LogError(data);
		}

		internal static void LogFatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void LogInfo(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void LogMessage(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void LogWarning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Def.SimulacrumNormalStagesFix", "SimulacrumNormalStagesFix", "1.1.0")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class SimulacrumNormalStagesFix : BaseUnityPlugin
	{
		public static SimulacrumNormalStagesFix instance;

		public const string PluginGUID = "Def.SimulacrumNormalStagesFix";

		public const string PluginAuthor = "Def";

		public const string PluginName = "SimulacrumNormalStagesFix";

		public const string PluginVersion = "1.1.0";

		public static PluginInfo PInfo { get; private set; }

		public void Awake()
		{
			PInfo = ((BaseUnityPlugin)this).Info;
			instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
		}

		private void OnEnable()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			ArenaMissionController.OnStartServer += new Manipulator(ArenaMissionController_OnStartServer);
			VoidStageMissionController.OnEnable += new Manipulator(VoidStageMissionController_OnEnable);
			VoidStageMissionController.Start += new Manipulator(VoidStageMissionController_Start);
			InfiniteTowerRun.OnPrePopulateSceneServer += new Manipulator(InfiniteTowerRun_OnPrePopulateSceneServer);
			InfiniteTowerRun.OnPrePopulateSceneServer += new hook_OnPrePopulateSceneServer(InfiniteTowerRun_OnPrePopulateSceneServer);
			SceneCatalog.OnActiveSceneChanged += new hook_OnActiveSceneChanged(SceneCatalog_OnActiveSceneChanged);
		}

		private void OnDisable()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			ArenaMissionController.OnStartServer -= new Manipulator(ArenaMissionController_OnStartServer);
			VoidStageMissionController.OnEnable -= new Manipulator(VoidStageMissionController_OnEnable);
			VoidStageMissionController.Start -= new Manipulator(VoidStageMissionController_Start);
			InfiniteTowerRun.OnPrePopulateSceneServer -= new Manipulator(InfiniteTowerRun_OnPrePopulateSceneServer);
			InfiniteTowerRun.OnPrePopulateSceneServer -= new hook_OnPrePopulateSceneServer(InfiniteTowerRun_OnPrePopulateSceneServer);
			SceneCatalog.OnActiveSceneChanged -= new hook_OnActiveSceneChanged(SceneCatalog_OnActiveSceneChanged);
		}

		private void SceneCatalog_OnActiveSceneChanged(orig_OnActiveSceneChanged orig, Scene oldScene, Scene newScene)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(oldScene, newScene);
			if (NetworkServer.active && ((object)Run.instance).GetType() == typeof(InfiniteTowerRun) && (Object)(object)SceneCatalog.mostRecentSceneDef != (Object)null && SceneCatalog.mostRecentSceneDef.baseSceneName == "arena")
			{
				SceneCatalog.mostRecentSceneDef.sceneType = (SceneType)1;
			}
		}

		private void ReturnImmediately<T>(ILContext il, Func<T, bool> funcWhetherToReturnImmediately)
		{
			//IL_0008: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			ILLabel val = il.DefineLabel();
			ILCursor val2 = new ILCursor(il);
			val2.Emit(OpCodes.Ldarg_0);
			val2.EmitDelegate<Func<T, bool>>(funcWhetherToReturnImmediately);
			val2.Emit(OpCodes.Brfalse, (object)val);
			val2.Emit(OpCodes.Ret);
			val2.MarkLabel(val);
		}

		private void ArenaMissionController_OnStartServer(ILContext il)
		{
			ReturnImmediately(il, delegate(ArenaMissionController self)
			{
				if (((object)Run.instance).GetType() == typeof(InfiniteTowerRun))
				{
					GameObject val = GameObject.Find("PortalArena");
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)val);
					}
					GameObject[] nullWards = self.nullWards;
					for (int i = 0; i < nullWards.Length; i++)
					{
						Object.Destroy((Object)(object)nullWards[i]);
					}
					self.nullWards = (GameObject[])(object)new GameObject[0];
					((Behaviour)self).enabled = false;
					return true;
				}
				return false;
			});
		}

		private void VoidStageMissionController_OnEnable(ILContext il)
		{
			ReturnImmediately(il, delegate(VoidStageMissionController self)
			{
				if (((object)Run.instance).GetType() == typeof(InfiniteTowerRun))
				{
					((Behaviour)self).enabled = false;
					return true;
				}
				return false;
			});
		}

		private void VoidStageMissionController_Start(ILContext il)
		{
			ReturnImmediately(il, delegate(VoidStageMissionController self)
			{
				if (((object)Run.instance).GetType() == typeof(InfiniteTowerRun))
				{
					if (Object.op_Implicit((Object)(object)self.deepVoidPortalObjectiveProvider))
					{
						((Behaviour)self.deepVoidPortalObjectiveProvider).enabled = false;
					}
					return true;
				}
				return false;
			});
		}

		private void InfiniteTowerRun_OnPrePopulateSceneServer(ILContext il)
		{
			ReturnImmediately(il, delegate(InfiniteTowerRun self)
			{
				if (((Run)self).nextStageScene.cachedName == EnumCollection.GetStageName(EnumCollection.StageEnum.Bazaar))
				{
					self.PerformStageCleanUp();
					return true;
				}
				return false;
			});
		}

		private void InfiniteTowerRun_OnPrePopulateSceneServer(orig_OnPrePopulateSceneServer orig, InfiniteTowerRun self, SceneDirector sceneDirector)
		{
			if (!EnumCollection.IsSimulacrumStage(((Run)self).nextStageScene.cachedName))
			{
				for (int i = 0; i < SpawnPoint.readOnlyInstancesList.Count; i++)
				{
					if (!SpawnPoint.readOnlyInstancesList[i].consumed)
					{
						SpawnPoint.readOnlyInstancesList[i].consumed = true;
					}
				}
				sceneDirector.monsterCredit = 0;
				CombatDirector[] array = CombatDirector.instancesList.ToArray();
				for (int j = 0; j < array.Length; j++)
				{
					((Behaviour)array[j]).enabled = false;
				}
			}
			orig.Invoke(self, sceneDirector);
		}
	}
}