Decompiled source of MagmaCore v1.0.0

MagmaCore.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using HarmonyLib;
using MagmaCore;
using MagmaCore.Customs;
using MagmaCore.Datatypes;
using MagmaCore.Interfaces;
using MagmaCore.ItemLoaderExtensions;
using MagmaCore.Managers;
using MagmaCore.Utils;
using MelonLoader;
using Newtonsoft.Json.Linq;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "Magma Core", "1.0.0", "QuackAndCheese", null)]
[assembly: MelonGame("TheJaspel", "Backpack Hero")]
[assembly: AssemblyTitle("MagmaCore")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MagmaCore")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0fa678ca-6362-4782-b717-ddf5552b774d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MagmaCore
{
	public abstract class MagmaMod : MelonMod
	{
		private List<ulong> PreInstalledMods = new List<ulong>();

		private List<ModpackInfo> EnabledDependencies = new List<ModpackInfo>();

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

		public static LangaugeManager LangManager;

		public static string LoadedScene;

		public bool FirstLoad = true;

		public abstract string InternalModName { get; }

		public virtual List<ulong> Dependencies { get; private set; } = new List<ulong>();


		public sealed override void OnInitializeMelon()
		{
			MelonCoroutines.Start(WaitUntilModsLoaded());
			OnInitializeMagma();
		}

		public sealed override void OnApplicationStart()
		{
			MelonCoroutines.Start(SubscribeToDependencies());
			Callback<ItemInstalled_t>.Create((DispatchDelegate<ItemInstalled_t>)EnableDependency);
		}

		public sealed override void OnApplicationQuit()
		{
			UnsubscribeFromDependencies();
		}

		private IEnumerator WaitUntilModsLoaded()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ModLoader>() != (Object)null));
			yield return (object)new WaitUntil((Func<bool>)(() => ModLoader.main.dataReady));
			OnLoadedMods();
			if (Dependencies.Intersect(PreInstalledMods).Count() == Dependencies.Count())
			{
				OnEnabledAllDependencies();
			}
		}

		public sealed override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			LoadedScene = sceneName;
			if (sceneName == "MainMenu" && FirstLoad)
			{
				SetFields();
				OnFirstMainMenuLoad();
				FirstLoad = false;
			}
			OnPostSceneWasLoaded(buildIndex, sceneName);
		}

		private void SetFields()
		{
			LangManager = Object.FindObjectOfType<LangaugeManager>();
			LangTerms = LangManager.languageTerms;
		}

		public virtual void OnInitializeMagma()
		{
		}

		public virtual void OnLoadedMods()
		{
		}

		protected virtual void OnEnabledAllDependencies()
		{
		}

		public virtual void OnFirstMainMenuLoad()
		{
		}

		public virtual void OnPostSceneWasLoaded(int buildIndex, string sceneName)
		{
		}

		public T AddCustom<T>() where T : CustomBase, new()
		{
			return CustomBase.RegisterCustom(new T
			{
				ModID = InternalModName,
				ModName = ((MelonBase)this).Info.Name
			});
		}

		public T AddManager<T>() where T : MonoBehaviour, new()
		{
			T val = new T();
			Main.Managers.Add((MonoBehaviour)(object)val);
			return val;
		}

		public T AddItemLoaderExtension<T>() where T : ItemLoaderExtension, new()
		{
			T val = new T();
			ItemLoaderExtension.Extensions.Add(val);
			return val;
		}

		private IEnumerator SubscribeToDependencies()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => SteamManager.s_EverInitialized));
			if (!SteamManager.s_EverInitialized)
			{
				yield break;
			}
			PublishedFileId_t[] fileIDs = (PublishedFileId_t[])(object)new PublishedFileId_t[SteamUGC.GetNumSubscribedItems()];
			SteamUGC.GetSubscribedItems(fileIDs, SteamUGC.GetNumSubscribedItems());
			PublishedFileId_t[] array = fileIDs;
			for (int i = 0; i < array.Length; i++)
			{
				PublishedFileId_t ID = array[i];
				PreInstalledMods.Add(ID.m_PublishedFileId);
			}
			foreach (ulong ID2 in Dependencies)
			{
				if (!PreInstalledMods.Contains(ID2))
				{
					SteamUGC.SubscribeItem(new PublishedFileId_t(ID2));
				}
			}
		}

		private void UnsubscribeFromDependencies()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			foreach (ulong dependency in Dependencies)
			{
				if (!PreInstalledMods.Contains(dependency))
				{
					SteamUGC.UnsubscribeItem(new PublishedFileId_t(dependency));
				}
			}
		}

		private void EnableDependency(ItemInstalled_t pCallback)
		{
			//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)
			ulong publishedFileId = pCallback.m_nPublishedFileId.m_PublishedFileId;
			MelonCoroutines.Start(EnableMod(publishedFileId));
		}

		private IEnumerator EnableMod(ulong fileId)
		{
			yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ModLoader>() != (Object)null));
			yield return (object)new WaitUntil((Func<bool>)(() => ModLoader.main.dataReady));
			ModLoader.main.ReloadModpacks();
			ModMetaSave.SaveModData();
			if (!Dependencies.Contains(fileId))
			{
				yield break;
			}
			ModpackInfo mod = ModLoader.main.modpacks.FindAll((ModpackInfo x) => x.workshop != null).Find((ModpackInfo x) => x.workshop.fileId.m_PublishedFileId == fileId);
			if (mod != null)
			{
				if (!mod.loaded)
				{
					ModLoader.main.LoadModpack(mod);
				}
				yield return (object)new WaitUntil((Func<bool>)(() => mod.loaded));
				EnabledDependencies.Add(mod);
				if (EnabledDependencies.Count >= Dependencies.Count)
				{
					OnEnabledAllDependencies();
				}
			}
		}
	}
	public class Main : MagmaMod
	{
		public static readonly List<Character> Characters = new List<Character>();

		public static List<MonoBehaviour> Managers = new List<MonoBehaviour>();

		public static readonly int ExtraItemFunctionNum = 555;

		public override string InternalModName => "MagmaCore";

		public override void OnInitializeMagma()
		{
			AddItemLoaderExtension<ModItemTypeExtension>();
			AddManager<MagmaManager>();
		}

		public override void OnFirstMainMenuLoad()
		{
			foreach (CustomBase value in CustomBase.Customs.Values)
			{
				value.Convert();
			}
		}

		public override void OnPostSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (!(sceneName == "Game"))
			{
				return;
			}
			foreach (MonoBehaviour manager in Managers)
			{
				((Component)Object.FindObjectOfType<GameManager>()).gameObject.AddComponent(((object)manager).GetType());
			}
		}
	}
}
namespace MagmaCore.Utils
{
	public static class AssetUtils
	{
		public static AssetBundle QuickLoadAssetBundle(string assetBundleName)
		{
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), assetBundleName);
			return AssetBundle.LoadFromFile(text);
		}

		public static AssetBundle QuickLoadAssetBundle(string assetBundleName, string assetBundleLocation)
		{
			string text = Path.Combine(Path.GetDirectoryName(assetBundleLocation), assetBundleName);
			return AssetBundle.LoadFromFile(text);
		}
	}
	public static class CharacterUtils
	{
		public static void AddItemToPool(this Character character, ref Item2 item)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			item.validForCharacters.Add(character.characterName);
		}

		public static void AddItemToPool(this Character character, string itemName)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			ItemUtils.FindItem(itemName).validForCharacters.Add(character.characterName);
		}

		public static void AddItemToPool(this Character character, ModItemDefinition itemDef)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			ItemUtils.FindItem(itemDef).validForCharacters.Add(character.characterName);
		}

		public static CustomCharacter FindCustomCharacter(string characterName, string modName)
		{
			return CustomUtils.GetCastedCustom<CustomCharacter>(modName, characterName);
		}

		public static Character FindCharacter(string characterName, string modName)
		{
			return FindCustomCharacter(characterName, modName).CharacterInstance;
		}

		public static Character FindCharacter(string characterName)
		{
			return Resources.FindObjectsOfTypeAll<Character>().ToList().Find((Character x) => ((Object)x).name.ToLower() == characterName.ToLower());
		}
	}
	public static class CustomUtils
	{
		public static CustomBase GetCustom(string modID, string name)
		{
			CustomBase.CustomsByGUID.TryGetValue(new KeyValuePair<string, string>(modID, name), out var value);
			if (value == null)
			{
				CustomBase.CustomsByModName.TryGetValue(new KeyValuePair<string, string>(modID, name), out value);
				MelonLogger.Warning("Mod Name " + modID + ":" + name + " should not be used to find GDOs. Use Mod ID instead.");
			}
			return value;
		}

		public static CustomBase GetCustom(int id)
		{
			CustomBase.Customs.TryGetValue(id, out var value);
			return value;
		}

		public static CustomBase GetCustom<T>()
		{
			CustomBase.CustomsByType.TryGetValue(typeof(T), out var value);
			return value;
		}

		public static T GetCastedCustom<T>(string modID, string name) where T : CustomBase
		{
			return (T)GetCustom(modID, name);
		}

		public static List<T> GetCustomsOfType<T>() where T : CustomBase
		{
			return (from entry in CustomBase.Customs
				where entry.Value is T
				select entry.Value as T).ToList();
		}

		public static Dictionary<int, T> GetCustomsOfTypeWithID<T>() where T : CustomBase
		{
			return CustomBase.Customs.Where((KeyValuePair<int, CustomBase> entry) => entry.Value is T).ToDictionary((KeyValuePair<int, CustomBase> x) => x.Key, (KeyValuePair<int, CustomBase> x) => x.Value as T);
		}

		public static List<CustomBase> GetCustomsFromMod(string modID)
		{
			return (from entry in CustomBase.CustomsByGUID
				where entry.Key.Key == modID
				select entry.Value).ToList();
		}

		public static List<T> GetCustomsFromMod<T>(string modID) where T : CustomBase
		{
			return (from entry in CustomBase.CustomsByGUID
				where entry.Key.Key == modID && entry.Value is T
				select entry.Value).ToList() as List<T>;
		}
	}
	public static class GameObjectUtils
	{
		public static Component CopyComponent(Component original, GameObject destination)
		{
			Type type = ((object)original).GetType();
			Component val = destination.AddComponent(type);
			FieldInfo[] fields = type.GetFields();
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				fieldInfo.SetValue(val, fieldInfo.GetValue(original));
			}
			return val;
		}

		public static void CopyComponentValues<T>(T from, T to)
		{
			string text = JsonUtility.ToJson((object)from);
			JsonUtility.FromJsonOverwrite(text, (object)to);
		}

		public static T GetCopyOf<T>(this Component comp, T other) where T : Component
		{
			Type type = ((object)comp).GetType();
			if (type != ((object)other).GetType())
			{
				return default(T);
			}
			BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
			PropertyInfo[] properties = type.GetProperties(bindingAttr);
			PropertyInfo[] array = properties;
			foreach (PropertyInfo propertyInfo in array)
			{
				if (propertyInfo.CanWrite)
				{
					try
					{
						propertyInfo.SetValue(comp, propertyInfo.GetValue(other, null), null);
					}
					catch
					{
					}
				}
			}
			FieldInfo[] fields = type.GetFields(bindingAttr);
			FieldInfo[] array2 = fields;
			foreach (FieldInfo fieldInfo in array2)
			{
				fieldInfo.SetValue(comp, fieldInfo.GetValue(other));
			}
			return (T)(object)((comp is T) ? comp : null);
		}

		public static GameObject DuplicateOnto(this GameObject originalObject, GameObject objectToCopyOnto)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			Component[] components = originalObject.GetComponents<Component>();
			foreach (Component val in components)
			{
				objectToCopyOnto.AddComponent(((object)val).GetType()).GetCopyOf<Component>(val);
			}
			foreach (Transform item in originalObject.transform)
			{
				Transform val2 = item;
				Object.Instantiate<Transform>(val2).SetParent(objectToCopyOnto.transform);
			}
			objectToCopyOnto.tag = originalObject.tag;
			objectToCopyOnto.layer = originalObject.layer;
			return objectToCopyOnto;
		}
	}
	public static class ItemLoaderUtils
	{
		public static Item2 GetItem(JToken jtoken, Item2 item)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Invalid comparison between Unknown and I4
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			string text = "";
			if ((int)jtoken.Type == 8)
			{
				string text2 = "BPH###";
				text = text2 + (object)jtoken;
			}
			else if ((int)jtoken.Type == 1)
			{
				JObject val = (JObject)jtoken;
				if (!((JToken)val).HasValues)
				{
					return null;
				}
				if (((JContainer)val).Count > 1)
				{
					throw new SyntaxException("MODPACK:ITEM Definition in Create Effect cannot have more than one item inside object. Make seperate objects for each item inside the array.");
				}
				JProperty val2 = (JProperty)((JToken)(JObject)jtoken).First;
				if ((int)val[val2.Name].Type != 8)
				{
					throw new SyntaxException("MODPACK:ITEM Definition in Create Effect must be of type string");
				}
				string name = val2.Name;
				string text3 = "###";
				text = name + text3 + (object)val[val2.Name];
			}
			ModItemLoader.main.gameItemLookup.TryGetValue(text.ToLower(), out var value);
			if ((Object)(object)value == (Object)null)
			{
				ModLog.LogWarning(((Component)item).GetComponent<ModdedItem>().fromModpack.internalName, ((Object)item).name, "Could not find " + text + ", adding Placeholder to be resolved after loading. This is not an Error. ");
				return ModItemLoader.main.CreatePlaceholder(text, ((Component)item).gameObject).GetComponent<Item2>();
			}
			return value.GetComponent<Item2>();
		}

		public static void ResolvePlaceholders(ref List<Item2> itemList)
		{
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < itemList.Count; i++)
			{
				ModdedItem component = ((Component)itemList[i]).GetComponent<ModdedItem>();
				if (!((Object)(object)component != (Object)null) || component.placeholder == null || !(component.placeholder != ""))
				{
					continue;
				}
				bool flag = false;
				Item2 value = null;
				if (component.placeholder.ToLower().StartsWith("bph###"))
				{
					string text = component.placeholder.ToLower().Substring(3);
					flag = ModItemLoader.main.modItemLookup.TryGetValue((component.fromModpack.internalName + text).ToLower(), out value);
					foreach (ModpackInfo modpack in ModLoader.main.modpacks)
					{
						if (!flag)
						{
							flag = ModItemLoader.main.modItemLookup.TryGetValue((modpack.internalName + text).ToLower(), out value);
						}
					}
				}
				else
				{
					flag = ModItemLoader.main.modItemLookup.TryGetValue(component.placeholder.ToLower(), out value);
				}
				if (!flag)
				{
					throw new ParseException(((Object)component.thisObj).name + " will not work! " + component.placeholder.Split(new string[1] { "###" }, StringSplitOptions.None)[1] + " is not a valid item");
				}
				ModLog.Log(component.fromModpack.internalName, ((Object)component.thisObj).name, "Resolved " + ((Object)component.thisObj).name + " placeholder: " + ((Object)value).name);
				Object.Destroy((Object)(object)itemList[i]);
				itemList[i] = value;
			}
		}

		public static void ResolvePlaceholder(ref Item2 item)
		{
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			ModdedItem component = ((Component)item).GetComponent<ModdedItem>();
			if (!((Object)(object)component != (Object)null) || component.placeholder == null || !(component.placeholder != ""))
			{
				return;
			}
			bool flag = false;
			Item2 value = null;
			if (component.placeholder.ToLower().StartsWith("bph###"))
			{
				string text = component.placeholder.ToLower().Substring(3);
				flag = ModItemLoader.main.modItemLookup.TryGetValue((component.fromModpack.internalName + text).ToLower(), out value);
				foreach (ModpackInfo modpack in ModLoader.main.modpacks)
				{
					if (!flag)
					{
						flag = ModItemLoader.main.modItemLookup.TryGetValue((modpack.internalName + text).ToLower(), out value);
					}
				}
			}
			else
			{
				flag = ModItemLoader.main.modItemLookup.TryGetValue(component.placeholder.ToLower(), out value);
			}
			if (!flag)
			{
				throw new ParseException(((Object)component.thisObj).name + " will not work! " + component.placeholder.Split(new string[1] { "###" }, StringSplitOptions.None)[1] + " is not a valid item");
			}
			ModLog.Log(component.fromModpack.internalName, ((Object)component.thisObj).name, "Resolved " + ((Object)component.thisObj).name + " placeholder: " + ((Object)value).name);
			Object.Destroy((Object)(object)item);
			item = value;
		}
	}
	public static class ItemUtils
	{
		public static Dictionary<int, ItemType> CustomItemTypes = new Dictionary<int, ItemType>();

		public static Dictionary<KeyValuePair<string, string>, ItemType> CustomItemTypesByModName = new Dictionary<KeyValuePair<string, string>, ItemType>();

		public static Item2 FindItem(string itemName)
		{
			ModItemLoader.main.gameItemLookup.TryGetValue("bph###" + itemName.ToLower(), out var value);
			if ((Object)(object)value == (Object)null)
			{
				MelonLogger.Error("Could not find item " + itemName + ".");
			}
			else if ((Object)(object)value.GetComponent<Item2>() == (Object)null)
			{
				MelonLogger.Error("Could not find Item2 component on 'item' " + itemName + ".");
			}
			return value.GetComponent<Item2>();
		}

		public static Item2 FindItem(string itemName, string modpackName)
		{
			bool flag = ModpackUtils.GetModpackFromInternalName(modpackName) != null;
			ModItemLoader.main.modItemLookup.TryGetValue(modpackName.ToLower() + "###" + itemName.ToLower(), out var value);
			if ((Object)(object)value == (Object)null)
			{
				MelonLogger.Error("Could not find item " + itemName + ".");
			}
			if (!flag)
			{
				MelonLogger.Error("Could not find modpack " + modpackName + " when trying to load item " + itemName + ".");
			}
			return value;
		}

		public static Item2 FindItem(ModItemDefinition itemDef)
		{
			return FindItem(itemDef.itemName, itemDef.internalModpackName);
		}

		public static ItemType RegisterItemType(string name, MelonInfoAttribute modInfo)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0052: 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)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			int int32HashCode = StringUtils.GetInt32HashCode(modInfo.Name + ":" + name);
			ItemType val = (ItemType)int32HashCode;
			CustomItemTypes.Add(int32HashCode, val);
			CustomItemTypesByModName.Add(new KeyValuePair<string, string>(modInfo.Name, name), val);
			TranslationUtils.CreateTranslation("english", int32HashCode.ToString(), name);
			return val;
		}

		public static ItemType RegisterItemType(string name, string modName)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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)
			int int32HashCode = StringUtils.GetInt32HashCode(modName + ":" + name);
			ItemType val = (ItemType)int32HashCode;
			CustomItemTypes.Add(int32HashCode, val);
			CustomItemTypesByModName.Add(new KeyValuePair<string, string>(modName, name), val);
			TranslationUtils.CreateTranslation("english", int32HashCode.ToString(), name);
			return val;
		}

		public static Item2 FindItemInInventory(Item2 itemToFind)
		{
			return Object.FindObjectsOfType<Item2>().ToList().Find((Item2 x) => Item2.GetDisplayName(((Object)x).name) == Item2.GetDisplayName(((Object)itemToFind).name) && !x.destroyed);
		}

		public static List<Item2> FindItemsInInventory(Item2 itemToFind)
		{
			return Object.FindObjectsOfType<Item2>().ToList().FindAll((Item2 x) => Item2.GetDisplayName(((Object)x).name) == Item2.GetDisplayName(((Object)itemToFind).name) && !x.destroyed);
		}
	}
	public static class ModpackUtils
	{
		public static bool CanRun = (Object)(object)Object.FindObjectOfType<ModLoader>() != (Object)null;

		public static ModpackInfo GetModpackFromInternalName(string internalModpackName)
		{
			ModpackInfo val = ModLoader.main.modpacks.Find((ModpackInfo x) => x.internalName.ToLower() == internalModpackName.ToLower());
			if (val == null)
			{
				MelonLogger.Warning("Could not find modpack with the internal name \"" + internalModpackName + "\"");
			}
			return val;
		}

		public static ModpackInfo GetModpackFromDisplayName(string displayModpackName)
		{
			ModpackInfo val = ModLoader.main.modpacks.Find((ModpackInfo x) => x.displayName.ToLower() == displayModpackName.ToLower());
			if (val == null)
			{
				MelonLogger.Warning("Could not find modpack with the display name \"" + displayModpackName + "\"");
			}
			return val;
		}
	}
	public static class StringUtils
	{
		private static SHA1 hash = new SHA1CryptoServiceProvider();

		public static int GetInt32HashCode(string strText)
		{
			if (string.IsNullOrEmpty(strText))
			{
				return 0;
			}
			byte[] bytes = Encoding.Unicode.GetBytes(strText);
			byte[] value = hash.ComputeHash(bytes);
			uint num = BitConverter.ToUInt32(value, 0);
			uint num2 = BitConverter.ToUInt32(value, 8);
			uint num3 = BitConverter.ToUInt32(value, 16);
			uint num4 = num ^ num2 ^ num3;
			return BitConverter.ToInt32(BitConverter.GetBytes(uint.MaxValue - num4), 0);
		}
	}
	public static class TranslationUtils
	{
		public static void CreateTranslation(string language, string key, string value)
		{
			key = key.ToLower().Trim();
			language = language.ToLower().Trim();
			if (!ModLoader.main.languageTerms.ContainsKey(language))
			{
				ModLoader.main.languageTerms.Add(language, new Dictionary<string, string>());
				MelonLogger.Error("Language not found: " + language + ". Language has been created.");
			}
			if (!ModLoader.main.languageTerms[language].ContainsKey(key))
			{
				ModLoader.main.languageTerms[language].Add(key, value);
			}
			foreach (KeyValuePair<string, Dictionary<string, string>> languageTerm in ModLoader.main.languageTerms)
			{
				if (!languageTerm.Value.ContainsKey(key))
				{
					ModLoader.main.languageTerms[languageTerm.Key].Add(key, value);
				}
			}
		}

		public static KeyValuePair<string, string> GetOrCreateTranslation(string language, string key, string value)
		{
			CreateTranslation(language, key, value);
			return new KeyValuePair<string, string>(key, value);
		}
	}
}
namespace MagmaCore.Patches
{
	[HarmonyPatch(typeof(Player), "SpawnObjects")]
	internal class AddStartingObjectsPatch
	{
		private static bool Prefix()
		{
			foreach (CustomCharacter item in CustomUtils.GetCustomsOfType<CustomCharacter>())
			{
				if (item.startingItems == null)
				{
					return true;
				}
				item.CharacterInstance.startingObjects.Clear();
				foreach (ModItemDefinition startingItem in item.startingItems)
				{
					Item2 val = null;
					val = ((startingItem.internalModpackName != null) ? ItemUtils.FindItem(startingItem) : ItemUtils.FindItem(startingItem.itemName));
					if ((Object)(object)val != (Object)null)
					{
						item.CharacterInstance.startingObjects.Add(((Component)val).gameObject);
					}
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "Awake")]
	internal class AddCharactersPatch
	{
		private static bool Prefix(ref Player __instance)
		{
			List<Character> list = new List<Character>();
			foreach (CustomCharacter item in CustomUtils.GetCustomsOfType<CustomCharacter>())
			{
				list.Add(item.CharacterInstance);
			}
			__instance.characterProperties.AddRange(list);
			return true;
		}
	}
	[HarmonyPatch(typeof(ContextMenuManager), "Command")]
	internal class ContextMenuTypePatch
	{
		private static void Postfix(ref ContextMenuManager __instance, Type type, List<Cost> costs, PlayerAnimation playerAnimation)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			((Component)__instance.selectedItem).GetComponent<IExtraItemFunction>().Event((MonoBehaviour)(object)__instance, (Enum)(object)type);
		}
	}
	[HarmonyPatch(typeof(SaveManager), "Load")]
	internal class FixBagSpritesPatch
	{
		private class PatchedEnumerator : IEnumerable
		{
			public IEnumerator enumerator;

			public Action postfixAction;

			IEnumerator IEnumerable.GetEnumerator()
			{
				return GetEnumerator();
			}

			public IEnumerator GetEnumerator()
			{
				while (enumerator.MoveNext())
				{
					yield return enumerator.Current;
				}
				postfixAction();
			}
		}

		private static void Postfix(ref IEnumerator __result)
		{
			Action postfixAction = delegate
			{
				((MonoBehaviour)MagmaManager.main).StartCoroutine(MagmaManager.main.FixBagCoroutine());
			};
			PatchedEnumerator patchedEnumerator = new PatchedEnumerator
			{
				enumerator = __result,
				postfixAction = postfixAction
			};
			__result = patchedEnumerator.GetEnumerator();
		}
	}
	[HarmonyPatch(typeof(ModItemLoader), "LoadItemFromFile")]
	internal class LoadModItemPatch
	{
		private static void Postfix(ref GameObject __result, ref ModItemLoader __instance, ModpackInfo modpack, string path)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			GameObject itemGameObject = __result;
			string text = Path.GetDirectoryName(path) + "/";
			string text2;
			try
			{
				text2 = File.ReadAllText(path);
			}
			catch (Exception ex)
			{
				throw new LoadingException(path, ex);
			}
			JObject jobject;
			try
			{
				jobject = JObject.Parse(text2);
			}
			catch (Exception ex2)
			{
				throw new ParseException(path, ex2);
			}
			ModdedItem component = itemGameObject.GetComponent<ModdedItem>();
			Item2 component2 = itemGameObject.GetComponent<Item2>();
			SpriteRenderer component3 = itemGameObject.GetComponent<SpriteRenderer>();
			string text3 = "";
			string internalName = modpack.internalName;
			foreach (ItemLoaderExtension extension in ItemLoaderExtension.Extensions)
			{
				extension?.Extension(ref itemGameObject, ref __instance, jobject);
			}
		}
	}
	[HarmonyPatch(typeof(Singleton), "SetCharacterFromNumber")]
	internal class SetCharacterFromNumberPatch
	{
		private static bool Prefix(ref Singleton __instance)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			if (Singleton.Instance.characterNumber < 0 || Singleton.Instance.characterNumber > Resources.FindObjectsOfTypeAll<Character>().Length)
			{
				Singleton.Instance.characterNumber = 0;
			}
			if (__instance.characterNumber == 0)
			{
				__instance.character = (CharacterName)1;
			}
			if (__instance.characterNumber == 1)
			{
				__instance.character = (CharacterName)3;
			}
			if (__instance.characterNumber == 2)
			{
				__instance.character = (CharacterName)4;
			}
			if (__instance.characterNumber == 3)
			{
				__instance.character = (CharacterName)2;
			}
			if (__instance.characterNumber == 4)
			{
				__instance.character = (CharacterName)5;
			}
			if (CustomUtils.GetCustomsOfTypeWithID<CustomCharacter>() == null)
			{
				MelonLogger.Warning("No custom characters detected.");
				return false;
			}
			foreach (KeyValuePair<int, CustomCharacter> item in CustomUtils.GetCustomsOfTypeWithID<CustomCharacter>())
			{
				int num = Resources.FindObjectsOfTypeAll<Character>().Length - CustomUtils.GetCustomsOfType<CustomCharacter>().Count;
				MelonLogger.Msg((object)(Resources.FindObjectsOfTypeAll<Character>().Length - CustomUtils.GetCustomsOfType<CustomCharacter>().Count));
				if (__instance.characterNumber == CustomUtils.GetCustomsOfTypeWithID<CustomCharacter>().Values.ToList().IndexOf(item.Value) + num)
				{
					MelonLogger.Warning("Custom char detected: " + item.Value.characterName);
					__instance.character = (CharacterName)item.Key;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Singleton), "SetNumberFromCharacter")]
	internal class SetNumberFromCharacterPatch
	{
		private static void Postfix(ref Singleton __instance, CharacterName name)
		{
			//IL_002b: 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)
			foreach (KeyValuePair<int, CustomCharacter> item in CustomUtils.GetCustomsOfTypeWithID<CustomCharacter>())
			{
				int num = Resources.FindObjectsOfTypeAll<Character>().Length - CustomUtils.GetCustomsOfType<CustomCharacter>().Count;
				if (name == item.Value.CharacterInstance.characterName)
				{
					MelonLogger.Warning("Custom char detected 2: " + item.Value.characterName);
					__instance.characterNumber = CustomUtils.GetCustomsOfTypeWithID<CustomCharacter>().Values.ToList().IndexOf(item.Value) + num;
				}
			}
		}
	}
}
namespace MagmaCore.ItemLoaderExtensions
{
	public class ModItemTypeExtension : ItemLoaderExtension
	{
		public override void Extension(ref GameObject itemGameObject, ref ModItemLoader __instance, JObject jobject)
		{
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Invalid comparison between Unknown and I4
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0091: 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_00a2: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Invalid comparison between Unknown and I4
			//IL_008a: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			Item2 component = itemGameObject.GetComponent<Item2>();
			if (ModUtils.IsNullEmpty(jobject["mod_item_types"]))
			{
				return;
			}
			foreach (JToken item3 in (IEnumerable<JToken>)jobject["mod_item_types"])
			{
				if ((int)item3.Type != 1)
				{
					continue;
				}
				JObject val = (JObject)item3;
				if (!((JToken)val).HasValues)
				{
					break;
				}
				if (((JContainer)val).Count > 1)
				{
					throw new SyntaxException("MODPACK:MOD ITEM TYPE Definitions cannot have more than one type inside object. Make seperate objects for each type inside the array.");
				}
				JProperty val2 = (JProperty)((JToken)(JObject)item3).First;
				if ((int)val[val2.Name].Type != 8)
				{
					throw new SyntaxException("MODPACK:MOD ITEM TYPE Definitions must be of type string");
				}
				string name = val2.Name;
				string text = ((object)val[val2.Name])?.ToString();
				try
				{
					if (!ItemUtils.CustomItemTypesByModName.ContainsKey(new KeyValuePair<string, string>(name, text)))
					{
						ItemType item = ItemUtils.RegisterItemType(text, name);
						component.itemType.Add(item);
					}
					else
					{
						ItemType item2 = ItemUtils.CustomItemTypesByModName[new KeyValuePair<string, string>(name, text)];
						component.itemType.Add(item2);
					}
				}
				catch (Exception ex)
				{
					throw new SyntaxException(text, ex);
				}
			}
		}
	}
}
namespace MagmaCore.Interfaces
{
	public interface IExtraItemFunction
	{
		void Event(MonoBehaviour sender, Enum enumType);
	}
}
namespace MagmaCore.Datatypes
{
	public struct ModItemDefinition
	{
		public string internalModpackName;

		public string itemName;
	}
}
namespace MagmaCore.Managers
{
	public class MagmaManager : MonoBehaviour
	{
		public static MagmaManager main;

		public void Awake()
		{
			main = this;
		}

		public void OnDestroy()
		{
			if ((Object)(object)main == (Object)(object)this)
			{
				main = null;
			}
		}

		public IEnumerator FixBagCoroutine()
		{
			yield return (object)new WaitForEndOfFrame();
			yield return (object)new WaitForFixedUpdate();
			ModularBackpack.SetAllBackpackSprites();
			Object.FindObjectOfType<LevelUpManager>().ResizeAllBackpacks();
		}
	}
}
namespace MagmaCore.Customs
{
	public abstract class CustomBase
	{
		public static Dictionary<int, CustomBase> Customs = new Dictionary<int, CustomBase>();

		public static Dictionary<KeyValuePair<string, string>, CustomBase> CustomsByModName = new Dictionary<KeyValuePair<string, string>, CustomBase>();

		public static Dictionary<KeyValuePair<string, string>, CustomBase> CustomsByGUID = new Dictionary<KeyValuePair<string, string>, CustomBase>();

		public static Dictionary<Type, CustomBase> CustomsByType = new Dictionary<Type, CustomBase>();

		public Type ConvertedCustom;

		public string ModID = "";

		public string ModName = "";

		public virtual int ID { get; internal set; }

		public abstract string UniqueNameID { get; }

		public abstract void Convert();

		public static T RegisterCustom<T>(T custom) where T : CustomBase
		{
			if (custom.ID == 0)
			{
				custom.ID = custom.GetHash();
			}
			if (Customs.ContainsKey(custom.ID))
			{
				MelonLogger.Error($"Error while registering custom \"{custom.ModID}:{custom.UniqueNameID}\". (Clashing with : {Customs[custom.ID]})");
				return null;
			}
			Customs.Add(custom.ID, custom);
			CustomsByType.Add(custom.GetType(), custom);
			CustomsByGUID.Add(new KeyValuePair<string, string>(custom.ModID, custom.UniqueNameID), custom);
			CustomsByModName.Add(new KeyValuePair<string, string>(custom.ModName, custom.UniqueNameID), custom);
			MelonLogger.Msg(custom.ModName + "," + custom.UniqueNameID);
			return custom;
		}

		public int GetHash()
		{
			return StringUtils.GetInt32HashCode(ModID + ":" + UniqueNameID);
		}
	}
	public abstract class CustomCharacter : CustomBase
	{
		public Character CharacterInstance;

		public virtual string characterName { get; protected set; }

		public virtual string characterDescription { get; protected set; }

		public virtual string mapCharacterHoverText { get; protected set; }

		public virtual int startingHealth { get; protected set; } = 40;


		public virtual int defaultEnergyPerTurn { get; protected set; } = 3;


		public virtual Sprite portraitSprite { get; protected set; }

		public virtual List<ModItemDefinition> startingItems { get; protected set; }

		public virtual List<GameObject> startingObjectsForLimitedItemGet { get; protected set; }

		public virtual List<RuntimeAnimatorController> skins { get; protected set; }

		public virtual List<float> characterSelectorSizeRatio { get; protected set; }

		public virtual List<float> yAdjustment { get; protected set; }

		public virtual Sprite standardGridSprite { get; protected set; }

		public virtual Sprite[] itemBorderBackgroundSprites { get; protected set; }

		public virtual BackpackPieces backpackPieces { get; protected set; }

		public virtual Vector3[] decalPositions { get; protected set; }

		public virtual Sprite mapSprite { get; protected set; }

		public virtual List<Sprite> mapCharacterSprite { get; protected set; }

		public virtual Sprite footstepSprite { get; protected set; }

		public virtual Vector2 defaultBagSize { get; protected set; }

		public virtual Vector2 endingBagSize { get; protected set; }

		public virtual Vector2 endingBagSizeDemo { get; protected set; }

		public virtual List<LevelUp> levelUps { get; protected set; }

		public virtual List<Type> buttonTypes { get; protected set; }

		public virtual List<string> itemBlacklist { get; protected set; }

		public virtual List<string> itemWhitelist { get; protected set; }

		public virtual bool blacklistItemsAllowedForOneCharacter { get; protected set; } = true;


		public virtual List<string> itemWhitelistUsingCharacter { get; protected set; }

		public override void Convert()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			Character val = Resources.FindObjectsOfTypeAll<Character>().ToList().Find((Character x) => (int)x.characterName == 1);
			Character val2 = Object.Instantiate<Character>(val);
			if ((Object)(object)standardGridSprite != (Object)null)
			{
				val2.standardGridSprite = standardGridSprite;
			}
			if (itemBorderBackgroundSprites != null)
			{
				val2.itemBorderBackgroundSprites = itemBorderBackgroundSprites;
			}
			if ((Object)(object)portraitSprite != (Object)null)
			{
				val2.portraitSprite = portraitSprite;
			}
			if (characterName != null)
			{
				val2.characterName = (CharacterName)GetHash();
			}
			if (characterName != null)
			{
				((Object)val2).name = characterName;
			}
			if (startingHealth != 0)
			{
				val2.startingHealth = startingHealth;
			}
			if (defaultEnergyPerTurn != 0)
			{
				val2.defaultEnergyPerTurn = defaultEnergyPerTurn;
			}
			if (startingObjectsForLimitedItemGet != null)
			{
				val2.startingObjectsForLimitedItemGet = startingObjectsForLimitedItemGet;
			}
			if (skins != null)
			{
				val2.animatorControllers = skins;
			}
			if (characterSelectorSizeRatio != null)
			{
				val2.characterSelectorSizeRatio = characterSelectorSizeRatio;
			}
			if (yAdjustment != null)
			{
				val2.yAdjustment = yAdjustment;
			}
			if (backpackPieces != null)
			{
				val2.backpackPieces = backpackPieces;
			}
			if (decalPositions != null)
			{
				val2.decalPositions = decalPositions;
			}
			if ((Object)(object)mapSprite != (Object)null)
			{
				val2.mapSprite = mapSprite;
			}
			if (mapCharacterSprite != null)
			{
				val2.mapCharacterSprite = mapCharacterSprite;
			}
			if ((Object)(object)footstepSprite != (Object)null)
			{
				val2.footstepSprite = footstepSprite;
			}
			if (defaultBagSize != Vector2.zero)
			{
				val2.defaultBagSize = defaultBagSize;
			}
			if (endingBagSize != Vector2.zero)
			{
				val2.endingBagSize = endingBagSize;
			}
			if (endingBagSizeDemo != Vector2.zero)
			{
				val2.endingBagSizeDemo = endingBagSizeDemo;
			}
			if (levelUps != null)
			{
				val2.levelUps = levelUps;
			}
			if (buttonTypes != null)
			{
				val2.buttonTypes = buttonTypes;
			}
			CharacterInstance = val2;
			CreateTranslations();
			CreateUIElements();
			CreateItemBlacklist();
			Modify(ref CharacterInstance);
		}

		private void CreateUIElements()
		{
			NewCharacterSelector val = Resources.FindObjectsOfTypeAll<NewCharacterSelector>()[0];
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Msg("The character selector is null!");
				return;
			}
			Transform val2 = ((Component)val).transform.Find("Character Select Master/Character Select/Character Selection List/Character Icon");
			GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject);
			val3.transform.parent = ((Component)val).transform.Find("Character Select Master/Character Select/Character Selection List");
			Image component = ((Component)val3.transform.Find("GameObject")).GetComponent<Image>();
			if (mapCharacterSprite != null)
			{
				component.sprite = mapCharacterSprite[0];
			}
			Button component2 = val3.GetComponent<Button>();
			object value = AccessTools.Field(typeof(UnityEventBase), "m_PersistentCalls").GetValue(component2.onClick);
			MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("PersistentCallGroup"), "RegisterObjectPersistentListener", new Type[5]
			{
				typeof(int),
				typeof(Object),
				typeof(Type),
				typeof(Object),
				typeof(string)
			}, (Type[])null);
			methodInfo.Invoke(value, new object[5]
			{
				0,
				val,
				typeof(NewCharacterSelector),
				CharacterInstance,
				"ChooseCharacter"
			});
		}

		private void CreateTranslations()
		{
			string key = "map" + GetHash();
			if (mapCharacterHoverText != null)
			{
				TranslationUtils.CreateTranslation("english", key, mapCharacterHoverText);
			}
			else
			{
				TranslationUtils.CreateTranslation("english", key, MagmaMod.LangTerms["mappurse"]);
			}
			if (characterName != null)
			{
				CharacterInstance.characterNameKey = GetHash().ToString();
				TranslationUtils.CreateTranslation("english", CharacterInstance.characterNameKey, characterName);
			}
			if (characterDescription != null)
			{
				CharacterInstance.characterDescriptionKey = GetHash() + "d";
				TranslationUtils.CreateTranslation("english", CharacterInstance.characterDescriptionKey, characterDescription);
			}
		}

		private void CreateItemBlacklist()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			Item2[] array = Resources.FindObjectsOfTypeAll<Item2>();
			foreach (Item2 val in array)
			{
				List<string> list = new List<string>();
				bool flag = false;
				bool flag2 = false;
				foreach (CharacterName validForCharacter in val.validForCharacters)
				{
					CharacterName current = validForCharacter;
					list.Add(((object)(CharacterName)(ref current)).ToString());
				}
				if (blacklistItemsAllowedForOneCharacter)
				{
					flag = val.validForCharacters.Count <= 1;
				}
				if (itemWhitelistUsingCharacter != null && list.Intersect(itemWhitelistUsingCharacter).Any())
				{
					flag = false;
				}
				if (itemBlacklist != null && itemBlacklist.Contains(val.displayName))
				{
					flag2 = true;
				}
				if (itemWhitelist != null && itemWhitelist.Contains(val.displayName))
				{
					flag2 = false;
				}
				if (!(flag2 || flag))
				{
					val.validForCharacters.Add(CharacterInstance.characterName);
				}
			}
		}

		public virtual void Modify(ref Character characterInstance)
		{
		}
	}
	public abstract class CustomDungeonEvent : CustomBase
	{
		public DungeonEvent Instance;

		public abstract GameObject prefabToCopyOnto { get; }

		public virtual Vector2 caveIn { get; protected set; }

		public virtual string mapTextOverrideKey { get; protected set; } = "";


		public virtual bool passable { get; protected set; } = true;


		public virtual DungeonEventType dungeonEventType { get; protected set; }

		public virtual List<GameObject> itemsToSpawn { get; protected set; } = new List<GameObject>();


		public virtual GameObject exitPrefab { get; protected set; }

		public virtual Sprite iconSprite { get; protected set; }

		public virtual Sprite[] sprites { get; protected set; }

		public virtual List<GameObject> particles { get; protected set; } = new List<GameObject>();


		public virtual GameObject destroyParticles { get; protected set; }

		public virtual int turnsToExpire { get; protected set; } = -1;


		public virtual List<EventProperty> eventProperties { get; protected set; }

		public virtual int doorNumber { get; protected set; }

		public override void Convert()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			DungeonEvent component = ((Component)Resources.FindObjectsOfTypeAll<DungeonEvent>().ToList().Find((DungeonEvent x) => ((Object)((Component)x).gameObject).name == "Random Event")).gameObject.GetComponent<DungeonEvent>();
			DungeonEvent copyOf = ((Component)(object)prefabToCopyOnto.AddComponent<DungeonEvent>()).GetCopyOf<DungeonEvent>(component);
			((Component)(object)prefabToCopyOnto.AddComponent<SpriteRenderer>()).GetCopyOf<SpriteRenderer>(((Component)component).gameObject.GetComponent<SpriteRenderer>());
			Object.Instantiate<Transform>(((Component)component).gameObject.GetComponentInChildren<TextMeshPro>(true).transform).SetParent(prefabToCopyOnto.transform);
			((Object)((Component)copyOf).gameObject).name = UniqueNameID;
			_ = caveIn;
			if (true)
			{
				copyOf.caveIn = caveIn;
			}
			if (mapTextOverrideKey != "")
			{
				copyOf.mapTextOverrideKey = mapTextOverrideKey;
			}
			copyOf.passable = passable;
			copyOf.itemsToSpawn = itemsToSpawn;
			if ((Object)(object)exitPrefab != (Object)null)
			{
				copyOf.exitPrefab = exitPrefab;
			}
			if ((Object)(object)iconSprite != (Object)null)
			{
				((Component)copyOf).GetComponent<SpriteRenderer>().sprite = iconSprite;
			}
			if (sprites != null)
			{
				copyOf.sprites = sprites;
			}
			if (particles != null)
			{
				copyOf.particles = particles;
			}
			if ((Object)(object)destroyParticles != (Object)null)
			{
				copyOf.destroyParticles = destroyParticles;
			}
			copyOf.turnsToExpire = turnsToExpire;
			if (eventProperties != null)
			{
				copyOf.eventProperties = eventProperties;
			}
			copyOf.doorNumber = doorNumber;
			((Component)copyOf).gameObject.tag = ((Component)component).gameObject.tag;
		}
	}
	public abstract class CustomDungeonEventSpawn : CustomBase
	{
		public DungeonEventSpawn EventInstance;

		public virtual List<DungeonLevel> dungeonLevels { get; protected set; } = Resources.FindObjectsOfTypeAll<DungeonLevel>().ToList();


		public virtual List<Floor> floors { get; protected set; } = new List<Floor>
		{
			(Floor)2,
			(Floor)3
		};


		public virtual List<Type> disablingRunProperties { get; protected set; } = new List<Type>();


		public virtual bool ignoreOnLastFloor { get; protected set; } = false;


		public virtual Vector2 num { get; protected set; } = Vector2.one;


		public virtual List<GameObject> prefabList { get; protected set; } = new List<GameObject>();


		public virtual bool repeatLoopsOnly { get; protected set; } = false;


		public virtual List<Type> requiredRunProperties { get; protected set; } = new List<Type>();


		public virtual List<MetaProgressCondition> storyModeConditions { get; protected set; } = new List<MetaProgressCondition>();


		public virtual bool storyModeOnly { get; protected set; } = false;


		public virtual Type type { get; protected set; } = (Type)1;


		public virtual List<CharacterName> validForCharacters { get; private set; } = new List<CharacterName>();


		public override void Convert()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0035: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			EventInstance = new DungeonEventSpawn();
			EventInstance.disablingRunProperties = disablingRunProperties;
			EventInstance.ignoreOnLastFloor = ignoreOnLastFloor;
			EventInstance.num = num;
			EventInstance.prefabList = prefabList;
			EventInstance.repeatLoopsOnly = repeatLoopsOnly;
			EventInstance.requiredRunProperties = requiredRunProperties;
			EventInstance.storyModeConditions = storyModeConditions;
			EventInstance.storyModeOnly = storyModeOnly;
			EventInstance.type = type;
			EventInstance.validForCharacters = validForCharacters;
			foreach (DungeonLevel dungeonLevel in dungeonLevels)
			{
				foreach (Floor floor in floors)
				{
					DungeonEventsToSpawn val = dungeonLevel.itemsToSpawnOnMap.Find((DungeonEventsToSpawn x) => x.floor == floor);
					if (val == null)
					{
						val = new DungeonEventsToSpawn
						{
							floor = floor
						};
						dungeonLevel.itemsToSpawnOnMap.Add(val);
					}
					val.itemsToSpawnOnMap.Add(EventInstance);
				}
			}
		}
	}
	public abstract class CustomEvent : CustomBase
	{
		public EventEncounter2 Instance;

		public virtual List<Type> disablingRunProperties { get; protected set; }

		public virtual List<GameObject> eventType { get; protected set; }

		public virtual List<Floor> floor { get; protected set; }

		public virtual List<Type> requiredRunProperties { get; protected set; }

		public virtual List<MetaProgressCondition> storyModeConditions { get; protected set; }

		public override void Convert()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			EventEncounter2 val = new EventEncounter2();
			val.disablingRunProperties = disablingRunProperties;
			val.eventType = eventType;
			val.floor = floor;
			val.requiredRunProperties = requiredRunProperties;
			val.storyModeConditions = storyModeConditions;
			Instance = val;
		}
	}
	public abstract class CustomSkin : CustomBase
	{
		public struct Skin
		{
			public List<AnimatorOverridePair> animationOverrides;
		}

		public struct AnimatorOverridePair
		{
			public string originalClipName;

			public AnimationClip overrideClip;
		}

		private enum OriginalClips
		{
			Attack,
			Hurt,
			Run,
			Die,
			UseItem,
			ReadMap,
			Win,
			Block,
			AttackOverhead,
			WalkAway,
			FireArrow,
			SearchPack,
			Command
		}

		public AnimatorOverrideController SkinInstance;

		public virtual Skin skin { get; private set; }

		public virtual List<Character> characters { get; private set; }

		public override void Convert()
		{
			SkinInstance = CreateAnimationOverrideController();
			if (characters != null && characters.Count != 0)
			{
				foreach (Character character in characters)
				{
					character.animatorControllers.Add((RuntimeAnimatorController)(object)SkinInstance);
				}
			}
			Modify(ref SkinInstance);
		}

		public virtual void Modify(ref AnimatorOverrideController skinInstance)
		{
		}

		private AnimatorOverrideController CreateAnimationOverrideController()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			RuntimeAnimatorController val = Resources.FindObjectsOfTypeAll<RuntimeAnimatorController>().ToList().Find((RuntimeAnimatorController x) => ((Object)x).name == "Player Controller");
			AnimatorOverrideController val2 = new AnimatorOverrideController(val);
			val2.runtimeAnimatorController = val;
			IList<KeyValuePair<AnimationClip, AnimationClip>> list = new List<KeyValuePair<AnimationClip, AnimationClip>>();
			for (int i = 0; i < skin.animationOverrides.Count; i++)
			{
				AnimatorOverridePair animatorOverridePair = skin.animationOverrides[i];
				for (int j = 0; j < val2.clips.Length; j++)
				{
					AnimationClip originalClip = val2.clips[j].originalClip;
					if (((Object)originalClip).name == animatorOverridePair.originalClipName)
					{
						if (animatorOverridePair.overrideClip.length < originalClip.length && originalClip.events != null)
						{
							MelonLogger.Error($"[{ModName}] The length of clip '{((Object)animatorOverridePair.overrideClip).name}' ({animatorOverridePair.overrideClip.length}) is less than the length of the original clip `{((Object)originalClip).name}` ({originalClip.length}). This will cause the animation events of this animation to not load properly.");
						}
						animatorOverridePair.overrideClip.events = originalClip.events;
						list.Add(new KeyValuePair<AnimationClip, AnimationClip>(originalClip, animatorOverridePair.overrideClip));
					}
				}
			}
			val2.ApplyOverrides(list);
			return val2;
		}
	}
	public abstract class ItemLoaderExtension
	{
		public static List<ItemLoaderExtension> Extensions = new List<ItemLoaderExtension>();

		public virtual void Extension(ref GameObject itemGameObject, ref ModItemLoader __instance, JObject jobject)
		{
		}
	}
}