Decompiled source of EnvyAndSpiteVanitized v1.5.4

ImNotSimon.ESVanified/DoomahLevelLoader.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using DoomahLevelLoader.UnityComponents;
using HarmonyLib;
using Logic;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.AddressableAssets.ResourceLocators;
using UnityEngine.Events;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("DoomahLevelLoader")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0cf93a53ad8ef37019ccab94c858dda4fdb8eefa")]
[assembly: AssemblyProduct("DoomahLevelLoader")]
[assembly: AssemblyTitle("DoomahLevelLoader")]
[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;
		}
	}
}
public class OpenDiscord : MonoBehaviour
{
	public void Open()
	{
		Application.OpenURL("https://discord.gg/RY8J67neJ9");
	}
}
public class TriggerZoneBehavior : MonoBehaviour
{
	public float delay = 2f;

	public float activationDelay = 0.1f;

	private bool hasActivated;

	private List<Transform> ignoreList = new List<Transform>();

	private void Start()
	{
		Collider component = ((Component)this).GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			component.isTrigger = true;
		}
		DelayedInitialization();
	}

	private void DelayedInitialization()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		foreach (Transform item in ((Component)this).transform)
		{
			((Component)item).gameObject.SetActive(false);
		}
	}

	private IEnumerator ActivateChildrenWithDelay()
	{
		bool allChildrenActivated;
		do
		{
			allChildrenActivated = true;
			foreach (Transform item in ((Component)this).transform)
			{
				Transform child = item;
				if ((Object)(object)child == (Object)null)
				{
					continue;
				}
				if (!ignoreList.Contains(child) && !((Object)child).name.Contains("Gore Zone") && !((Component)child).gameObject.activeSelf)
				{
					allChildrenActivated = false;
					if (((Object)child).name != null && (((Object)child).name != "NoPass(Clone)" || (Object)(object)((Component)child).GetComponent<AddressableReplacer>() == (Object)null))
					{
						yield return (object)new WaitForSeconds(activationDelay);
					}
					((Component)child).gameObject.SetActive(true);
					Debug.Log((object)("Trigger Activated child:  " + ((Object)child).name));
				}
				else
				{
					ignoreList.Add(child);
				}
			}
		}
		while (!allChildrenActivated);
		hasActivated = true;
	}

	private void OnTriggerEnter(Collider other)
	{
		if (((Object)((Component)other).gameObject).name == "Player" && !hasActivated)
		{
			((MonoBehaviour)this).StartCoroutine(ActivateChildrenWithDelay());
		}
	}
}
public class WaveComponent : MonoBehaviour
{
	public float checkInterval = 1f;

	private float timer;

	private float activationDelay = 0.1f;

	private bool hasActivated;

	private List<Transform> activatedChildren = new List<Transform>();

	private List<Transform> ignoreList = new List<Transform>();

	private void Start()
	{
		DisableAllChildren();
	}

	private void DisableAllChildren()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		foreach (Transform item in ((Component)this).transform)
		{
			((Component)item).gameObject.SetActive(false);
		}
	}

	private void Update()
	{
		timer += Time.deltaTime;
		if (timer >= checkInterval)
		{
			timer = 0f;
			CheckChildren();
		}
	}

	private IEnumerator ActivateChildrenWithDelay(Transform[] childrenToActivate)
	{
		foreach (Transform val in childrenToActivate)
		{
			if (((Object)val).name != "NoPass(Clone)" || (Object)(object)((Component)val).GetComponent<AddressableReplacer>() == (Object)null)
			{
				((Component)val).gameObject.SetActive(true);
				yield return (object)new WaitForSeconds(activationDelay);
			}
			else
			{
				((Component)val).gameObject.SetActive(true);
			}
		}
	}

	private void CheckChildren()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		GameObject gameObject = ((Component)((Component)this).transform.parent).gameObject;
		List<GameObject> list = new List<GameObject>();
		foreach (Transform item in ((Component)this).transform)
		{
			Transform val = item;
			list.Add(((Component)val).gameObject);
		}
		List<Transform> list2 = new List<Transform>();
		list2.AddRange(gameObject.GetComponentsInChildren<Transform>());
		list2.Remove(((Component)this).transform);
		List<Transform> list3 = new List<Transform>();
		foreach (Transform item2 in list2)
		{
			EnemyIdentifier component = ((Component)item2).GetComponent<EnemyIdentifier>();
			if ((Object)(object)component != (Object)null && !component.dead)
			{
				list3.Add(item2);
			}
			else if ((Object)(object)component != (Object)null && component.dead && list3.Contains(item2))
			{
				list3.Remove(item2);
			}
		}
		Transform[] array = (Transform[])(object)new Transform[list.Count];
		for (int i = 0; i < list.Count; i++)
		{
			array[i] = list[i].transform;
		}
		if (list3.Count == 0 && !hasActivated)
		{
			hasActivated = true;
			((MonoBehaviour)this).StartCoroutine(ActivateChildrenWithDelay(array));
		}
	}
}
public static class ShaderManager
{
	public class ShaderInfo
	{
		public string Name { get; set; }
	}

	public static Dictionary<string, Shader> shaderDictionary = new Dictionary<string, Shader>();

	private static HashSet<Material> modifiedMaterials = new HashSet<Material>();

	public static IEnumerator LoadShadersAsync()
	{
		AsyncOperationHandle<IResourceLocator> handle = Addressables.InitializeAsync();
		while (!handle.IsDone)
		{
			yield return null;
		}
		if ((int)handle.Status == 1)
		{
			IResourceLocator result = handle.Result;
			foreach (string key in ((ResourceLocationMap)result).Keys)
			{
				if (!key.EndsWith(".shader"))
				{
					continue;
				}
				AsyncOperationHandle<Shader> shaderHandle = Addressables.LoadAssetAsync<Shader>((object)key);
				while (!shaderHandle.IsDone)
				{
					yield return null;
				}
				if ((int)shaderHandle.Status == 1)
				{
					Shader result2 = shaderHandle.Result;
					if ((Object)(object)result2 != (Object)null && ((Object)result2).name != "ULTRAKILL/PostProcessV2" && !shaderDictionary.ContainsKey(((Object)result2).name))
					{
						shaderDictionary[((Object)result2).name] = result2;
					}
				}
				else
				{
					Debug.LogError((object)("Failed to load shader: " + shaderHandle.OperationException));
				}
			}
		}
		else
		{
			Debug.LogError((object)("Addressables initialization failed: " + handle.OperationException));
		}
	}

	public static string ModPath()
	{
		return Assembly.GetExecutingAssembly().Location.Substring(0, Assembly.GetExecutingAssembly().Location.LastIndexOf(Path.DirectorySeparatorChar));
	}

	public static IEnumerator ApplyShadersAsync(GameObject[] allGameObjects)
	{
		if (allGameObjects == null)
		{
			yield break;
		}
		foreach (GameObject val in allGameObjects)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Material[] array = (Material[])(object)new Material[val2.sharedMaterials.Length];
				for (int k = 0; k < val2.sharedMaterials.Length; k++)
				{
					Material val3 = (array[k] = val2.sharedMaterials[k]);
					if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3.shader == (Object)null) && !modifiedMaterials.Contains(val3) && !(((Object)val3.shader).name == "ULTRAKILL/PostProcessV2") && shaderDictionary.TryGetValue(((Object)val3.shader).name, out var value))
					{
						array[k].shader = value;
						modifiedMaterials.Add(val3);
					}
				}
				val2.materials = array;
			}
			yield return null;
		}
	}

	public static IEnumerator ApplyShadersAsyncContinuously()
	{
		new GameObject("ShaderManagerObject").AddComponent<ShaderManagerRunner>().StartApplyingShaders();
		yield return null;
	}

	public static void CreateShaderDictionary()
	{
		List<ShaderInfo> list = new List<ShaderInfo>();
		Shader[] array = Resources.FindObjectsOfTypeAll<Shader>();
		foreach (Shader shader in array)
		{
			if (!list.Any((ShaderInfo s) => s.Name == ((Object)shader).name))
			{
				list.Add(new ShaderInfo
				{
					Name = ((Object)shader).name
				});
			}
		}
		string contents = JsonConvert.SerializeObject((object)list, (Formatting)1);
		File.WriteAllText(Path.Combine(ModPath(), "ShaderList.json"), contents);
	}

	public static IEnumerator LoadShadersFromDictionaryAsync()
	{
		string path = Path.Combine(ModPath(), "ShaderList.json");
		if (!File.Exists(path))
		{
			yield break;
		}
		Task<string> shaderDataTask = ReadAllTextAsync(path);
		while (!shaderDataTask.IsCompleted)
		{
			yield return null;
		}
		List<ShaderInfo> list = JsonConvert.DeserializeObject<List<ShaderInfo>>(shaderDataTask.Result);
		Dictionary<string, Shader> dictionary = new Dictionary<string, Shader>();
		foreach (ShaderInfo item in list)
		{
			Shader val = Shader.Find(item.Name);
			if ((Object)(object)val != (Object)null)
			{
				if (!dictionary.ContainsKey(item.Name))
				{
					dictionary[item.Name] = val;
				}
				else
				{
					Debug.LogWarning((object)("Duplicate shader name found: " + item.Name));
				}
			}
		}
		Material[] array = Resources.FindObjectsOfTypeAll<Material>();
		foreach (Material val2 in array)
		{
			if (dictionary.TryGetValue(((Object)val2.shader).name, out var value) && (Object)(object)val2.shader != (Object)(object)value)
			{
				val2.shader = value;
			}
		}
	}

	private static async Task<string> ReadAllTextAsync(string path)
	{
		using StreamReader reader = new StreamReader(path);
		return await reader.ReadToEndAsync();
	}
}
public class ShaderManagerRunner : MonoBehaviour
{
	public void StartApplyingShaders()
	{
		((MonoBehaviour)this).StartCoroutine(ApplyShadersContinuously());
	}

	private IEnumerator ApplyShadersContinuously()
	{
		while (true)
		{
			yield return (object)new WaitForSeconds(0.15f);
			Scene activeScene = SceneManager.GetActiveScene();
			yield return ShaderManager.ApplyShadersAsync(((Scene)(ref activeScene)).GetRootGameObjects());
			yield return ShaderManager.LoadShadersFromDictionaryAsync();
		}
	}
}
namespace meshwhatever
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DoomahLevelLoader";

		public const string PLUGIN_NAME = "DoomahLevelLoader";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DoomahLevelLoader
{
	public class RefreshAndDirectory : MonoBehaviour
	{
		private static RefreshAndDirectory instance;

		public Button Refresh;

		public Button Directory;

		public static RefreshAndDirectory Instance
		{
			get
			{
				if ((Object)(object)instance == (Object)null)
				{
					instance = Object.FindObjectOfType<RefreshAndDirectory>();
					if ((Object)(object)instance == (Object)null)
					{
						Debug.LogError((object)"RefreshAndDirectory instance not found in the scene.");
					}
				}
				return instance;
			}
		}

		private void Start()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((UnityEvent)Refresh.onClick).AddListener(new UnityAction(Refreshaction));
			((UnityEvent)Directory.onClick).AddListener(new UnityAction(DirectoryOpen));
		}

		private void Refreshaction()
		{
			Loaderscene.Refresh();
		}

		private void DirectoryOpen()
		{
			Loaderscene.OpenFilesFolder();
		}
	}
	public class EnvyLoaderMenu : MonoBehaviour
	{
		private static EnvyLoaderMenu instance;

		public GameObject ContentStuff;

		public Button MenuOpener;

		public GameObject LevelsMenu;

		public GameObject LevelsButton;

		public Button Goback;

		public GameObject FuckingPleaseWait;

		public static EnvyLoaderMenu Instance
		{
			get
			{
				if ((Object)(object)instance == (Object)null)
				{
					instance = Object.FindObjectOfType<EnvyLoaderMenu>();
					if ((Object)(object)instance == (Object)null)
					{
						Debug.LogError((object)"EnvyLoaderMenu instance not found in the scene.");
					}
				}
				return instance;
			}
		}

		private void Start()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((UnityEvent)MenuOpener.onClick).AddListener(new UnityAction(OpenLevelsMenu));
			((UnityEvent)Goback.onClick).AddListener(new UnityAction(GoBackToMenu));
			CreateLevels();
		}

		public static void CreateLevels()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				return;
			}
			for (int i = 0; i < Loaderscene.loadedAssetBundles.Count; i++)
			{
				string text = Loaderscene.bundleFolderPaths[i];
				string path = Path.Combine(text, "info.txt");
				if (!Directory.Exists(text))
				{
					Debug.LogWarning((object)("Skipping level at '" + text + "' because the directory does not exist."));
					continue;
				}
				GameObject obj = Object.Instantiate<GameObject>(Instance.LevelsButton, Instance.ContentStuff.transform);
				Button component = obj.GetComponent<Button>();
				int index = i;
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					Loaderscene.currentAssetBundleIndex = index;
					Loaderscene.ExtractSceneName();
					Loaderscene.Loadscene();
				});
				LevelButtonScript component2 = obj.GetComponent<LevelButtonScript>();
				Loaderscene.UpdateLevelPicture(component2.LevelImageButtonThing, component2.NoLevel, getFirstBundle: false, text);
				string assetBundleSize = Loaderscene.GetAssetBundleSize(index);
				((TMP_Text)component2.FileSize).text = assetBundleSize;
				try
				{
					string[] array = File.ReadAllLines(path);
					if (array.Length >= 2)
					{
						((TMP_Text)component2.Author).text = array[0] ?? "Failed to load Author name!";
						((TMP_Text)component2.LevelName).text = array[1] ?? "Failed to load Level name!";
					}
					else
					{
						((TMP_Text)component2.Author).text = "Failed to load Author name!";
						((TMP_Text)component2.LevelName).text = "Failed to load Level name!";
					}
				}
				catch
				{
					Debug.LogError((object)("Failed to read info.txt in bundle folder '" + text + "'"));
				}
			}
		}

		public static void ClearContentStuffChildren()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null)
			{
				return;
			}
			foreach (Transform item in Instance.ContentStuff.transform)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
		}

		public static IEnumerator UpdateLevelListingCoroutine()
		{
			Instance.FuckingPleaseWait.SetActive(true);
			ClearContentStuffChildren();
			CreateLevels();
			yield return null;
			Instance.FuckingPleaseWait.SetActive(false);
		}

		public static void UpdateLevelListing()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((MonoBehaviour)Instance).StartCoroutine(UpdateLevelListingCoroutine());
			}
		}

		private void OpenLevelsMenu()
		{
			LevelsMenu.SetActive(true);
			((Component)MenuOpener).gameObject.SetActive(false);
			MainMenuAgony.isAgonyOpen = true;
		}

		private void GoBackToMenu()
		{
			LevelsMenu.SetActive(false);
			((Component)MenuOpener).gameObject.SetActive(true);
			MainMenuAgony.isAgonyOpen = false;
		}
	}
	public class DropdownHandler : MonoBehaviour
	{
		public TMP_Dropdown dropdown;

		private const string selectedDifficultyKey = "difficulty";

		private string settingsFilePath;

		private void Awake()
		{
			settingsFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "settings.json");
		}

		private void OnEnable()
		{
			int value = LoadDifficulty();
			dropdown.value = value;
			((UnityEvent<int>)(object)dropdown.onValueChanged).AddListener((UnityAction<int>)OnDropdownValueChanged);
		}

		private int LoadDifficulty()
		{
			if (File.Exists(settingsFilePath))
			{
				Dictionary<string, int> dictionary = JsonConvert.DeserializeObject<Dictionary<string, int>>(File.ReadAllText(settingsFilePath));
				if (dictionary != null && dictionary.TryGetValue("difficulty", out var value))
				{
					return value;
				}
			}
			return 2;
		}

		private void SaveDifficulty(int difficulty)
		{
			string contents = JsonConvert.SerializeObject((object)new Dictionary<string, int> { { "difficulty", difficulty } }, (Formatting)1);
			File.WriteAllText(settingsFilePath, contents);
		}

		public void OnDropdownValueChanged(int index)
		{
			SaveDifficulty(index);
		}
	}
	public class LevelButtonScript : MonoBehaviour
	{
		private static LevelButtonScript instance;

		public Image LevelImageButtonThing;

		public Button LevelButtonReal;

		public TextMeshProUGUI NoLevel;

		public TextMeshProUGUI FileSize;

		public TextMeshProUGUI Author;

		public TextMeshProUGUI LevelName;

		public static LevelButtonScript Instance
		{
			get
			{
				if ((Object)(object)instance == (Object)null)
				{
					instance = Object.FindObjectOfType<LevelButtonScript>();
					if ((Object)(object)instance == (Object)null)
					{
						Debug.LogError((object)"LevelButtonScript instance not found in the scene.");
					}
				}
				return instance;
			}
		}
	}
	public class EnvyandSpiteterimal : MonoBehaviour
	{
		private static EnvyandSpiteterimal instance;

		public TextMeshProUGUI levelname;

		public TextMeshProUGUI loadbutton;

		public Button load;

		public Button gofowardinlist;

		public Button gobackinlist;

		public Image Levelpicture;

		public TextMeshProUGUI FrownyFace;

		public GameObject FuckingPleaseWait;

		public Button Discord;

		public static EnvyandSpiteterimal Instance
		{
			get
			{
				if ((Object)(object)instance == (Object)null)
				{
					instance = Object.FindObjectOfType<EnvyandSpiteterimal>();
					if ((Object)(object)instance == (Object)null)
					{
						Debug.LogError((object)"EnvyandSpiteterimal instance not found in the scene.");
					}
				}
				return instance;
			}
		}

		private void Start()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_005a: 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_009d: Expected O, but got Unknown
			((UnityEvent)load.onClick).AddListener(new UnityAction(OnLoadButtonClick));
			((UnityEvent)gofowardinlist.onClick).AddListener(new UnityAction(OnGoForwardButtonClick));
			((UnityEvent)gobackinlist.onClick).AddListener(new UnityAction(OnGoBackButtonClick));
			((Graphic)Levelpicture).color = Color.white;
			UpdateLevelName();
			Loaderscene.UpdateLevelPicture(Levelpicture, FrownyFace);
			((UnityEvent)Discord.onClick).AddListener(new UnityAction(OnDiscordButtonClick));
		}

		private void OnLoadButtonClick()
		{
			Loaderscene.Loadscene();
		}

		private void OnGoForwardButtonClick()
		{
			Loaderscene.MoveToNextAssetBundle();
			Loaderscene.ExtractSceneName();
			UpdateLevelName();
			Loaderscene.UpdateLevelPicture(Levelpicture, FrownyFace);
		}

		private void OnGoBackButtonClick()
		{
			Loaderscene.MoveToPreviousAssetBundle();
			Loaderscene.ExtractSceneName();
			UpdateLevelName();
			Loaderscene.UpdateLevelPicture(Levelpicture, FrownyFace);
		}

		private void OnDiscordButtonClick()
		{
			Application.OpenURL("https://discord.gg/RY8J67neJ9");
		}

		public void UpdateLevelName()
		{
			string currentBundleFolderPath = Loaderscene.GetCurrentBundleFolderPath();
			if (string.IsNullOrEmpty(currentBundleFolderPath))
			{
				return;
			}
			string path = Path.Combine(currentBundleFolderPath, "info.txt");
			if (!File.Exists(path))
			{
				((TMP_Text)levelname).text = "Failed to load Level name!";
				return;
			}
			try
			{
				string[] array = File.ReadAllLines(path);
				if (array.Length >= 2)
				{
					string text = array[1];
					((TMP_Text)levelname).text = text;
				}
				else
				{
					((TMP_Text)levelname).text = "Failed to load Level name!";
				}
			}
			catch
			{
				((TMP_Text)levelname).text = "Failed to load Level name!";
			}
		}
	}
	public static class Loader
	{
		public static AssetBundle LoadTerminal()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string name = "meshwhatever.terminal.bundle";
				using Stream stream = executingAssembly.GetManifestResourceStream(name);
				if (stream == null)
				{
					Debug.LogError((object)"Resource 'terminal.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 terminal: " + ex.Message));
				return null;
			}
		}
	}
	public static class Loaderscene
	{
		public static List<AssetBundle> loadedAssetBundles;

		public static int currentAssetBundleIndex;

		public static List<string> bundleFolderPaths;

		private static EnvyLoaderMenu envyLoaderMenuScript;

		private static string executablePath;

		private static string directoryPath;

		public static string LoadedSceneName { get; set; }

		static Loaderscene()
		{
			loadedAssetBundles = new List<AssetBundle>();
			currentAssetBundleIndex = 0;
			bundleFolderPaths = new List<string>();
			executablePath = Assembly.GetExecutingAssembly().Location;
			directoryPath = Path.GetDirectoryName(executablePath);
		}

		public static string GetUnpackedLevelsPath()
		{
			return Path.Combine(directoryPath, "UnpackedLevels");
		}

		public static async Task Setup()
		{
			await RecreateUnpackedLevelsFolder(GetUnpackedLevelsPath());
		}

		public static async Task RecreateUnpackedLevelsFolder(string unpackedLevelsPath)
		{
			if (Directory.Exists(unpackedLevelsPath))
			{
				Directory.Delete(unpackedLevelsPath, recursive: true);
			}
			Directory.CreateDirectory(unpackedLevelsPath);
			string[] files = Directory.GetFiles(Plugin.getConfigPath(), "*.doomah");
			string[] array = files;
			foreach (string doomahFile in array)
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(doomahFile);
				string levelFolderPath = Path.Combine(unpackedLevelsPath, fileNameWithoutExtension);
				try
				{
					await Task.Run(delegate
					{
						ZipFile.ExtractToDirectory(doomahFile, levelFolderPath);
					});
					LoadAssetBundle(levelFolderPath);
				}
				catch
				{
					string fileName = Path.GetFileName(doomahFile);
					Debug.LogError((object)("Failed to extract " + fileName + "! Please uninstall map or ask creator to update to 1.3.0!"));
				}
			}
			EnvyLoaderMenu.UpdateLevelListing();
			await Task.CompletedTask;
		}

		public static async Task Refresh()
		{
			EnvyandSpiteterimal envyScript = Object.FindObjectOfType<EnvyandSpiteterimal>();
			if ((Object)(object)envyScript != (Object)null)
			{
				envyScript.FuckingPleaseWait.SetActive(true);
			}
			else
			{
				envyLoaderMenuScript = Object.FindObjectOfType<EnvyLoaderMenu>();
				if ((Object)(object)envyLoaderMenuScript != (Object)null)
				{
					envyLoaderMenuScript.FuckingPleaseWait.SetActive(true);
				}
			}
			await RecreateUnpackedLevelsFolder(GetUnpackedLevelsPath());
			await Task.WhenAll(new List<Task> { Setup() });
			if ((Object)(object)envyScript != (Object)null)
			{
				envyScript.FuckingPleaseWait.SetActive(false);
			}
			else if ((Object)(object)envyLoaderMenuScript != (Object)null)
			{
				envyLoaderMenuScript.FuckingPleaseWait.SetActive(false);
			}
			EnvyLoaderMenu.UpdateLevelListing();
		}

		public static async Task LoadAssetBundle(string folderPath)
		{
			string[] files = Directory.GetFiles(folderPath, "*.bundle");
			string[] array = files;
			foreach (string bundleFile in array)
			{
				await Task.Run(delegate
				{
					AssetBundle val = AssetBundle.LoadFromFile(bundleFile);
					if ((Object)(object)val != (Object)null)
					{
						loadedAssetBundles.Add(val);
						bundleFolderPaths.Add(Path.GetDirectoryName(bundleFile));
					}
				});
			}
		}

		public static string GetCurrentBundleFolderPath()
		{
			if (currentAssetBundleIndex >= 0 && currentAssetBundleIndex < bundleFolderPaths.Count)
			{
				return bundleFolderPaths[currentAssetBundleIndex];
			}
			return null;
		}

		public static void SelectAssetBundle(int index)
		{
			if (index >= 0 && index < loadedAssetBundles.Count)
			{
				currentAssetBundleIndex = index;
			}
		}

		public static void ExtractSceneName()
		{
			if (loadedAssetBundles.Count > 0)
			{
				string[] allScenePaths = loadedAssetBundles[currentAssetBundleIndex].GetAllScenePaths();
				if (allScenePaths.Length != 0)
				{
					LoadedSceneName = Path.GetFileNameWithoutExtension(allScenePaths[0]);
				}
			}
		}

		public static void Loadscene()
		{
			if (!string.IsNullOrEmpty(LoadedSceneName))
			{
				SceneManager.LoadSceneAsync(LoadedSceneName).completed += OnSceneLoadComplete;
				SceneHelper.ShowLoadingBlocker();
			}
		}

		private static void OnSceneLoadComplete(AsyncOperation asyncOperation)
		{
			SceneHelper.DismissBlockers();
		}

		public static void MoveToNextAssetBundle()
		{
			currentAssetBundleIndex = (currentAssetBundleIndex + 1) % loadedAssetBundles.Count;
		}

		public static void MoveToPreviousAssetBundle()
		{
			currentAssetBundleIndex = (currentAssetBundleIndex - 1 + loadedAssetBundles.Count) % loadedAssetBundles.Count;
		}

		public static void OpenFilesFolder()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			RuntimePlatform platform = Application.platform;
			if ((int)platform <= 2)
			{
				if ((int)platform <= 1)
				{
					Application.OpenURL("file://" + Plugin.getConfigPath());
					return;
				}
				if ((int)platform == 2)
				{
					goto IL_0024;
				}
			}
			else
			{
				if ((int)platform == 7)
				{
					goto IL_0024;
				}
				if ((int)platform == 13 || (int)platform == 16)
				{
					Application.OpenURL("file://" + Plugin.getConfigPath());
					return;
				}
			}
			Debug.LogWarning((object)"BROTHER WHAT IS YOUR OS?????");
			return;
			IL_0024:
			Application.OpenURL("file:///" + Plugin.getConfigPath().Replace("\\", "/"));
		}

		public static void UpdateLevelPicture(Image levelPicture, TextMeshProUGUI frownyFace, bool getFirstBundle = true, string bundlePath = "")
		{
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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)
			try
			{
				string text = "";
				if (getFirstBundle)
				{
					text = GetCurrentBundleFolderPath();
				}
				else
				{
					if (string.IsNullOrEmpty(bundlePath))
					{
						Debug.LogError((object)"Bundle folder path is null or empty.");
						((Component)frownyFace).gameObject.SetActive(true);
						((Graphic)levelPicture).color = new Color(1f, 1f, 1f, 0f);
						return;
					}
					text = bundlePath;
				}
				if (!string.IsNullOrEmpty(text))
				{
					string[] files = Directory.GetFiles(text, "*.png");
					if (files.Length != 0)
					{
						Texture2D val = LoadTextureFromFile(files[0]);
						if ((Object)(object)val != (Object)null)
						{
							((Texture)val).filterMode = (FilterMode)0;
							levelPicture.sprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero);
							((Component)frownyFace).gameObject.SetActive(false);
							((Graphic)levelPicture).color = Color.white;
						}
					}
					else
					{
						((Component)frownyFace).gameObject.SetActive(true);
						((Graphic)levelPicture).color = new Color(1f, 1f, 1f, 0f);
					}
				}
				else
				{
					Debug.LogError((object)"Bundle folder path is null or empty.");
					((Component)frownyFace).gameObject.SetActive(true);
					((Graphic)levelPicture).color = new Color(1f, 1f, 1f, 0f);
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("An error occurred while updating level picture: " + ex.Message));
				((Component)frownyFace).gameObject.SetActive(true);
				((Graphic)levelPicture).color = new Color(1f, 1f, 1f, 0f);
			}
		}

		private static Texture2D LoadTextureFromFile(string path)
		{
			//IL_0009: 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_0015: Expected O, but got Unknown
			//IL_0017: Expected O, but got Unknown
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			return val;
		}

		public static string GetAssetBundleSize(int index)
		{
			if (index >= 0 && index < loadedAssetBundles.Count)
			{
				_ = loadedAssetBundles[index];
				return FormatFileSize(CalculateFileSize(bundleFolderPaths[index]));
			}
			return "Index out of range";
		}

		private static long CalculateFileSize(string bundlePath)
		{
			long num = 0L;
			string[] files = Directory.GetFiles(bundlePath, "*", SearchOption.AllDirectories);
			foreach (string fileName in files)
			{
				num += new FileInfo(fileName).Length;
			}
			return num;
		}

		private static string FormatFileSize(long bytes)
		{
			string[] array = new string[6] { "B", "KB", "MB", "GB", "TB", "PB" };
			int num = 0;
			double num2 = bytes;
			while (num2 >= 1024.0 && num < array.Length - 1)
			{
				num2 /= 1024.0;
				num++;
			}
			return $"{Math.Round(num2, 2)} {array[num]}";
		}
	}
	[HarmonyPatch(typeof(SceneHelper), "RestartScene")]
	public static class SceneHelper_RestartScene_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if (Plugin.IsCustomLevel)
			{
				SceneManager.LoadScene(Loaderscene.LoadedSceneName);
				Plugin.FixVariables();
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(FinalRank), "LevelChange")]
	public static class FinalRank_LevelChangePatch
	{
		[HarmonyPrefix]
		public static bool Prefix(FinalRank __instance)
		{
			if (!Plugin.IsCustomLevel)
			{
				return true;
			}
			if (__instance.targetLevelName == null)
			{
				return true;
			}
			Loaderscene.LoadedSceneName = __instance.targetLevelName;
			Loaderscene.Loadscene();
			return false;
		}
	}
	[HarmonyPatch(typeof(LevelNameFinder))]
	[HarmonyPatch("OnEnable")]
	public static class LevelNameFinder_Patch
	{
		private static void Postfix(LevelNameFinder __instance)
		{
			if (!Plugin.IsCustomLevel)
			{
				return;
			}
			string currentBundleFolderPath = Loaderscene.GetCurrentBundleFolderPath();
			if (string.IsNullOrEmpty(currentBundleFolderPath))
			{
				return;
			}
			string path = Path.Combine(currentBundleFolderPath, "info.txt");
			if (!File.Exists(path))
			{
				__instance.txt2.text = "Failed to load Level name!";
				return;
			}
			try
			{
				string[] array = File.ReadAllLines(path);
				if (array.Length >= 2)
				{
					string text = array[1];
					__instance.txt2.text = text;
				}
				else
				{
					__instance.txt2.text = "Failed to load Level name!";
				}
			}
			catch
			{
				__instance.txt2.text = "Failed to load Level name!";
			}
		}
	}
	[BepInPlugin("doomahreal.ultrakill.levelloader", "DoomahLevelLoader", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private AssetBundle terminal;

		private Shader loadedShader;

		public static bool IsCustomLevel;

		private static Plugin _instance;

		public static Plugin Instance => _instance;

		public static async Task foldershitAsync()
		{
			await Loaderscene.RecreateUnpackedLevelsFolder(Loaderscene.GetUnpackedLevelsPath());
		}

		public static string getConfigPath()
		{
			string[] array = new string[1];
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			array[0] = configPath + directorySeparatorChar + "EnvyLevels";
			return Path.Combine(array);
		}

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"If you see this, dont panick! because everything is fine :)");
			terminal = Loader.LoadTerminal();
			_instance = this;
			new Harmony("doomahreal.ultrakill.levelloader").PatchAll();
			if (!Directory.Exists(getConfigPath()))
			{
				Directory.CreateDirectory(getConfigPath());
			}
			SceneManager.sceneLoaded += OnSceneLoaded;
			SceneManager.sceneUnloaded += OnSceneUnloaded;
			Loaderscene.Setup();
			Loaderscene.ExtractSceneName();
		}

		private async void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			SceneManager.sceneUnloaded -= OnSceneUnloaded;
			await foldershitAsync();
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (ShaderManager.shaderDictionary.Count <= 0)
			{
				((MonoBehaviour)this).StartCoroutine(ShaderManager.LoadShadersAsync());
			}
			_ = SceneHelper.CurrentScene == "uk_construct";
			if (SceneHelper.CurrentScene == "Main Menu")
			{
				ShaderManager.CreateShaderDictionary();
				foldershitAsync();
				InstantiateEnvyScreen();
			}
			if (((Scene)(ref scene)).name == Loaderscene.LoadedSceneName)
			{
				Scene activeScene = SceneManager.GetActiveScene();
				SceneHelper.CurrentScene = ((Scene)(ref activeScene)).name;
				Camera main = Camera.main;
				IsCustomLevel = true;
				if ((Object)(object)main != (Object)null)
				{
					main.clearFlags = (CameraClearFlags)1;
				}
				else
				{
					Debug.LogWarning((object)"Main camera not found in the scene.");
				}
				((MonoBehaviour)this).StartCoroutine(ShaderManager.ApplyShadersAsyncContinuously());
			}
			else
			{
				IsCustomLevel = false;
			}
		}

		private void OnSceneUnloaded(Scene scene)
		{
			_ = SceneHelper.CurrentScene == "uk_construct";
			if (SceneHelper.CurrentScene == "Main Menu")
			{
				InstantiateEnvyScreen();
				foldershitAsync();
				ShaderManager.CreateShaderDictionary();
			}
		}

		public static void FixVariables()
		{
			MonoSingleton<MapVarManager>.Instance.ReloadMapVars();
		}

		private void Update()
		{
		}

		private void InstantiateEnvyScreen()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = terminal.LoadAsset<GameObject>("assets/envyscreen.prefab");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"EnvyScreen prefab not found in the terminal bundle.");
				return;
			}
			GameObject val2 = GameObject.Find("/Canvas/Main Menu (1)");
			if (!((Object)(object)val2 == (Object)null))
			{
				GameObject obj = Object.Instantiate<GameObject>(val);
				obj.transform.SetParent(val2.transform, false);
				obj.transform.localPosition = Vector3.zero;
				obj.transform.localScale = new Vector3(1.75f, 1.75f, 1.75f);
			}
		}

		private void InstantiateTerminal()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_001b: Invalid comparison between Unknown and I4
			//IL_0056: 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)
			AsyncOperationHandle<Shader> val = Addressables.LoadAssetAsync<Shader>((object)"Assets/Shaders/Main/ULTRAKILL-vertexlit.shader");
			val.WaitForCompletion();
			if ((int)val.Status != 1)
			{
				return;
			}
			loadedShader = val.Result;
			GameObject val2 = terminal.LoadAsset<GameObject>("assets/levelloadterminal.prefab");
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			GameObject val3 = Object.Instantiate<GameObject>(val2, new Vector3(-36f, -10f, 335f), Quaternion.Euler(0f, 0f, 180f));
			Transform val4 = val3.transform.Find("Cube");
			if ((Object)(object)val4 == (Object)null)
			{
				return;
			}
			GameObject[] targets = (GameObject[])(object)new GameObject[1] { ((Component)val4).gameObject };
			Renderer component = ((Component)val4).GetComponent<Renderer>();
			if (!((Object)(object)component == (Object)null))
			{
				Material[] materials = component.materials;
				Material[] array = materials;
				for (int i = 0; i < array.Length; i++)
				{
					array[i].shader = loadedShader;
				}
				component.materials = materials;
				OutdoorsChecker val5 = val3.AddComponent<OutdoorsChecker>();
				if ((Object)(object)val5 != (Object)null)
				{
					val5.targets = targets;
					val5.nonSolid = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Material))]
	internal static class MaterialPatches
	{
		public static void Process(Material material)
		{
			if (!((Object)(object)material.shader == (Object)null) && ShaderManager.shaderDictionary.TryGetValue(((Object)material.shader).name, out var value) && !((Object)(object)material.shader == (Object)(object)value))
			{
				material.shader = value;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		public static void CtorPatch1(Material __instance)
		{
			Process(__instance);
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		public static void CtorPatch2(Material __instance)
		{
			Process(__instance);
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		public static void CtorPatch3(Material __instance)
		{
			Process(__instance);
		}
	}
}
namespace DoomahLevelLoader.UnityComponents
{
	public class AddressableReplacer : MonoBehaviour
	{
		public string targetAddress;

		public bool oneTime = true;

		public bool moveToParent = true;

		public bool destroyThis = true;

		public bool IsBoss;

		public string BossName;

		public bool IsSanded;

		public bool IsPuppet;

		public bool IsRadient;

		public float RadienceTier;

		public float DamageTier;

		public float SpeedTier;

		public float HealthTier;

		internal EnemyIdentifier eid;

		private bool _activated;

		private void OnEnable()
		{
			Activate();
		}

		public void Activate()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (oneTime && _activated)
			{
				return;
			}
			_activated = true;
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)targetAddress).WaitForCompletion();
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogWarning((object)("Tried to load asset at address " + targetAddress + ", but it does not exist"));
				((Behaviour)this).enabled = false;
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)this).transform.position, ((Component)this).transform.rotation, ((Component)this).transform);
			eid = val2.GetComponent<EnemyIdentifier>();
			if ((Object)(object)eid == (Object)null && val2.transform.childCount > 0)
			{
				eid = ((Component)val2.transform.GetChild(0)).GetComponent<EnemyIdentifier>();
			}
			if (moveToParent)
			{
				val2.transform.SetParent(((Component)this).transform.parent, true);
			}
			PostInstantiate(val2);
			if ((Object)(object)eid != (Object)null && IsBoss)
			{
				BossHealthBar val3 = ((Component)eid).gameObject.AddComponent<BossHealthBar>();
				if (!string.IsNullOrEmpty(BossName))
				{
					val3.bossName = BossName;
				}
			}
			if ((Object)(object)eid != (Object)null && IsSanded)
			{
				eid.Sandify(false);
			}
			if ((Object)(object)eid != (Object)null && IsPuppet)
			{
				eid.PuppetSpawn();
				eid.puppet = true;
			}
			if ((Object)(object)eid != (Object)null && IsRadient)
			{
				eid.radianceTier = RadienceTier;
				eid.healthBuffModifier = HealthTier;
				eid.speedBuffModifier = SpeedTier;
				eid.damageBuffModifier = DamageTier;
				eid.BuffAll();
			}
			if (destroyThis)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				((Component)this).gameObject.SetActive(false);
			}
			((Behaviour)this).enabled = false;
		}

		protected virtual void PostInstantiate(GameObject instantiatedObject)
		{
		}
	}
	public class CheckpointReplacer : AddressableReplacer
	{
		protected override void PostInstantiate(GameObject instantiatedObject)
		{
			Debug.Log((object)"Replacing checkpoint");
			CheckPoint componentInParent = ((Component)this).GetComponentInParent<CheckPoint>();
			CheckPoint component = instantiatedObject.GetComponent<CheckPoint>();
			foreach (Collider item in from col in instantiatedObject.GetComponentsInChildren<Collider>()
				where col.isTrigger
				select col)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			Transform[] array = (from i in Enumerable.Range(0, instantiatedObject.transform.childCount)
				select instantiatedObject.transform.GetChild(i)).ToArray();
			foreach (Transform obj in array)
			{
				Debug.Log((object)((Object)obj).name);
				obj.SetParent(((Component)this).transform.parent, true);
			}
			componentInParent.graphic = component.graphic;
			componentInParent.activateEffect = component.activateEffect;
		}
	}
	public class ClashTriggerDisable : MonoBehaviour
	{
		private void OnTriggerEnter(Collider other)
		{
			if (((Component)other).gameObject.tag == "Player")
			{
				MonoSingleton<PlayerTracker>.Instance.ChangeToFPS();
			}
		}
	}
	public class ClashTriggerEnable : MonoBehaviour
	{
		private bool hasenabled;

		public bool OnlyOnce;

		private void OnTriggerEnter(Collider other)
		{
			if (((Component)other).gameObject.tag == "Player" && !hasenabled)
			{
				MonoSingleton<PlayerTracker>.Instance.ChangeToPlatformer();
				if (OnlyOnce)
				{
					hasenabled = true;
				}
			}
		}
	}
	public class FinalDoorFixer : MonoBehaviour
	{
		public bool oneTime = true;

		public bool moveToParent = true;

		public BoxCollider OpenTrigger;

		private FinalDoor FD;

		private GameObject instantiatedObject;

		private bool isOpened;

		private bool _activated;

		private void OnEnable()
		{
			Activate();
		}

		public void Activate()
		{
			//IL_001d: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (oneTime && _activated)
			{
				return;
			}
			_activated = true;
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"Assets/Prefabs/Levels/Special Rooms/FinalRoom.prefab").WaitForCompletion();
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogWarning((object)"Tried to load asset, but it does not exist");
				((Behaviour)this).enabled = false;
				return;
			}
			instantiatedObject = Object.Instantiate<GameObject>(val, ((Component)this).transform.position, ((Component)this).transform.rotation, ((Component)this).transform);
			if (moveToParent)
			{
				instantiatedObject.transform.SetParent(((Component)this).transform.parent, true);
			}
			Debug.Log((object)"FinalDoorFixer: Final door game object loaded successfully.");
			Transform obj = instantiatedObject.transform.Find("FinalDoor");
			FinalDoor val2 = ((obj != null) ? ((Component)obj).GetComponent<FinalDoor>() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				FD = val2;
				Debug.Log((object)"FinalDoorFixer: Final door component found successfully.");
			}
			else
			{
				Debug.LogWarning((object)"FinalDoorFixer: Final door component not found.");
			}
			PostInstantiate(instantiatedObject);
		}

		protected virtual void PostInstantiate(GameObject instantiatedObject)
		{
		}

		private void OnTriggerEnter(Collider other)
		{
			if (!isOpened && ((Component)other).CompareTag("Player") && (Object)(object)FD != (Object)null)
			{
				FD.Open();
				isOpened = true;
			}
		}
	}
	public class IdolAssigner : MonoBehaviour
	{
		public AddressableReplacer Target;

		public bool oneTime = true;

		public bool moveToParent = true;

		public bool destroyThis = true;

		private bool _activated;

		private void OnEnable()
		{
			Activate();
		}

		public void Activate()
		{
			//IL_001d: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (oneTime && _activated)
			{
				return;
			}
			_activated = true;
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"Assets/Prefabs/Enemies/Idol.prefab").WaitForCompletion();
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogWarning((object)"Tried to load asset, but it does not exist");
				((Behaviour)this).enabled = false;
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)this).transform.position, ((Component)this).transform.rotation, ((Component)this).transform);
			if (moveToParent)
			{
				val2.transform.SetParent(((Component)this).transform.parent, true);
			}
			Idol component = val2.GetComponent<Idol>();
			if ((Object)(object)component != (Object)null && (Object)(object)Target != (Object)null && (Object)(object)Target.eid != (Object)null)
			{
				component.overrideTarget = Target.eid;
			}
			PostInstantiate(val2);
			if (destroyThis)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				((Component)this).gameObject.SetActive(false);
			}
			((Behaviour)this).enabled = false;
		}

		protected virtual void PostInstantiate(GameObject instantiatedObject)
		{
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}