Decompiled source of DronemeldDevotionFix v1.0.6

DronemeldDevotionFix.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using IL.RoR2;
using IL.RoR2.CharacterAI;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour.HookGen;
using On;
using On.RoR2;
using On.RoR2.UI;
using R2API;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RiskyMod.Allies;
using RoR2;
using RoR2.CharacterAI;
using RoR2.UI;
using ThinkInvisible.Dronemeld;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("DronemeldDevotionFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f327b943a329cf4909947bf0a956fe63fdd240ce")]
[assembly: AssemblyProduct("DronemeldDevotionFix")]
[assembly: AssemblyTitle("DronemeldDevotionFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DronemeldDevotionFix
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.score.DronemeldDevotionFix", "DronemeldDevotionFix", "1.0.5")]
	public class DronemeldFixPlugin : BaseUnityPlugin
	{
		public delegate CharacterMaster orig_TryApply(IEnumerable<CharacterMaster> cm);

		public delegate CharacterMaster hook_TryApply(orig_TryApply orig, IEnumerable<CharacterMaster> cm);

		public delegate bool orig_IsDronemeldEnabledFor(string masterPrefabName);

		public delegate bool hook_IsDronemeldEnabledFor(orig_IsDronemeldEnabledFor orig, string masterPrefabName);

		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Rebuild <0>__AddLemurianInventory;

			public static ArtifactStateChangeDelegate <1>__RunArtifactManager_onArtifactEnabledGlobal;

			public static Manipulator <2>__LemurianEggController_SummonLemurian;

			public static Manipulator <3>__DevotionInventoryController_GenerateEliteBuff;

			public static Manipulator <4>__DevotionInventoryController_EvolveDevotedLumerian;

			public static hook_OnDevotedBodyDead <5>__DevotedLemurianController_OnDevotedBodyDead;

			public static Func<orig_TryApply, IEnumerable<CharacterMaster>, CharacterMaster> <6>__TryApply;

			public static Func<orig_IsDronemeldEnabledFor, string, bool> <7>__IsDronemeldEnabledFor;
		}

		public const string PluginGUID = "com.score.DronemeldDevotionFix";

		public const string PluginName = "DronemeldDevotionFix";

		public const string PluginVersion = "1.0.5";

		internal static ManualLogSource _logger;

		public static List<EquipmentIndex> lowLvl = new List<EquipmentIndex>();

		public static List<EquipmentIndex> highLvl = new List<EquipmentIndex>();

		public static List<EquipmentIndex> gigaChadLvl = new List<EquipmentIndex>();

		public static Dictionary<DevotedLemurianController, SortedList<int, int>> lemItemDict = new Dictionary<DevotedLemurianController, SortedList<int, int>>();

		public static DevotedLemurianController meldRef;

		public static bool rooInstalled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		public static bool riskyInstalled => Chainloader.PluginInfos.ContainsKey("com.RiskyLives.RiskyMod");

		public void Awake()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			_logger = ((BaseUnityPlugin)this).Logger;
			PluginConfig.myConfig = ((BaseUnityPlugin)this).Config;
			PluginConfig.ReadConfig();
			if (PluginConfig.enabled.Value)
			{
				object obj = <>O.<0>__AddLemurianInventory;
				if (obj == null)
				{
					hook_Rebuild val = AddLemurianInventory;
					<>O.<0>__AddLemurianInventory = val;
					obj = (object)val;
				}
				ScoreboardController.Rebuild += (hook_Rebuild)obj;
				object obj2 = <>O.<1>__RunArtifactManager_onArtifactEnabledGlobal;
				if (obj2 == null)
				{
					ArtifactStateChangeDelegate val2 = RunArtifactManager_onArtifactEnabledGlobal;
					<>O.<1>__RunArtifactManager_onArtifactEnabledGlobal = val2;
					obj2 = (object)val2;
				}
				RunArtifactManager.onArtifactEnabledGlobal += (ArtifactStateChangeDelegate)obj2;
				if (riskyInstalled)
				{
					DevotionInventoryController.GetOrCreateDevotionInventoryController += new hook_GetOrCreateDevotionInventoryController(DevotionInventoryController_GetOrCreateDevotionInventoryController);
				}
				object obj3 = <>O.<2>__LemurianEggController_SummonLemurian;
				if (obj3 == null)
				{
					Manipulator val3 = LemurianEggController_SummonLemurian;
					<>O.<2>__LemurianEggController_SummonLemurian = val3;
					obj3 = (object)val3;
				}
				LemurianEggController.SummonLemurian += (Manipulator)obj3;
				object obj4 = <>O.<3>__DevotionInventoryController_GenerateEliteBuff;
				if (obj4 == null)
				{
					Manipulator val4 = DevotionInventoryController_GenerateEliteBuff;
					<>O.<3>__DevotionInventoryController_GenerateEliteBuff = val4;
					obj4 = (object)val4;
				}
				DevotionInventoryController.GenerateEliteBuff += (Manipulator)obj4;
				object obj5 = <>O.<4>__DevotionInventoryController_EvolveDevotedLumerian;
				if (obj5 == null)
				{
					Manipulator val5 = DevotionInventoryController_EvolveDevotedLumerian;
					<>O.<4>__DevotionInventoryController_EvolveDevotedLumerian = val5;
					obj5 = (object)val5;
				}
				DevotionInventoryController.EvolveDevotedLumerian += (Manipulator)obj5;
				DevotionInventoryController.UpdateMinionInventory += new hook_UpdateMinionInventory(DevotionInventoryController_UpdateMinionInventory);
				object obj6 = <>O.<5>__DevotedLemurianController_OnDevotedBodyDead;
				if (obj6 == null)
				{
					hook_OnDevotedBodyDead val6 = DevotedLemurianController_OnDevotedBodyDead;
					<>O.<5>__DevotedLemurianController_OnDevotedBodyDead = val6;
					obj6 = (object)val6;
				}
				DevotedLemurianController.OnDevotedBodyDead += (hook_OnDevotedBodyDead)obj6;
				HookEndpointManager.Add<hook_TryApply>((MethodBase)typeof(DronemeldPlugin).GetMethod("TryApply", new Type[1] { typeof(IEnumerable<CharacterMaster>) }), (Delegate)new Func<orig_TryApply, IEnumerable<CharacterMaster>, CharacterMaster>(TryApply));
				HookEndpointManager.Add<hook_IsDronemeldEnabledFor>((MethodBase)typeof(DronemeldPlugin).GetMethod("IsDronemeldEnabledFor"), (Delegate)new Func<orig_IsDronemeldEnabledFor, string, bool>(IsDronemeldEnabledFor));
			}
		}

		private static bool IsDronemeldEnabledFor(orig_IsDronemeldEnabledFor orig, string masterPrefabName)
		{
			if (masterPrefabName == "DevotedLemurianMaster" || masterPrefabName == "DevotedLemurianBruiserMaster")
			{
				return true;
			}
			return orig(masterPrefabName);
		}

		private static CharacterMaster TryApply(orig_TryApply orig, IEnumerable<CharacterMaster> cm)
		{
			CharacterMaster val = orig(cm);
			meldRef = null;
			DevotedLemurianController val2 = default(DevotedLemurianController);
			if ((Object)(object)val != (Object)null && ((Component)val).TryGetComponent<DevotedLemurianController>(ref val2))
			{
				meldRef = val2;
				if (!lemItemDict.ContainsKey(meldRef))
				{
					lemItemDict.Add(meldRef, new SortedList<int, int>());
				}
			}
			return val;
		}

		[SystemInitializer(new Type[] { typeof(ItemCatalog) })]
		private static void HideLemItems()
		{
			ItemDef[] itemDefs = ItemCatalog.itemDefs;
			foreach (ItemDef val in itemDefs)
			{
				if (val.nameToken == "ITEM_BOOSTDAMAGE_NAME" || val.nameToken == "ITEM_BOOSTHP_NAME")
				{
					val.hidden = true;
				}
			}
		}

		private static void RunArtifactManager_onArtifactEnabledGlobal([NotNull] RunArtifactManager runArtifactManager, [NotNull] ArtifactDef artifactDef)
		{
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Invalid comparison between Unknown and I4
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)artifactDef != (Object)(object)Artifacts.Devotion)
			{
				return;
			}
			if (Chainloader.PluginInfos.TryGetValue("com.Nuxlar.DevotionInventoryDisplay", out var value) && value != null && (Object)(object)value.Instance != (Object)null)
			{
				Object.Destroy((Object)(object)value.Instance);
			}
			lowLvl = new List<EquipmentIndex>();
			highLvl = new List<EquipmentIndex>();
			gigaChadLvl = new List<EquipmentIndex>();
			lemItemDict = new Dictionary<DevotedLemurianController, SortedList<int, int>>();
			meldRef = null;
			foreach (EliteTierDef item in EliteAPI.GetCombatDirectorEliteTiers().ToList())
			{
				if (item == null || item.eliteTypes.Length == 0 || item.eliteTypes == null)
				{
					continue;
				}
				bool flag = false;
				bool flag2 = false;
				EliteDef[] eliteTypes = item.eliteTypes;
				foreach (EliteDef val in eliteTypes)
				{
					if ((Object)(object)val != (Object)null && !((Object)val).name.EndsWith("Honor"))
					{
						if ((Object)(object)val.eliteEquipmentDef == (Object)(object)Equipment.AffixPoison || (Object)(object)val.eliteEquipmentDef == (Object)(object)Equipment.AffixLunar)
						{
							flag = true;
							break;
						}
						if ((Object)(object)val.eliteEquipmentDef == (Object)(object)Equipment.AffixBlue)
						{
							flag2 = true;
							break;
						}
					}
				}
				if (!(flag2 || flag))
				{
					continue;
				}
				eliteTypes = item.eliteTypes;
				foreach (EliteDef val2 in eliteTypes)
				{
					if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.eliteEquipmentDef) || (int)val2.eliteEquipmentDef.equipmentIndex == -1 || !Object.op_Implicit((Object)(object)val2.eliteEquipmentDef.passiveBuffDef) || !val2.eliteEquipmentDef.passiveBuffDef.isElite)
					{
						continue;
					}
					EliteIndex eliteIndex;
					if (flag2)
					{
						if (PluginConfig.enableDebugging.Value)
						{
							ManualLogSource logger = _logger;
							eliteIndex = val2.eliteIndex;
							logger.LogInfo((object)("t1 " + ((object)(EliteIndex)(ref eliteIndex)).ToString() + " " + val2.eliteEquipmentDef.nameToken));
						}
						lowLvl.Add(val2.eliteEquipmentDef.equipmentIndex);
						highLvl.Add(val2.eliteEquipmentDef.equipmentIndex);
					}
					else if (flag)
					{
						if (PluginConfig.enableDebugging.Value)
						{
							ManualLogSource logger2 = _logger;
							eliteIndex = val2.eliteIndex;
							logger2.LogInfo((object)("t2 " + ((object)(EliteIndex)(ref eliteIndex)).ToString() + " " + val2.eliteEquipmentDef.nameToken));
						}
						highLvl.Add(val2.eliteEquipmentDef.equipmentIndex);
						gigaChadLvl.Add(val2.eliteEquipmentDef.equipmentIndex);
					}
				}
			}
			lowLvl = lowLvl.Distinct().ToList();
			highLvl = highLvl.Distinct().ToList();
			gigaChadLvl = gigaChadLvl.Distinct().ToList();
		}

		private static void AddLemurianInventory(orig_Rebuild orig, ScoreboardController self)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!Object.op_Implicit((Object)(object)RunArtifactManager.instance) || !RunArtifactManager.instance.IsArtifactEnabled(Artifacts.Devotion))
			{
				return;
			}
			List<CharacterMaster> list = new List<CharacterMaster>();
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				list.Add(instance.master);
			}
			CharacterMaster master = LocalUserManager.readOnlyLocalUsersList.First().cachedMasterController.master;
			if (Object.op_Implicit((Object)(object)master))
			{
				MinionGroup val = MinionGroup.FindGroup(((NetworkBehaviour)master).netId);
				if (val != null)
				{
					MinionOwnership[] members = val.members;
					foreach (MinionOwnership val2 in members)
					{
						if (!Object.op_Implicit((Object)(object)val2))
						{
							continue;
						}
						CharacterMaster component = ((Component)val2).GetComponent<CharacterMaster>();
						if (((Object)((Component)component).gameObject).name.StartsWith("DevotedLemurian"))
						{
							list.Add(component);
							if (!PluginConfig.showAllMinions.Value)
							{
								break;
							}
						}
					}
				}
			}
			self.SetStripCount(list.Count);
			for (int j = 0; j < list.Count; j++)
			{
				self.stripAllocator.elements[j].SetMaster(list[j]);
			}
		}

		private static void LemurianEggController_SummonLemurian(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[3]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdarg(i, 0),
				(Instruction i) => ILPatternMatchingExt.MatchCall<Component>(i, "get_gameObject"),
				(Instruction i) => ILPatternMatchingExt.MatchCall<Object>(i, "Destroy")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.Emit(OpCodes.Ldloc_1);
				val.Emit(OpCodes.Ldloc_2);
				val.Emit(OpCodes.Ldarga_S, (byte)1);
				val.Emit<PickupIndex>(OpCodes.Call, "get_itemIndex");
				val.EmitDelegate<Action<LemurianEggController, CharacterMaster, EffectData, int>>((Action<LemurianEggController, CharacterMaster, EffectData, int>)delegate(LemurianEggController self, CharacterMaster cm, EffectData ed, int idx)
				{
					if (!Object.op_Implicit((Object)(object)cm))
					{
						DevotionInventoryController orCreateDevotionInventoryController = DevotionInventoryController.GetOrCreateDevotionInventoryController(self.interactor);
						if (Object.op_Implicit((Object)(object)orCreateDevotionInventoryController))
						{
							if ((Object)(object)meldRef != (Object)null)
							{
								SortedList<int, int> sortedList = lemItemDict[meldRef];
								if (sortedList.ContainsKey(idx))
								{
									sortedList[idx]++;
								}
								else
								{
									sortedList.Add(idx, 1);
								}
							}
							if (PluginConfig.shareItems.Value)
							{
								orCreateDevotionInventoryController.GiveItem((ItemIndex)idx, 1);
							}
							else
							{
								DevotedLemurianController obj = meldRef;
								if (obj != null)
								{
									obj.LemurianInventory.GiveItem((ItemIndex)idx, 1);
								}
							}
							orCreateDevotionInventoryController.UpdateAllMinions(false);
							Util.PlaySound(self.sfxLocator.openSound, ((Component)self).gameObject);
							EffectManager.SpawnEffect(LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/LemurianEggHatching"), ed, true);
						}
					}
				});
			}
			else
			{
				_logger.LogError((object)"Sorry guy, ILHook failed for LemurianEggController::SummonLemurian");
			}
		}

		private DevotionInventoryController DevotionInventoryController_GetOrCreateDevotionInventoryController(orig_GetOrCreateDevotionInventoryController orig, Interactor summoner)
		{
			DevotionInventoryController val = orig.Invoke(summoner);
			if ((Object)(object)val != (Object)null && Object.op_Implicit((Object)(object)val._devotionMinionInventory))
			{
				Inventory devotionMinionInventory = val._devotionMinionInventory;
				if (devotionMinionInventory.GetItemCount(AllyItems.AllyMarkerItem) <= 0)
				{
					devotionMinionInventory.GiveItem(AllyItems.AllyMarkerItem, 1);
					devotionMinionInventory.GiveItem(AllyItems.AllyRegenItem, 40);
				}
			}
			return val;
		}

		private static void DevotionInventoryController_EvolveDevotedLumerian(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[2]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdstr(i, "shouldn't evolve!"),
				(Instruction i) => ILPatternMatchingExt.MatchCall<Debug>(i, "LogError")
			}))
			{
				val.Emit(OpCodes.Ldloc_0);
				val.EmitDelegate<Action<CharacterBody>>((Action<CharacterBody>)delegate(CharacterBody body)
				{
					//IL_0027: Unknown result type (might be due to invalid IL or missing references)
					if (PluginConfig.randomizeElites.Value)
					{
						List<EquipmentIndex> list = gigaChadLvl;
						int index = Random.Range(0, list.Count);
						body.inventory.SetEquipmentIndex(list[index]);
					}
				});
				val.RemoveRange(2);
			}
			else
			{
				_logger.LogError((object)"Sorry guy, ILHook failed for DevotionInventoryController::EvolveDevotedLumerian");
			}
		}

		private static void DevotionInventoryController_GenerateEliteBuff(ILContext ll)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			ILCursor val = new ILCursor(ll);
			ILLabel val3 = default(ILLabel);
			ILLabel val2 = default(ILLabel);
			if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[4]
			{
				(Instruction i) => ILPatternMatchingExt.MatchBrtrue(i, ref val3),
				(Instruction i) => ILPatternMatchingExt.MatchLdsfld<DevotionInventoryController>(i, "highLevelEliteBuffs"),
				(Instruction i) => ILPatternMatchingExt.MatchBr(i, ref val2),
				(Instruction i) => ILPatternMatchingExt.MatchLdsfld<DevotionInventoryController>(i, "lowLevelEliteBuffs")
			}))
			{
				val.RemoveRange(4);
				val.EmitDelegate<Func<bool, List<EquipmentIndex>>>((Func<bool, List<EquipmentIndex>>)((bool isLowLvl) => (!isLowLvl) ? highLvl : lowLvl));
			}
			else
			{
				_logger.LogError((object)"Sorry guy, ILHook failed for DevotionInventoryController::GenerateEliteBuff");
			}
		}

		private void DevotionInventoryController_UpdateMinionInventory(orig_UpdateMinionInventory orig, DevotionInventoryController self, DevotedLemurianController lemCtrl, bool shouldEvolve)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				orig.Invoke(self, lemCtrl, shouldEvolve);
				return;
			}
			int itemCount = lemCtrl.LemurianInventory.GetItemCount(DronemeldPlugin.stackItem);
			orig.Invoke(self, lemCtrl, shouldEvolve);
			if (itemCount > 0)
			{
				lemCtrl.LemurianInventory.GiveItem(DronemeldPlugin.stackItem, itemCount);
			}
			if (PluginConfig.disableFallDamage.Value)
			{
				CharacterBody lemurianBody = lemCtrl.LemurianBody;
				lemurianBody.bodyFlags = (BodyFlags)(lemurianBody.bodyFlags | 1);
			}
			lemCtrl._leashDistSq = PluginConfig.teleportDistance.Value * PluginConfig.teleportDistance.Value;
			if (PluginConfig.shareItems.Value || !lemItemDict.TryGetValue(lemCtrl, out var value))
			{
				return;
			}
			foreach (KeyValuePair<int, int> item in value)
			{
				lemCtrl.LemurianInventory.GiveItem((ItemIndex)item.Key, item.Value);
			}
		}

		private static void DevotedLemurianController_OnDevotedBodyDead(orig_OnDevotedBodyDead orig, DevotedLemurianController self)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected I4, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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)
			if (self._devotionInventoryController.HasItem(Items.ExtraLife))
			{
				orig.Invoke(self);
				return;
			}
			if (lemItemDict.TryGetValue(self, out var value))
			{
				if (PluginConfig.enableDebugging.Value)
				{
					_logger.LogInfo((object)"Found lem");
				}
				foreach (KeyValuePair<int, int> item in value)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef((ItemIndex)item.Key);
					if (!((Object)(object)itemDef != (Object)null))
					{
						continue;
					}
					PickupIndex val = PickupIndex.none;
					ItemTier tier = itemDef.tier;
					switch ((int)tier)
					{
					case 0:
						val = PickupCatalog.FindPickupIndex("ItemIndex.ScrapWhite");
						break;
					case 1:
						val = PickupCatalog.FindPickupIndex("ItemIndex.ScrapGreen");
						break;
					case 2:
						val = PickupCatalog.FindPickupIndex("ItemIndex.ScrapRed");
						break;
					case 4:
						val = PickupCatalog.FindPickupIndex("ItemIndex.ScrapYellow");
						break;
					}
					if (val != PickupIndex.none)
					{
						if (PluginConfig.enableDebugging.Value)
						{
							_logger.LogInfo((object)("Dropping item " + itemDef.nameToken));
						}
						PickupDropletController.CreatePickupDroplet(val, self.LemurianBody.corePosition, Vector2.op_Implicit(Random.insideUnitCircle * 15f));
						if (PluginConfig.shareItems.Value)
						{
							self._devotionInventoryController.RemoveItem((ItemIndex)item.Key, item.Value);
						}
					}
				}
				lemItemDict.Remove(self);
				meldRef = null;
			}
			else if (PluginConfig.enableDebugging.Value)
			{
				_logger.LogError((object)"Could not find target lem :(");
			}
			orig.Invoke(self);
		}
	}
	public static class PluginConfig
	{
		public static ConfigFile myConfig;

		public static ConfigEntry<bool> enabled;

		public static ConfigEntry<bool> randomizeElites;

		public static ConfigEntry<bool> allowT1Elites;

		public static ConfigEntry<bool> disableFallDamage;

		public static ConfigEntry<bool> showAllMinions;

		public static ConfigEntry<bool> shareItems;

		public static ConfigEntry<bool> enableDebugging;

		public static ConfigEntry<int> teleportDistance;

		public const string GENERAL = "01 - General";

		public const string EXPERIMENTAL = "02 - Experimental";

		internal static void ReadConfig()
		{
			InitROO();
			enabled = BindAndOptions("01 - General", "Enabled", defaultValue: true, "Set to false to disable all DronemeldDevotionFix changes. Does not affect the base Dronemeld plugin.", restartRequired: true);
			randomizeElites = BindAndOptions("01 - General", "Reroll Elite Elder Lemurians", defaultValue: true, "If true, fully evolved Elite Elder Lemurians will reroll to a new elite type after each boss is defeated.");
			disableFallDamage = BindAndOptions("01 - General", "Disable Fall Damage", defaultValue: true, "If true, prevents Lemurians from taking fall damage.");
			teleportDistance = BindAndOptions("01 - General", "Teleport Distance", 150, "Sets the max distance a Lemurian can be from their owner before teleporting.");
			showAllMinions = BindAndOptions("02 - Experimental", "Show All Minions on Scoreboard", defaultValue: false, "If true, the scoreboard will display all of the Lemurians and their inventories. Intended to be used with \"Share Lemurian Items\" set to false.");
			shareItems = BindAndOptions("02 - Experimental", "Share Lemurian Items", defaultValue: true, "If true, Lemurians will use items from every other Lemurian that you currently control. Items are still lost on death when their original owner dies. If false, Lemurians will only use items that have been given to them.");
			enableDebugging = BindAndOptions("02 - Experimental", "Enable Debugging", defaultValue: false, "For dev use, enables console debug messages. Keep this off.");
		}

		public static void InitROO()
		{
			if (DronemeldFixPlugin.rooInstalled)
			{
				Sprite val = LoadSprite();
				if ((Object)(object)val != (Object)null)
				{
					ModSettingsManager.SetModIcon(val);
				}
				ModSettingsManager.SetModDescription("Devotion Artifact but better.");
			}
		}

		public static Sprite LoadSprite()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_005b: 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)
			string path = Path.Combine(Assembly.GetExecutingAssembly().Location, "icon.png");
			if (File.Exists(path))
			{
				Texture2D val = new Texture2D(1, 1);
				ImageConversion.LoadImage(val, File.ReadAllBytes(path));
				if ((Object)(object)val != (Object)null)
				{
					Rect val2 = default(Rect);
					((Rect)(ref val2))..ctor(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height);
					return Sprite.Create(val, val2, new Vector2(((Rect)(ref val2)).width * 0.5f, ((Rect)(ref val2)).height * 0.5f));
				}
			}
			return null;
		}

		public static ConfigEntry<T> BindAndOptions<T>(string section, string name, T defaultValue, string description = "", bool restartRequired = false)
		{
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			if (restartRequired)
			{
				description += " (restart required)";
			}
			ConfigEntry<T> val = myConfig.Bind<T>(section, name, defaultValue, description);
			if (DronemeldFixPlugin.rooInstalled)
			{
				TryRegisterOption<T>(val, restartRequired);
			}
			return val;
		}

		public static ConfigEntry<float> BindAndOptionsSlider(string section, string name, float defaultValue, string description = "", float min = 0f, float max = 20f, bool restartRequired = false)
		{
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			description = description + " (Default: " + defaultValue + ")";
			if (restartRequired)
			{
				description += " (restart required)";
			}
			ConfigEntry<float> val = myConfig.Bind<float>(section, name, defaultValue, description);
			if (DronemeldFixPlugin.rooInstalled)
			{
				TryRegisterOptionSlider(val, min, max, restartRequired);
			}
			return val;
		}

		public static ConfigEntry<int> BindAndOptionsSlider(string section, string name, int defaultValue, string description = "", int min = 0, int max = 20, bool restartRequired = false)
		{
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			description = description + " (Default: " + defaultValue + ")";
			if (restartRequired)
			{
				description += " (restart required)";
			}
			ConfigEntry<int> val = myConfig.Bind<int>(section, name, defaultValue, description);
			if (DronemeldFixPlugin.rooInstalled)
			{
				TryRegisterOptionSlider(val, min, max, restartRequired);
			}
			return val;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static void TryRegisterOption<T>(ConfigEntry<T> entry, bool restartRequired)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			if (entry is ConfigEntry<string> val)
			{
				ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(val, restartRequired));
			}
			if (entry is ConfigEntry<float>)
			{
				ModSettingsManager.AddOption((BaseOption)new SliderOption(entry as ConfigEntry<float>, new SliderConfig
				{
					min = 0f,
					max = 20f,
					formatString = "{0:0.00}",
					restartRequired = restartRequired
				}));
			}
			if (entry is ConfigEntry<int>)
			{
				ModSettingsManager.AddOption((BaseOption)new IntSliderOption(entry as ConfigEntry<int>, restartRequired));
			}
			if (entry is ConfigEntry<bool>)
			{
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(entry as ConfigEntry<bool>, restartRequired));
			}
			if (entry is ConfigEntry<KeyboardShortcut>)
			{
				ModSettingsManager.AddOption((BaseOption)new KeyBindOption(entry as ConfigEntry<KeyboardShortcut>, restartRequired));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static void TryRegisterOptionSlider(ConfigEntry<int> entry, int min, int max, bool restartRequired)
		{
			//IL_0001: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(entry, new IntSliderConfig
			{
				min = min,
				max = max,
				formatString = "{0:0.00}",
				restartRequired = restartRequired
			}));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static void TryRegisterOptionSlider(ConfigEntry<float> entry, float min, float max, bool restartRequired)
		{
			//IL_0001: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new SliderOption(entry, new SliderConfig
			{
				min = min,
				max = max,
				formatString = "{0:0.00}",
				restartRequired = restartRequired
			}));
		}
	}
}