Decompiled source of LemurTeam v0.2.15

LemurTeam.dll

Decompiled 6 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using EntityStates;
using EntityStates.BeetleQueenMonster;
using EntityStates.ClayBoss;
using EntityStates.GrandParentBoss;
using EntityStates.Gup;
using EntityStates.RoboBallBoss.Weapon;
using EntityStates.VoidInfestor;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProperSave;
using ProperSave.Data;
using ProperSave.SaveData;
using R2API;
using R2API.Networking;
using R2API.Networking.Interfaces;
using RiskOfOptions;
using RiskOfOptions.Components.Options;
using RiskOfOptions.Components.Panel;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.CharacterAI;
using RoR2.ContentManagement;
using RoR2.ExpansionManagement;
using RoR2.Navigation;
using RoR2.Networking;
using RoR2.Orbs;
using RoR2.Projectile;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 LemurTeam
{
	internal static class AspectRules
	{
		[HarmonyPatch(typeof(DevotionInventoryController), "GenerateEliteBuff")]
		private static class NativeAspect
		{
			private static bool Prefix(CharacterBody body, DevotedLemurianController devotedCntroller, bool isLowLevel)
			{
				if (!Followers.IsDevoted(body))
				{
					return true;
				}
				LemurProgress lemurProgress = LemurProgress.For(devotedCntroller);
				lemurProgress.Data.NativeAspect = null;
				lemurProgress.UpdateNativeAspect(body, isLowLevel, reroll: true);
				return false;
			}
		}

		private static ConfigEntry<int> maximum;

		private static readonly Dictionary<string, ConfigEntry<bool>> Enabled = new Dictionary<string, ConfigEntry<bool>>();

		internal static int Revision { get; private set; }

		internal static int Maximum => maximum?.Value ?? 1;

		internal static void Configure(ConfigFile config)
		{
			((ResourceAvailability)(ref EliteCatalog.availability)).CallWhenAvailable((Action)delegate
			{
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Expected O, but got Unknown
				//IL_00f0: Expected O, but got Unknown
				EliteDef[] array = (from elite in ((IEnumerable<EliteIndex>)EliteCatalog.eliteList).Select((Func<EliteIndex, EliteDef>)EliteCatalog.GetEliteDef)
					where Object.op_Implicit((Object)(object)elite) && (int)elite.devotionLevel != 0 && Object.op_Implicit((Object)(object)elite.eliteEquipmentDef) && Object.op_Implicit((Object)(object)elite.eliteEquipmentDef.passiveBuffDef)
					group elite by ((Object)elite.eliteEquipmentDef.passiveBuffDef).name into @group
					select @group.First()).ToArray();
				int total = array.Length;
				if (total != 0)
				{
					config.SaveOnConfigSet = false;
					Settings.Migrate(config, new ConfigDefinition("Companions", "Maximum per Lemurian"), new ConfigDefinition("Companions", "Aspects per companion"), (string value) => (!(value == "-1")) ? value : total.ToString(CultureInfo.InvariantCulture));
					maximum = Settings.Bind(config, "Companions", "Aspects per companion", total, "1 keeps only the stock aspect. Each step adds one possible extra aspect.", "1 оставляет только штатный аспект. Каждое следующее значение разрешает ещё один аспект.", (ConfigEntry<int> c) => (BaseOption)new IntSliderOption(c, new IntSliderConfig
					{
						min = 1,
						max = total
					}), null, null, "Аспектов на питомца", (AcceptableValueBase)((total == 1) ? ((object)new AcceptableValueList<int>(new int[1] { 1 })) : ((object)new AcceptableValueRange<int>(1, total))));
					maximum.SettingChanged += delegate
					{
						Revision++;
					};
					Plugin.Log($"Found {array.Length} devotion aspects in the catalog.");
					Language val = Language.FindLanguageByName("RU");
					if (val != Language.currentLanguage && val != null)
					{
						val.LoadStrings();
					}
					EliteDef[] array2 = array;
					foreach (EliteDef val2 in array2)
					{
						BuffDef passiveBuffDef = val2.eliteEquipmentDef.passiveBuffDef;
						string english = AspectName(val2.modifierToken, "en", ((Object)passiveBuffDef).name);
						string russianKey = AspectName(val2.modifierToken, "RU", "Аспект " + (Array.IndexOf(array, val2) + 1));
						Enabled[((Object)passiveBuffDef).name] = Settings.Bind(config, "Companions", "Allow " + ((Object)passiveBuffDef).name, value: true, "Allow the " + english + " aspect for allied Lemurians.", "Разрешить этот аспект союзным лемурам.", (ConfigEntry<bool> c) => (BaseOption)new CheckBoxOption(c, new CheckBoxConfig
						{
							name = english
						}), null, null, russianKey);
						Enabled[((Object)passiveBuffDef).name].SettingChanged += delegate
						{
							Revision++;
						};
					}
					if (val != Language.currentLanguage && val != null)
					{
						val.UnloadStrings();
					}
					config.SaveOnConfigSet = true;
					config.Save();
				}
			});
		}

		private static string AspectName(string token, string language, string fallback)
		{
			if (string.IsNullOrEmpty(token))
			{
				return fallback;
			}
			string text = Language.GetString(token, language);
			if (!string.IsNullOrEmpty(text) && !(text == token))
			{
				return text.Replace("{0}", "").Trim();
			}
			return fallback;
		}

		internal static bool Allows(BuffDef buff)
		{
			if (Object.op_Implicit((Object)(object)buff))
			{
				return IsEnabled(((Object)buff).name);
			}
			return false;
		}

		internal static bool IsEnabled(string name)
		{
			if (Enabled.TryGetValue(name, out var value))
			{
				return value.Value;
			}
			return true;
		}

		internal static EquipmentDef[] Eligible(DevotionEvolutionLevel? level = null)
		{
			return (from elite in ((IEnumerable<EliteIndex>)EliteCatalog.eliteList).Select((Func<EliteIndex, EliteDef>)EliteCatalog.GetEliteDef)
				where Object.op_Implicit((Object)(object)elite) && (int)elite.devotionLevel != 0 && ((int)level.GetValueOrDefault() != 1 || elite.devotionLevel == level.Value) && elite.IsAvailable() && Object.op_Implicit((Object)(object)elite.eliteEquipmentDef) && Allows(elite.eliteEquipmentDef.passiveBuffDef)
				select elite.eliteEquipmentDef).Distinct().ToArray();
		}
	}
	internal sealed class AuraVisibility : MonoBehaviour
	{
		[HarmonyPatch(typeof(NetworkedBodyAttachment), "OnAttachedBodyObjectAssigned")]
		private static class AttachedAura
		{
			private static void Postfix(NetworkedBodyAttachment __instance)
			{
				if (Object.op_Implicit((Object)(object)__instance.attachedBody))
				{
					string text = ((Object)((Component)__instance).gameObject).name;
					if (text.EndsWith("(Clone)", StringComparison.Ordinal))
					{
						text = text.Substring(0, text.Length - "(Clone)".Length);
					}
					if (AttachedAuras.Contains(text) && !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<AuraVisibility>()))
					{
						((Component)__instance).gameObject.AddComponent<AuraVisibility>().owner = __instance.attachedBody;
					}
				}
			}
		}

		[HarmonyPatch(typeof(FireAuraController), "FixedUpdate")]
		private static class FireAura
		{
			private static void Postfix(FireAuraController __instance)
			{
				if (Object.op_Implicit((Object)(object)__instance.owner) && !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<AuraVisibility>()))
				{
					CharacterBody component = __instance.owner.GetComponent<CharacterBody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						((Component)__instance).gameObject.AddComponent<AuraVisibility>().owner = component;
					}
				}
			}
		}

		private static readonly HashSet<string> AttachedAuras = new HashSet<string>(StringComparer.Ordinal) { "AffixHauntedWard", "AffixEarthBodyAttachment", "AffixBeadWard", "IcicleAura", "CausticPheromonesAura", "GoldenGooseAura" };

		private readonly List<Renderer> hiddenRenderers = new List<Renderer>();

		private CharacterBody owner;

		private bool hidden;

		private void LateUpdate()
		{
			bool flag = Plugin.HideAllyEffects.Value && Followers.IsAlliedMob(owner);
			if (hidden == flag)
			{
				return;
			}
			if (flag)
			{
				Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val in componentsInChildren)
				{
					if (!val.forceRenderingOff)
					{
						val.forceRenderingOff = true;
						hiddenRenderers.Add(val);
					}
				}
				hidden = true;
			}
			else
			{
				RestoreRenderers();
			}
		}

		private void OnDisable()
		{
			RestoreRenderers();
		}

		private void RestoreRenderers()
		{
			foreach (Renderer hiddenRenderer in hiddenRenderers)
			{
				if (Object.op_Implicit((Object)(object)hiddenRenderer))
				{
					hiddenRenderer.forceRenderingOff = false;
				}
			}
			hiddenRenderers.Clear();
			hidden = false;
		}
	}
	internal sealed class BossEgg : MonoBehaviour
	{
		[HarmonyPatch(typeof(InteractableSpawnCard), "Spawn")]
		private static class RareEgg
		{
			private static void Prefix(InteractableSpawnCard __instance, out GameObject __state)
			{
				__state = null;
				if (NetworkServer.active && Object.op_Implicit((Object)(object)Prefab) && Plugin.BossLimit.Value != 0 && __instance == stageEggCard && !spawnedThisStage && stageRng != null && !(stageRng.nextNormalizedFloat >= 0.1f))
				{
					__state = ((SpawnCard)__instance).prefab;
					((SpawnCard)__instance).prefab = Prefab;
				}
			}

			private static void Postfix(ref SpawnResult result, GameObject __state)
			{
				if (Object.op_Implicit((Object)(object)__state) && result.success)
				{
					spawnedThisStage = true;
				}
			}

			private static void Finalizer(InteractableSpawnCard __instance, GameObject __state)
			{
				if (Object.op_Implicit((Object)(object)__state))
				{
					((SpawnCard)__instance).prefab = __state;
				}
			}
		}

		[HarmonyPatch]
		private static class BlockAdditionalSummons
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.Method(typeof(SummonEggs), "SummonEgg", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(DeployMinions), "SummonMinion", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(Offspring), "SpawnPods", (Type[])null, (Type[])null);
			}

			private static bool Prefix(EntityState __instance)
			{
				CharacterBody component = ((Component)__instance.outer).GetComponent<CharacterBody>();
				if (Followers.IsDevoted(component))
				{
					return !IsBossBody(((Component)component).gameObject);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(GrandParentSunController), "SearchForTargets")]
		private static class FriendlySun
		{
			private static void Postfix(GrandParentSunController __instance, List<HurtBox> dest)
			{
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				GameObject ownerObject = ((Component)__instance).GetComponent<GenericOwnership>().ownerObject;
				CharacterBody val = (Object.op_Implicit((Object)(object)ownerObject) ? ownerObject.GetComponent<CharacterBody>() : null);
				if (Followers.IsDevoted(val) && IsBossBody(((Component)val).gameObject))
				{
					TeamMask enemies = TeamMask.GetEnemyTeams(val.teamComponent.teamIndex);
					dest.RemoveAll((HurtBox target) => Object.op_Implicit((Object)(object)target) && Object.op_Implicit((Object)(object)target.healthComponent) && Object.op_Implicit((Object)(object)target.healthComponent.body) && !((TeamMask)(ref enemies)).HasTeam(target.healthComponent.body.teamComponent.teamIndex));
				}
			}
		}

		[HarmonyPatch(typeof(Recover), "FireTethers")]
		private static class FriendlyTethers
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Expected O, but got Unknown
				List<CodeInstruction> list = instructions.ToList();
				FieldInfo allTeams = AccessTools.Field(typeof(TeamMask), "allButNeutral");
				CodeInstruction val = list.Single((CodeInstruction instruction) => CodeInstructionExtensions.LoadsField(instruction, allTeams, false));
				val.opcode = OpCodes.Ldarg_0;
				val.operand = null;
				list.Insert(list.IndexOf(val) + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(FriendlyTethers), "TargetTeams", (Type[])null, (Type[])null)));
				return list;
			}

			private static TeamMask TargetTeams(Recover state)
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				CharacterBody component = ((Component)((EntityState)state).outer).GetComponent<CharacterBody>();
				if (!Followers.IsDevoted(component) || !IsBossBody(((Component)component).gameObject))
				{
					return TeamMask.allButNeutral;
				}
				return TeamMask.GetEnemyTeams(component.teamComponent.teamIndex);
			}
		}

		[HarmonyPatch(typeof(PickupPickerController), "GetContextString")]
		private static class Context
		{
			private static void Postfix(PickupPickerController __instance, ref string __result)
			{
				if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<BossEgg>()))
				{
					__result = Settings.Text("Offer a boss item to the golden egg", "Поднести золотой предмет боссовому яйцу");
				}
			}
		}

		[HarmonyPatch(typeof(PickupPickerController), "SetOptionsFromInteractor")]
		private static class Options
		{
			private static bool Prefix(PickupPickerController __instance, Interactor activator)
			{
				BossEgg bossEgg = default(BossEgg);
				if (!NetworkServer.active || !((Component)__instance).TryGetComponent<BossEgg>(ref bossEgg))
				{
					return true;
				}
				bossEgg.ShowItems(__instance, ((Component)activator).GetComponent<CharacterBody>());
				return false;
			}
		}

		[HarmonyPatch(typeof(PickupPickerController), "SubmitChoice")]
		private static class EncodeChoice
		{
			private static void Prefix(PickupPickerController __instance, ref int choiceIndex)
			{
				if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<BossEgg>()) && (uint)choiceIndex < __instance.options.Length && __instance.options[choiceIndex].pickup.upgradeValue != 0)
				{
					choiceIndex |= int.MinValue;
				}
			}
		}

		[HarmonyPatch(typeof(PickupPickerController), "HandlePickupSelected")]
		private static class Selection
		{
			private static bool Prefix(PickupPickerController __instance, int choiceIndex)
			{
				BossEgg bossEgg = default(BossEgg);
				if (!NetworkServer.active || !((Component)__instance).TryGetComponent<BossEgg>(ref bossEgg))
				{
					return true;
				}
				bossEgg.Select(__instance, choiceIndex);
				return false;
			}
		}

		private static readonly Dictionary<string, string> Forms = new Dictionary<string, string>(StringComparer.Ordinal)
		{
			["BeetleGland"] = "BeetleQueen2Body",
			["Knurl"] = "TitanBody",
			["NovaOnLowHealth"] = "VagrantBody",
			["SiphonOnLowHealth"] = "ClayBossBody",
			["SprintWisp"] = "GravekeeperBody",
			["BleedOnHitAndExplode"] = "ImpBossBody",
			["FireballsOnHit"] = "MagmaWormBody",
			["LightningStrikeOnHit"] = "ElectricWormBody",
			["RoboBallBuddy"] = "RoboBallBossBody",
			["ParentEgg"] = "GrandParentBody",
			["TitanGoldDuringTP"] = "TitanGoldBody"
		};

		private static readonly HashSet<string> BossBodies = new HashSet<string>(Forms.Values, StringComparer.Ordinal);

		private static InteractableSpawnCard stageEggCard;

		private static Xoroshiro128Plus stageRng;

		private static bool spawnedThisStage;

		private CharacterMaster participant;

		private ItemIndex selectedItem = (ItemIndex)(-1);

		private CharacterMaster[] targets = Array.Empty<CharacterMaster>();

		private readonly OperationGate operation = new OperationGate();

		internal static GameObject Prefab { get; private set; }

		internal static GameObject CreatePrefab(GameObject source)
		{
			//IL_003d: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			Prefab = PrefabAPI.InstantiateClone(source, "LemurTeamBossEgg", false);
			Prefab.AddComponent<BossEgg>();
			SpecialTextures.Apply(Prefab, isEgg: true);
			Highlight componentInChildren = Prefab.GetComponentInChildren<Highlight>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				componentInChildren.highlightColor = (HighlightColor)3;
				componentInChildren.CustomColor = new Color(1f, 0.73f, 0.22f);
			}
			return Prefab;
		}

		internal static bool IsBossBody(GameObject prefab)
		{
			if (Object.op_Implicit((Object)(object)prefab))
			{
				return BossBodies.Contains(VisualEffects.PrefabName(prefab));
			}
			return false;
		}

		internal static bool UsesPetSlot(CharacterMaster master)
		{
			if (!Plugin.BossesUsePetSlots.Value)
			{
				return !IsBossBody(master.bodyPrefab);
			}
			return true;
		}

		private static GameObject FindForm(ItemIndex index)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			ItemDef itemDef = ItemCatalog.GetItemDef(index);
			if (!Object.op_Implicit((Object)(object)itemDef) || (int)itemDef.tier != 4 || !Forms.TryGetValue(((Object)itemDef).name, out var value))
			{
				return null;
			}
			return BodyCatalog.FindBodyPrefab(value);
		}

		internal static void Plan(InteractableSpawnCard card)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			stageEggCard = card;
			spawnedThisStage = false;
			stageRng = new Xoroshiro128Plus(Run.instance.seed ^ (ulong)Run.instance.stageClearCount ^ 0xB055E66);
		}

		internal static void EndPopulation()
		{
			stageEggCard = null;
			stageRng = null;
		}

		private static Option Option(PickupIndex index, uint target = 0u)
		{
			//IL_0002: 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_0022: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			Option result = new Option
			{
				available = true
			};
			UniquePickup pickup = default(UniquePickup);
			((UniquePickup)(ref pickup))..ctor(index);
			pickup.upgradeValue = (int)target;
			result.pickup = pickup;
			return result;
		}

		private void ShowItems(PickupPickerController picker, CharacterBody body)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			participant = (Object.op_Implicit((Object)(object)body) ? body.master : null);
			selectedItem = (ItemIndex)(-1);
			targets = Array.Empty<CharacterMaster>();
			picker.SetOptionsServer((Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.inventory)) ? (from item in body.inventory.itemAcquisitionOrder
				where Object.op_Implicit((Object)(object)FindForm(item)) && InteractionOperation.CanPay(body, item)
				select PickupCatalog.FindPickupIndex(item) into pickup
				where pickup != PickupIndex.none
				select Option(pickup)).ToArray() : Array.Empty<Option>());
		}

		private static bool Alive(CharacterMaster master)
		{
			CharacterBody val = (Object.op_Implicit((Object)(object)master) ? master.GetBody() : null);
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.healthComponent))
			{
				return val.healthComponent.alive;
			}
			return false;
		}

		private static CharacterMaster[] OccupiedSlots(CharacterMaster owner)
		{
			return (from minion in SharedInventory.Minions
				select ((Component)minion).GetComponent<CharacterMaster>() into master
				where (Object)(object)master.minionOwnership.ownerMaster == (Object)(object)owner && PetRules.OccupiesSlot(PetRegistry.State(master))
				select master).OrderBy(delegate(CharacterMaster master)
			{
				//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)
				NetworkInstanceId netId = ((NetworkBehaviour)master).netId;
				return ((NetworkInstanceId)(ref netId)).Value;
			}).ToArray();
		}

		private static bool HasBossRoom(CharacterMaster[] slots)
		{
			return PetRules.HasRoom(Plugin.BossLimit.Value, slots.Count((CharacterMaster master) => IsBossBody(master.bodyPrefab)), -1);
		}

		private static bool HasRoom(CharacterMaster[] slots)
		{
			if (HasBossRoom(slots))
			{
				if (Plugin.BossesUsePetSlots.Value)
				{
					return PetRules.HasRoom(Plugin.LemurLimit.Value, slots.Count(UsesPetSlot), 0);
				}
				return true;
			}
			return false;
		}

		private static IEnumerable<CharacterMaster> Replacements(CharacterMaster[] slots)
		{
			bool canPromote = HasBossRoom(slots);
			return slots.Where((CharacterMaster master) => Alive(master) && (canPromote || IsBossBody(master.bodyPrefab)));
		}

		private void Select(PickupPickerController picker, int encodedChoice)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Invalid comparison between Unknown and I4
			//IL_00aa: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00e8: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_0162: Unknown result type (might be due to invalid IL or missing references)
			NetworkUIPromptController component = ((Component)this).GetComponent<NetworkUIPromptController>();
			CharacterMaster currentParticipantMaster = component.currentParticipantMaster;
			CharacterBody body = (Object.op_Implicit((Object)(object)currentParticipantMaster) ? currentParticipantMaster.GetBody() : null);
			if (operation.Pending || Plugin.BossLimit.Value == 0 || (Object)(object)currentParticipantMaster != (Object)(object)participant || !InteractionOperation.ValidParticipant(picker, body))
			{
				return;
			}
			bool flag = encodedChoice < 0;
			int num = encodedChoice & 0x7FFFFFFF;
			if (flag != ((int)selectedItem != -1) || num >= picker.options.Length || !picker.options[num].available)
			{
				return;
			}
			PickupIndex pickup = picker.options[num].pickup.pickupIndex;
			PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup);
			ItemIndex val = (ItemIndex)((pickupDef == null) ? (-1) : ((int)pickupDef.itemIndex));
			GameObject prefab = FindForm(val);
			if (!Object.op_Implicit((Object)(object)prefab) || !InteractionOperation.CanPay(body, val))
			{
				ShowItems(picker, body);
				return;
			}
			CharacterMaster[] slots = OccupiedSlots(currentParticipantMaster);
			if (flag)
			{
				if (val == selectedItem && num < targets.Length)
				{
					CharacterMaster val2 = targets[num];
					if (!Object.op_Implicit((Object)(object)val2) || (Object)(object)val2.bodyPrefab == (Object)(object)prefab || !Replacements(slots).Contains(val2))
					{
						ShowItems(picker, body);
					}
					else
					{
						Complete(picker, component, body, val, prefab, val2);
					}
				}
				return;
			}
			if (HasRoom(slots))
			{
				Complete(picker, component, body, val, prefab, null);
				return;
			}
			targets = (from master in Replacements(slots)
				where (Object)(object)master.bodyPrefab != (Object)(object)prefab
				select master).ToArray();
			if (targets.Length != 0)
			{
				selectedItem = val;
				picker.SetOptionsServer(targets.Select(delegate(CharacterMaster master)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: 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)
					PickupIndex index = pickup;
					NetworkInstanceId netId = ((NetworkBehaviour)master).netId;
					return Option(index, ((NetworkInstanceId)(ref netId)).Value);
				}).ToArray());
			}
		}

		private void Complete(PickupPickerController picker, NetworkUIPromptController prompt, CharacterBody body, ItemIndex item, GameObject prefab, CharacterMaster target)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			Inventory inventory = body.inventory;
			if (!operation.TryBegin())
			{
				return;
			}
			Run instance = Run.instance;
			CharacterMaster master = body.master;
			inventory.RemoveItemPermanent(item, 1);
			bool flag = false;
			try
			{
				flag = (Object.op_Implicit((Object)(object)target) ? Companions.ReplaceBody(target, prefab) : Hatch(body, prefab));
				if (flag && Object.op_Implicit((Object)(object)target))
				{
					SharedInventory.Refresh();
				}
			}
			finally
			{
				if (!flag && Object.op_Implicit((Object)(object)target) && target.GetBody()?.bodyIndex == (BodyIndex?)prefab.GetComponent<CharacterBody>().bodyIndex)
				{
					flag = true;
					picker.SetAvailable(false);
					prompt.ClearParticipant();
					operation.Finish();
					NetworkServer.Destroy(((Component)this).gameObject);
				}
				if (!flag && operation.Finish())
				{
					InteractionOperation.Refund(master, item, instance, ((Component)this).transform.position);
					if (Object.op_Implicit((Object)(object)picker) && Object.op_Implicit((Object)(object)body))
					{
						ShowItems(picker, body);
					}
				}
			}
			if (flag)
			{
				picker.SetAvailable(false);
				prompt.ClearParticipant();
				operation.Finish();
				if (Object.op_Implicit((Object)(object)target))
				{
					RunStatistics.Current.Offerings++;
				}
				GameObject val = LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/LemurianEggHatching");
				if (Object.op_Implicit((Object)(object)val))
				{
					EffectManager.SpawnEffect(val, new EffectData
					{
						origin = ((Component)this).transform.position
					}, true);
				}
				NetworkServer.Destroy(((Component)this).gameObject);
			}
		}

		private bool Hatch(CharacterBody owner, GameObject prefab)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0046: 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_005f: Expected O, but got Unknown
			LemurianEggController component = ((Component)this).GetComponent<LemurianEggController>();
			CharacterMaster val = Companions.SummonWithBody(new MasterSummon
			{
				masterPrefab = component.masterPrefab,
				position = ((Component)this).transform.position,
				rotation = ((Component)this).transform.rotation,
				summonerBodyObject = ((Component)owner).gameObject,
				ignoreTeamMemberLimit = true,
				useAmbientLevel = true
			}, prefab);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			bool flag = false;
			try
			{
				DevotedLemurianController val2 = default(DevotedLemurianController);
				if (!Object.op_Implicit((Object)(object)val.GetBody()) || !((Component)val).TryGetComponent<DevotedLemurianController>(ref val2))
				{
					return false;
				}
				DevotionInventoryController val3 = SharedInventory.ForOwner(owner.master);
				val2.InitializeDevotedLemurian((ItemIndex)(-1), val3);
				if (!PetRegistry.Owns(val))
				{
					return false;
				}
				SharedInventory.Flush();
				RunStatistics.RecordHatch(val2);
				flag = true;
				return true;
			}
			finally
			{
				if (!flag)
				{
					SharedInventory.CancelHatch(val);
				}
			}
		}

		internal static string Label(UniquePickup pickup, int index)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (pickup.upgradeValue != 0)
			{
				GameObject val = Util.FindNetworkObject(new NetworkInstanceId((uint)pickup.upgradeValue));
				CharacterMaster val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<CharacterMaster>() : null);
				CharacterBody val3 = (Object.op_Implicit((Object)(object)val2) ? val2.GetBody() : null);
				if (!Object.op_Implicit((Object)(object)val3))
				{
					return Settings.Text($"Companion {index + 1}", $"Питомец {index + 1}");
				}
				return $"{index + 1}. {val3.GetDisplayName()} ({Mathf.CeilToInt(val3.healthComponent.healthFraction * 100f)}%)";
			}
			return FormName(pickup.pickupIndex);
		}

		internal static string FormName(PickupIndex pickup)
		{
			//IL_0000: 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)
			PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup);
			GameObject val = FindForm((ItemIndex)((pickupDef == null) ? (-1) : ((int)pickupDef.itemIndex)));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return "";
			}
			return Language.GetString(val.GetComponent<CharacterBody>().baseNameToken);
		}
	}
	internal static class CompanionInventory
	{
		private sealed class Ledger
		{
			internal Dictionary<string, int> Applied = new Dictionary<string, int>();

			internal bool Restoring;

			internal bool AdoptExisting;
		}

		private static readonly ConditionalWeakTable<DevotedLemurianController, Ledger> Ledgers = new ConditionalWeakTable<DevotedLemurianController, Ledger>();

		private static readonly Action<DevotionInventoryController, DevotedLemurianController> Evolve = AccessTools.MethodDelegate<Action<DevotionInventoryController, DevotedLemurianController>>(AccessTools.Method(typeof(DevotionInventoryController), "EvolveDevotedLumerian", (Type[])null, (Type[])null), (object)null, true);

		private static readonly FieldRef<NetworkSoundEventDef> EvolutionSound = AccessTools.StaticFieldRefAccess<NetworkSoundEventDef>(AccessTools.Field(typeof(DevotionInventoryController), "activationSoundEventDef"));

		private static Ledger For(DevotedLemurianController minion)
		{
			return Ledgers.GetValue(minion, (DevotedLemurianController _) => new Ledger());
		}

		internal static Dictionary<string, int> Snapshot(DevotedLemurianController minion)
		{
			if (!Ledgers.TryGetValue(minion, out var value) || value.AdoptExisting)
			{
				return null;
			}
			return new Dictionary<string, int>(value.Applied);
		}

		internal static void BeginRestore(DevotedLemurianController minion)
		{
			Ledger ledger = For(minion);
			ledger.Restoring = true;
			ledger.AdoptExisting = true;
		}

		internal static void RestoreLedger(DevotedLemurianController minion, Dictionary<string, int> saved)
		{
			if (saved != null)
			{
				Ledger ledger = For(minion);
				ledger.Applied = new Dictionary<string, int>(saved);
				ledger.AdoptExisting = false;
			}
		}

		internal static void FinishRestore(DevotedLemurianController minion)
		{
			For(minion).Restoring = false;
			SharedInventory.Refresh();
		}

		internal static bool SpendSharedRevival(DevotedLemurianController minion, ItemIndex item)
		{
			//IL_0007: 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)
			Ledger ledger = For(minion);
			string name = ((Object)ItemCatalog.GetItemDef(item)).name;
			if (!ledger.Applied.TryGetValue(name, out var value) || value <= 0)
			{
				return false;
			}
			if (((Component)minion).GetComponent<CharacterMaster>().inventory.GetItemCountPermanent(item) >= value)
			{
				return false;
			}
			ledger.Applied[name] = value - 1;
			return true;
		}

		internal static void Advance(DevotionInventoryController controller, DevotedLemurianController minion, CharacterBody body)
		{
			//IL_0015: 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)
			NetworkSoundEventDef val = EvolutionSound.Invoke();
			if (Object.op_Implicit((Object)(object)val))
			{
				EffectManager.SimpleSoundEffect(val.index, ((Component)body).transform.position, true);
			}
			int devotedEvolutionLevel = minion.DevotedEvolutionLevel;
			minion.DevotedEvolutionLevel = devotedEvolutionLevel + 1;
			Evolve(controller, minion);
		}

		internal static void Sync(DevotedLemurianController minion, Inventory pool, ItemIndex[] changed = null)
		{
			//IL_009e: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: 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)
			Ledger ledger = For(minion);
			Inventory inventory = ((Component)minion).GetComponent<CharacterMaster>().inventory;
			if (ledger.Restoring || !Object.op_Implicit((Object)(object)inventory))
			{
				return;
			}
			int devotedEvolutionLevel = minion.DevotedEvolutionLevel;
			bool flag = BossEgg.IsBossBody(((Component)minion).GetComponent<CharacterMaster>().bodyPrefab);
			int num = ((devotedEvolutionLevel == 0 || devotedEvolutionLevel == 2) ? 10 : (20 + Math.Max(0, devotedEvolutionLevel - 3)));
			ItemIndex[] array = ((changed != null && !ledger.AdoptExisting) ? changed : (from index in pool.itemAcquisitionOrder.Concat(((IEnumerable<string>)ledger.Applied.Keys).Select((Func<string, ItemIndex>)ItemCatalog.FindItemIndex)).Append(Items.BoostHp.itemIndex).Append(Items.BoostDamage.itemIndex)
				where (int)index != -1
				select index).Distinct().ToArray());
			foreach (ItemIndex val in array)
			{
				string name = ((Object)ItemCatalog.GetItemDef(val)).name;
				int num3 = ((Inventory.defaultItemCopyFilterDelegate(val) && (!flag || !Heresy.IsHeresyItem(val))) ? pool.GetItemCountPermanent(val) : 0);
				if (val == Items.BoostHp.itemIndex || val == Items.BoostDamage.itemIndex)
				{
					num3 += num;
				}
				if (!ledger.Applied.TryGetValue(name, out var value) && ledger.AdoptExisting && num3 > 0)
				{
					value = Math.Min(num3, inventory.GetItemCountPermanent(val));
				}
				if (num3 > value)
				{
					inventory.GiveItemPermanent(val, num3 - value);
				}
				else if (num3 < value)
				{
					int num4 = Math.Min(value, inventory.GetItemCountPermanent(val)) - num3;
					if (num4 > 0)
					{
						inventory.RemoveItemPermanent(val, num4);
					}
				}
				if (num3 > 0)
				{
					ledger.Applied[name] = num3;
				}
				else
				{
					ledger.Applied.Remove(name);
				}
			}
			if (ledger.AdoptExisting)
			{
				Plugin.Log("Restored legacy companion inventory; existing matching stacks were adopted as shared.");
			}
			ledger.AdoptExisting = false;
		}
	}
	public enum CompanionSpecies
	{
		Lemurian,
		Beetle,
		Gup,
		Wisp,
		Vermin,
		Construct,
		Lynx
	}
	internal static class Companions
	{
		private sealed class ReplacementHealth
		{
			internal BodyIndex Target;

			internal float Fraction;
		}

		[HarmonyPatch(typeof(CharacterMaster), "OnBodyStart")]
		private static class PreserveReplacementHealth
		{
			private static void Postfix(CharacterMaster __instance, CharacterBody body)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (NetworkServer.active && PendingHealth.TryGetValue(__instance, out var value) && value.Target == body.bodyIndex)
				{
					PendingHealth.Remove(__instance);
					HealthComponent healthComponent = body.healthComponent;
					healthComponent.Networkhealth = Mathf.Clamp(healthComponent.fullHealth * value.Fraction, 1f, healthComponent.fullHealth);
				}
			}
		}

		[HarmonyPatch(typeof(LemurianEggController), "SummonLemurian", new Type[] { typeof(PickupIndex) })]
		private static class ConfiguredHatch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Expected O, but got Unknown
				MethodInfo perform = AccessTools.Method(typeof(MasterSummon), "Perform", (Type[])null, (Type[])null);
				MethodInfo operand = AccessTools.Method(typeof(Companions), "Summon", (Type[])null, (Type[])null);
				List<CodeInstruction> list = instructions.ToList();
				CodeInstruction val = list.Single((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, perform));
				CodeInstruction val2 = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				val2.labels.AddRange(val.labels);
				val.labels.Clear();
				list.Insert(list.IndexOf(val), val2);
				val.opcode = OpCodes.Call;
				val.operand = operand;
				MethodInfo destroy = AccessTools.Method(typeof(Object), "Destroy", new Type[1] { typeof(Object) }, (Type[])null);
				list.Single((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, destroy)).operand = AccessTools.Method(typeof(EggOverflow), "FinishHatch", (Type[])null, (Type[])null);
				return list;
			}
		}

		[HarmonyPatch(typeof(DevotionInventoryController), "EvolveDevotedLumerian")]
		private static class VariantEvolution
		{
			private static bool Prefix(DevotedLemurianController devotedLemurianController)
			{
				//IL_004e: 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)
				CharacterMaster component = ((Component)devotedLemurianController).GetComponent<CharacterMaster>();
				GameObject bodyPrefab = component.bodyPrefab;
				if (!IsAlternateBody(bodyPrefab))
				{
					return true;
				}
				int devotedEvolutionLevel = devotedLemurianController.DevotedEvolutionLevel;
				if (devotedEvolutionLevel == 3 && ((Object)bodyPrefab).name == "GeepBody")
				{
					Evolve(component, "GupBody");
				}
				if (devotedEvolutionLevel != 2)
				{
					return true;
				}
				Inventory inventory = component.inventory;
				EquipmentLocation activeEquipmentLocation = inventory.activeEquipmentLocation;
				inventory.SetEquipmentIndex((EquipmentIndex)(-1), ref activeEquipmentLocation);
				switch (((Object)bodyPrefab).name)
				{
				case "BeetleBody":
					Evolve(component, "BeetleGuardAllyBody");
					break;
				case "GipBody":
					Evolve(component, "GeepBody");
					break;
				case "WispBody":
					Evolve(component, "GreaterWispBody");
					break;
				case "VerminBody":
					Evolve(component, "FlyingVerminBody");
					break;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(BaseSplitDeath), "OnEnter")]
		private static class NoUntrackedSplits
		{
			private static void Prefix(BaseSplitDeath __instance)
			{
				if (Followers.IsDevoted(((Component)((EntityState)__instance).outer).GetComponent<CharacterBody>()))
				{
					__instance.spawnCount = 0;
				}
			}
		}

		private static ConfigEntry<CompanionSpecies> species;

		private static readonly Dictionary<string, bool> NextLynxIsArcher = new Dictionary<string, bool>();

		private static readonly HashSet<string> CompanionBodies = new HashSet<string>
		{
			"BeetleBody", "BeetleGuardAllyBody", "GipBody", "GeepBody", "GupBody", "WispBody", "GreaterWispBody", "VerminBody", "FlyingVerminBody", "MinorConstructOnKillBody",
			"Lynx2Body", "LynxArcherBody", "HereticBody"
		};

		private static readonly Dictionary<GameObject, BaseAI> BodyAIs = new Dictionary<GameObject, BaseAI>();

		private static readonly FieldInfo[] DriverFields = (from field in typeof(AISkillDriver).GetFields(BindingFlags.Instance | BindingFlags.Public)
			where field.Name != "nextHighPriorityOverride"
			select field).ToArray();

		private static readonly ConditionalWeakTable<CharacterMaster, ReplacementHealth> PendingHealth = new ConditionalWeakTable<CharacterMaster, ReplacementHealth>();

		internal static CompanionSpecies Current { get; private set; }

		internal static void Configure(ConfigFile config)
		{
			species = Settings.Bind(config, "Companions", "Companion species", CompanionSpecies.Lemurian, "Choose what hatches from eggs. Applies to a new run. Vermin, Gup and Construct require DLC1; Lynx requires DLC4.", "Выбирает, кто вылупляется из яиц. Со следующего нового забега. Для гупов, паразитов и конструкта нужен DLC1, для рысей DLC4.", (ConfigEntry<CompanionSpecies> entry) => (BaseOption)new ChoiceOption((ConfigEntryBase)(object)entry), null, null, "Вид питомца");
			Run.onRunStartGlobal += OnRunStart;
		}

		private static void OnRunStart(Run run)
		{
			if (!NetworkServer.active)
			{
				return;
			}
			NextLynxIsArcher.Clear();
			Current = species.Value;
			string text;
			switch (Current)
			{
			case CompanionSpecies.Gup:
			case CompanionSpecies.Vermin:
			case CompanionSpecies.Construct:
				text = "DLC1";
				break;
			case CompanionSpecies.Lynx:
				text = "DLC4";
				break;
			default:
				text = null;
				break;
			}
			string text2 = text;
			if (text2 != null)
			{
				ExpansionDef val = ExpansionCatalog.FindByName(text2);
				if (!Object.op_Implicit((Object)(object)val) || !run.IsExpansionEnabled(val))
				{
					Plugin.Log($"Companion species {Current} requires {text2} in the run. Falling back to Lemurians.");
					Current = CompanionSpecies.Lemurian;
				}
			}
			if (Current != CompanionSpecies.Lemurian && !Object.op_Implicit((Object)(object)FindBody(FirstBody(Current))))
			{
				Plugin.Log($"Companion body for {Current} was not found. Falling back to Lemurians.");
				Current = CompanionSpecies.Lemurian;
			}
		}

		private static string FirstBody(CompanionSpecies choice)
		{
			return choice switch
			{
				CompanionSpecies.Beetle => "BeetleBody", 
				CompanionSpecies.Gup => "GipBody", 
				CompanionSpecies.Wisp => "WispBody", 
				CompanionSpecies.Vermin => "VerminBody", 
				CompanionSpecies.Construct => "MinorConstructOnKillBody", 
				CompanionSpecies.Lynx => "Lynx2Body", 
				_ => "DevotedLemurianBody", 
			};
		}

		private static GameObject FindBody(string name)
		{
			return BodyCatalog.FindBodyPrefab(name);
		}

		internal static BodyIndex PortraitIndex()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return BodyCatalog.FindBodyIndex(FirstBody(Current));
		}

		internal static bool IsAlternateBody(GameObject body)
		{
			if (Object.op_Implicit((Object)(object)body))
			{
				if (!CompanionBodies.Contains(VisualEffects.PrefabName(body)))
				{
					return BossEgg.IsBossBody(body);
				}
				return true;
			}
			return false;
		}

		internal static bool IsAlternateBody(BodyIndex index)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return IsAlternateBody(BodyCatalog.GetBodyPrefab(index));
		}

		internal static string TeamName(bool alternate)
		{
			if (!alternate)
			{
				return Settings.Text("Team Lemurians", "Лемуры команды");
			}
			return Settings.Text("Team Companions", "Питомцы команды");
		}

		private static string OwnerKey(GameObject summoner)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			object obj;
			if (!Object.op_Implicit((Object)(object)summoner))
			{
				obj = null;
			}
			else
			{
				CharacterBody component = summoner.GetComponent<CharacterBody>();
				if (component == null)
				{
					obj = null;
				}
				else
				{
					CharacterMaster master = component.master;
					obj = ((master != null) ? master.playerCharacterMasterController : null);
				}
			}
			PlayerCharacterMasterController val = (PlayerCharacterMasterController)obj;
			NetworkUser val2 = (Object.op_Implicit((Object)(object)val) ? val.networkUser : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return null;
			}
			return ProgressSave.Key(UserIDData.Create(val2.id));
		}

		internal static Dictionary<string, bool> SaveLynxOrder()
		{
			return new Dictionary<string, bool>(NextLynxIsArcher);
		}

		internal static void Restore(CompanionSpecies restored, Dictionary<string, bool> lynxOrder)
		{
			Current = restored;
			NextLynxIsArcher.Clear();
			if (lynxOrder == null)
			{
				return;
			}
			foreach (KeyValuePair<string, bool> item in lynxOrder)
			{
				NextLynxIsArcher[item.Key] = item.Value;
			}
		}

		private static CharacterMaster Summon(MasterSummon summon, LemurianEggController egg)
		{
			CharacterMaster val = SummonConfigured(summon);
			EggOverflow.RecordSpawn(egg, val);
			return val;
		}

		private static CharacterMaster SummonConfigured(MasterSummon summon)
		{
			if (Current == CompanionSpecies.Lemurian)
			{
				return summon.Perform();
			}
			string text = ((Current == CompanionSpecies.Lynx) ? OwnerKey(summon.summonerBodyObject) : null);
			bool value = default(bool);
			bool flag = text != null && NextLynxIsArcher.TryGetValue(text, out value) && value;
			GameObject val = FindBody(flag ? "LynxArcherBody" : FirstBody(Current));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return summon.Perform();
			}
			CharacterMaster obj = SummonWithBody(summon, val);
			if (Object.op_Implicit((Object)(object)obj) && text != null)
			{
				NextLynxIsArcher[text] = !flag;
			}
			return obj;
		}

		internal static CharacterMaster SummonWithBody(MasterSummon summon, GameObject prefab)
		{
			summon.preSpawnSetupCallback = (Action<CharacterMaster>)Delegate.Combine(summon.preSpawnSetupCallback, (Action<CharacterMaster>)delegate(CharacterMaster master)
			{
				SetBaseBody(master, prefab);
				master.PushBodyHandlingConfig((BodyHandlingConfig)null, prefab, true);
				ApplyDrivers(master, prefab);
			});
			return summon.Perform();
		}

		internal static bool ReplaceBody(CharacterMaster master, GameObject prefab)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody body = master.GetBody();
			if (!Object.op_Implicit((Object)(object)body) || !body.healthComponent.alive)
			{
				return false;
			}
			ReplacementHealth replacementHealth = new ReplacementHealth
			{
				Target = prefab.GetComponent<CharacterBody>().bodyIndex,
				Fraction = Mathf.Clamp01(body.healthComponent.healthFraction)
			};
			PendingHealth.Remove(master);
			PendingHealth.Add(master, replacementHealth);
			bool flag = false;
			try
			{
				Evolve(master, ((Object)prefab).name);
				body = master.GetBody();
				flag = Object.op_Implicit((Object)(object)body) && body.bodyIndex == replacementHealth.Target;
				return flag;
			}
			finally
			{
				if (!flag)
				{
					PendingHealth.Remove(master);
				}
			}
		}

		private static void SetBaseBody(CharacterMaster master, GameObject prefab)
		{
			master.SetBaseBodyHandlingConfig((BodyHandlingConfig)null, prefab, true);
		}

		internal static void ApplyDrivers(CharacterMaster master, GameObject prefab)
		{
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			DevotedLemurianController lemur = default(DevotedLemurianController);
			BaseAI val = default(BaseAI);
			if (!IsAlternateBody(prefab) || !((Component)master).TryGetComponent<DevotedLemurianController>(ref lemur) || !((Component)master).TryGetComponent<BaseAI>(ref val))
			{
				return;
			}
			LemurProgress lemurProgress = LemurProgress.For(lemur);
			if ((Object)(object)lemurProgress.DriverBodyPrefab == (Object)(object)prefab)
			{
				return;
			}
			if (!BodyAIs.TryGetValue(prefab, out var value))
			{
				CharacterMaster val2 = MasterCatalog.allAiMasters.FirstOrDefault((Func<CharacterMaster, bool>)((CharacterMaster candidate) => Object.op_Implicit((Object)(object)candidate) && (Object)(object)candidate.bodyPrefab == (Object)(object)prefab));
				value = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<BaseAI>() : null);
				BodyAIs[prefab] = value;
			}
			lemurProgress.DriverBodyPrefab = prefab;
			if (!Object.op_Implicit((Object)(object)value))
			{
				Plugin.Log("No native AI found for " + ((Object)prefab).name + ". Keeping the Devotion drivers.");
				return;
			}
			AISkillDriver[] components = ((Component)value).GetComponents<AISkillDriver>();
			val.desiredSpawnNodeGraphType = value.desiredSpawnNodeGraphType;
			val.aimVectorDampTime = value.aimVectorDampTime;
			val.aimVectorMaxSpeed = value.aimVectorMaxSpeed;
			if (components.Length == 0)
			{
				return;
			}
			LemurProgress lemurProgress2 = lemurProgress;
			if (lemurProgress2.FollowDrivers == null)
			{
				lemurProgress2.FollowDrivers = val.skillDrivers.Where((AISkillDriver driver) => (int)driver.moveTargetType == 2).ToArray();
			}
			if (lemurProgress.CombatDrivers != null)
			{
				AISkillDriver[] combatDrivers = lemurProgress.CombatDrivers;
				for (int num = 0; num < combatDrivers.Length; num++)
				{
					Object.Destroy((Object)(object)combatDrivers[num]);
				}
			}
			AISkillDriver[] array = (AISkillDriver[])(object)new AISkillDriver[components.Length];
			for (int num2 = 0; num2 < array.Length; num2++)
			{
				array[num2] = ((Component)master).gameObject.AddComponent<AISkillDriver>();
				FieldInfo[] driverFields = DriverFields;
				foreach (FieldInfo fieldInfo in driverFields)
				{
					fieldInfo.SetValue(array[num2], fieldInfo.GetValue(components[num2]));
				}
			}
			for (int num3 = 0; num3 < array.Length; num3++)
			{
				int num4 = Array.IndexOf(components, components[num3].nextHighPriorityOverride);
				if (num4 >= 0)
				{
					array[num3].nextHighPriorityOverride = array[num4];
				}
			}
			lemurProgress.CombatDrivers = array;
			val.ReplaceSkillDrivers(array.Where((AISkillDriver driver) => (int)driver.moveTargetType == 0).Concat(lemurProgress.FollowDrivers).Concat(array.Where((AISkillDriver driver) => (int)driver.moveTargetType > 0))
				.ToArray());
		}

		private static void Evolve(CharacterMaster master, string nextBody)
		{
			GameObject val = FindBody(nextBody);
			if (Object.op_Implicit((Object)(object)val))
			{
				ApplyDrivers(master, val);
				SetBaseBody(master, val);
				master.TransformBody(nextBody, false);
			}
		}
	}
	internal sealed class ConditionalRows : MonoBehaviour
	{
		[HarmonyPatch]
		private static class AddVisibility
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.DeclaredMethod(typeof(IntSliderOption), "CreateOptionGameObject", (Type[])null, (Type[])null);
				yield return AccessTools.DeclaredMethod(typeof(IntFieldOption), "CreateOptionGameObject", (Type[])null, (Type[])null);
			}

			private static void Postfix(BaseOption __instance, Transform parent, GameObject __result)
			{
				if (Rules.TryGetValue(__instance, out var value))
				{
					ConditionalRows conditionalRows = ((Component)parent).GetComponent<ConditionalRows>();
					if (!Object.op_Implicit((Object)(object)conditionalRows))
					{
						conditionalRows = ((Component)parent).gameObject.AddComponent<ConditionalRows>();
					}
					conditionalRows.rows.Add(__result, value);
				}
			}
		}

		private static readonly ConditionalWeakTable<BaseOption, IsDisabledDelegate> Rules = new ConditionalWeakTable<BaseOption, IsDisabledDelegate>();

		private readonly Dictionary<GameObject, IsDisabledDelegate> rows = new Dictionary<GameObject, IsDisabledDelegate>();

		private readonly List<GameObject> removed = new List<GameObject>();

		internal static BaseOption Register(BaseOption option, IsDisabledDelegate hidden)
		{
			if (hidden != null)
			{
				Rules.Add(option, hidden);
			}
			return option;
		}

		private void LateUpdate()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			foreach (KeyValuePair<GameObject, IsDisabledDelegate> row in rows)
			{
				if (!Object.op_Implicit((Object)(object)row.Key))
				{
					removed.Add(row.Key);
					continue;
				}
				bool flag2 = !row.Value.Invoke();
				if (row.Key.activeSelf != flag2)
				{
					row.Key.SetActive(flag2);
					flag = true;
				}
			}
			foreach (GameObject item in removed)
			{
				rows.Remove(item);
			}
			removed.Clear();
			if (!flag)
			{
				return;
			}
			Selectable val = null;
			foreach (Transform item2 in ((Component)this).transform)
			{
				Transform val2 = item2;
				if (!((Component)val2).gameObject.activeSelf || !Object.op_Implicit((Object)(object)((Component)val2).GetComponentInChildren<ModSetting>()))
				{
					continue;
				}
				Selectable componentInChildren = ((Component)val2).GetComponentInChildren<Selectable>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					Navigation navigation = componentInChildren.navigation;
					((Navigation)(ref navigation)).selectOnUp = val;
					((Navigation)(ref navigation)).selectOnDown = null;
					componentInChildren.navigation = navigation;
					if (Object.op_Implicit((Object)(object)val))
					{
						navigation = val.navigation;
						((Navigation)(ref navigation)).selectOnDown = componentInChildren;
						val.navigation = navigation;
					}
					val = componentInChildren;
				}
			}
		}
	}
	internal static class EggOverflow
	{
		private sealed class Offering
		{
			internal CharacterMaster Owner;

			internal ItemIndex Item;

			internal Run Run;

			internal CharacterMaster Spawned;

			internal readonly OperationGate Gate = new OperationGate();
		}

		[HarmonyPatch(typeof(LemurianEggController), "OnDestroy")]
		private static class DestroyedEgg
		{
			private static void Prefix(LemurianEggController __instance)
			{
				if (NetworkServer.active && Donors.TryGetValue(__instance, out var value) && !Object.op_Implicit((Object)(object)value.Spawned))
				{
					Refund(__instance, value);
				}
			}
		}

		[HarmonyPatch(typeof(PickupPickerController), "HandlePickupSelected")]
		private static class PermanentSelection
		{
			private static bool Prefix(PickupPickerController __instance, int choiceIndex)
			{
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				if (!NetworkServer.active || !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<LemurianEggController>()) || Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<BossEgg>()))
				{
					return true;
				}
				if (__instance.available && (uint)choiceIndex < __instance.options.Length)
				{
					return IsPermanent(__instance.options[choiceIndex]);
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(LemurianEggController), "OfferItem", new Type[] { typeof(int) })]
		private static class Offer
		{
			private static bool Prefix(LemurianEggController __instance, int intPickupIndex, Interactor ___interactor)
			{
				//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)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Invalid comparison between Unknown and I4
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				if (!NetworkServer.active || Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<BossEgg>()) || Donors.TryGetValue(__instance, out var _))
				{
					return false;
				}
				PickupIndex index = new PickupIndex(intPickupIndex);
				PickupDef pickupDef = PickupCatalog.GetPickupDef(index);
				PickupPickerController component = ((Component)__instance).GetComponent<PickupPickerController>();
				CharacterBody val = (Object.op_Implicit((Object)(object)___interactor) ? ((Component)___interactor).GetComponent<CharacterBody>() : null);
				if (pickupDef != null && (int)pickupDef.itemIndex != -1 && InteractionOperation.ValidParticipant(component, val) && InteractionOperation.CanPay(val, pickupDef.itemIndex) && component.options.Any((Option option) => option.pickup.pickupIndex == index && IsPermanent(option)))
				{
					List<Option> list = GetOptions(component, ___interactor);
					if (list != null && list.Any((Option option) => option.pickup.pickupIndex == index && IsPermanent(option)))
					{
						Offering offering = new Offering
						{
							Owner = val.master,
							Item = pickupDef.itemIndex,
							Run = Run.instance
						};
						offering.Gate.TryBegin();
						Donors.Add(__instance, offering);
						return true;
					}
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(LemurianEggController), "AssignPotentialInteractor", new Type[] { typeof(Interactor) })]
		private static class LockDonor
		{
			private static bool Prefix(LemurianEggController __instance)
			{
				Offering value;
				return !Donors.TryGetValue(__instance, out value);
			}
		}

		[HarmonyPatch(typeof(DevotedLemurianController), "InitializeDevotedLemurian")]
		private static class RecordHatch
		{
			private static void Postfix(DevotedLemurianController __instance)
			{
				SharedInventory.Register(__instance);
			}
		}

		[HarmonyPatch(typeof(LemurianEggController), "SummonLemurian", new Type[] { typeof(PickupIndex) })]
		private static class Hatch
		{
			private static Exception Finalizer(LemurianEggController __instance, Exception __exception)
			{
				if (__exception == null || !NetworkServer.active || !Donors.TryGetValue(__instance, out var value))
				{
					return __exception;
				}
				SharedInventory.CancelHatch(value.Spawned);
				Refund(__instance, value);
				__instance.SetInteractabilityServer(true);
				return __exception;
			}

			private static bool Prefix(LemurianEggController __instance, PickupIndex pickupIndex, Interactor ___interactor)
			{
				//IL_0049: 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_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0212: Unknown result type (might be due to invalid IL or missing references)
				//IL_022e: Unknown result type (might be due to invalid IL or missing references)
				//IL_027f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0284: Unknown result type (might be due to invalid IL or missing references)
				//IL_028b: Unknown result type (might be due to invalid IL or missing references)
				//IL_029b: Expected O, but got Unknown
				if (!NetworkServer.active || !Donors.TryGetValue(__instance, out var value))
				{
					return true;
				}
				CharacterMaster owner = value.Owner;
				if ((Object)(object)value.Run != (Object)(object)Run.instance || !Object.op_Implicit((Object)(object)owner) || PickupCatalog.GetPickupDef(pickupIndex)?.itemIndex != (ItemIndex?)value.Item)
				{
					Refund(__instance, value);
					__instance.SetInteractabilityServer(true);
					return false;
				}
				ItemIndex item = value.Item;
				DevotedLemurianController[] source = SharedInventory.Minions.Where((DevotedLemurianController minion) => (Object)(object)((Component)minion).GetComponent<CharacterMaster>().minionOwnership.ownerMaster == (Object)(object)owner).ToArray();
				DevotedLemurianController[] array = source.Where(delegate(DevotedLemurianController minion)
				{
					CharacterBody body = ((Component)minion).GetComponent<CharacterMaster>().GetBody();
					return body != null && body.healthComponent.alive;
				}).ToArray();
				int occupied = source.Select((DevotedLemurianController minion) => ((Component)minion).GetComponent<CharacterMaster>()).Count((CharacterMaster master) => BossEgg.UsesPetSlot(master) && PetRules.OccupiesSlot(PetRegistry.State(master)));
				bool flag = PetRules.HasRoom(Plugin.LemurLimit.Value, occupied, 0);
				CharacterBody val = (Object.op_Implicit((Object)(object)___interactor) ? ((Component)___interactor).GetComponent<CharacterBody>() : null);
				if (flag && Object.op_Implicit((Object)(object)val) && (Object)(object)val.master == (Object)(object)owner && (Object)(object)owner.GetBody() == (Object)(object)val && val.healthComponent.alive)
				{
					return true;
				}
				if (flag || array.Length == 0)
				{
					Refund(__instance, value);
					__instance.SetInteractabilityServer(true);
					return false;
				}
				SharedInventory.ForOwner(owner);
				DevotedLemurianController lemur = array[Random.Range(0, array.Length)];
				LemurProgress.For(lemur).Data.Contributions.Add(new EggContribution
				{
					PetId = LemurProgress.For(lemur).Data.PetId,
					OwnerId = LemurProgress.For(lemur).Data.OwnerId,
					Item = ((Object)ItemCatalog.GetItemDef(item)).name,
					Stacks = 1
				});
				SharedInventory.Mark(item);
				value.Gate.Finish();
				Donors.Remove(__instance);
				RunStatistics.Current.Offerings++;
				SharedInventory.Flush();
				AwardTeamExperience();
				GameObject val2 = LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/LemurianEggHatching");
				if (Object.op_Implicit((Object)(object)val2))
				{
					EffectManager.SpawnEffect(val2, new EffectData
					{
						origin = ((Component)__instance).transform.position
					}, true);
				}
				Object.Destroy((Object)(object)((Component)__instance).gameObject);
				return false;
			}
		}

		private static readonly Func<PickupPickerController, Interactor, List<Option>> GetOptions = AccessTools.MethodDelegate<Func<PickupPickerController, Interactor, List<Option>>>(AccessTools.Method(typeof(PickupPickerController), "GetGeneratedOptionsFromInteractor", (Type[])null, (Type[])null), (object)null, true);

		private static readonly ConditionalWeakTable<LemurianEggController, Offering> Donors = new ConditionalWeakTable<LemurianEggController, Offering>();

		private static void AwardTeamExperience()
		{
			TeamManager instance = TeamManager.instance;
			if (Object.op_Implicit((Object)(object)instance) && !SuppressExperience.suppressExperience)
			{
				ulong teamCurrentLevelExperience = instance.GetTeamCurrentLevelExperience((TeamIndex)1);
				ulong teamNextLevelExperience = instance.GetTeamNextLevelExperience((TeamIndex)1);
				if (teamNextLevelExperience > teamCurrentLevelExperience)
				{
					instance.GiveTeamExperience((TeamIndex)1, Math.Max(1uL, (teamNextLevelExperience - teamCurrentLevelExperience) / 20));
				}
			}
		}

		private static bool IsPermanent(Option option)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			if (option.available && !option.pickup.isRental)
			{
				return option.pickup.decayValue == 0f;
			}
			return false;
		}

		private static void Refund(LemurianEggController egg, Offering offering)
		{
			//IL_0021: 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)
			if (offering.Gate.Finish())
			{
				Donors.Remove(egg);
				InteractionOperation.Refund(offering.Owner, offering.Item, offering.Run, ((Component)egg).transform.position);
			}
		}

		internal static void RecordSpawn(LemurianEggController egg, CharacterMaster spawned)
		{
			if (Object.op_Implicit((Object)(object)spawned) && Donors.TryGetValue(egg, out var value))
			{
				value.Spawned = spawned;
			}
		}

		internal static void FinishHatch(GameObject obj)
		{
			LemurianEggController component = obj.GetComponent<LemurianEggController>();
			if (Donors.TryGetValue(component, out var value))
			{
				if (!Object.op_Implicit((Object)(object)value.Spawned) || !Object.op_Implicit((Object)(object)value.Spawned.GetBody()) || !PetRegistry.Owns(value.Spawned))
				{
					SharedInventory.CancelHatch(value.Spawned);
					Refund(component, value);
					component.SetInteractabilityServer(true);
					return;
				}
				value.Gate.Finish();
				Donors.Remove(component);
				RunStatistics.RecordHatch(((Component)value.Spawned).GetComponent<DevotedLemurianController>());
			}
			Object.Destroy((Object)(object)obj);
		}
	}
	internal sealed class EggPoolCounts : MonoBehaviour
	{
		private sealed class CountLabel
		{
			internal ItemIndex Item;

			internal HGTextMeshProUGUI Text;

			internal int Previous = -1;
		}

		[HarmonyPatch(typeof(PickupPickerPanel), "SetPickupOptions")]
		private static class ShowOnEgg
		{
			private static void Postfix(PickupPickerPanel __instance, Option[] ___pickupOptions, UIElementAllocator<MPButton> ___buttonAllocator)
			{
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a9: Invalid comparison between Unknown and I4
				//IL_01df: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				PickupPickerController pickerController = __instance.pickerController;
				if (!Object.op_Implicit((Object)(object)pickerController) || (!Object.op_Implicit((Object)(object)((Component)pickerController).GetComponent<LemurianEggController>()) && !Object.op_Implicit((Object)(object)((Component)pickerController).GetComponent<FlockPrinter>())))
				{
					return;
				}
				if (Object.op_Implicit((Object)(object)((Component)pickerController).GetComponent<BossEgg>()))
				{
					ReadOnlyCollection<MPButton> elements = ___buttonAllocator.elements;
					TooltipProvider val = default(TooltipProvider);
					for (int i = 0; i < elements.Count; i++)
					{
						HGTextMeshProUGUI label = GetLabel(elements[i]);
						((TMP_Text)label).text = BossEgg.Label(___pickupOptions[i].pickup, i);
						((Component)label).gameObject.SetActive(true);
						if (((Component)elements[i]).TryGetComponent<TooltipProvider>(ref val))
						{
							val.overrideTitleText = ((TMP_Text)label).text;
							string text = BossEgg.FormName(___pickupOptions[i].pickup.pickupIndex);
							val.overrideBodyText = ((___pickupOptions[i].pickup.upgradeValue == 0) ? Settings.Text("Hatches " + text + ". Spends one copy of the item.", "Форма питомца — " + text + ". Цена — один экземпляр предмета.") : Settings.Text("Replace this companion with " + text + ".", "Сменить форму этого питомца на «" + text + "»."));
						}
					}
					return;
				}
				EggPoolCounts eggPoolCounts = ((Component)__instance).GetComponent<EggPoolCounts>();
				if (!Object.op_Implicit((Object)(object)eggPoolCounts))
				{
					eggPoolCounts = ((Component)__instance).gameObject.AddComponent<EggPoolCounts>();
				}
				ReadOnlyCollection<MPButton> elements2 = ___buttonAllocator.elements;
				eggPoolCounts.labels = new CountLabel[elements2.Count];
				for (int j = 0; j < elements2.Count; j++)
				{
					PickupDef pickupDef = PickupCatalog.GetPickupDef(___pickupOptions[j].pickup.pickupIndex);
					HGTextMeshProUGUI label2 = GetLabel(elements2[j]);
					bool flag = pickupDef != null && (int)pickupDef.itemIndex != -1 && ___pickupOptions[j].available;
					((Component)label2).gameObject.SetActive(flag);
					if (flag)
					{
						eggPoolCounts.labels[j] = new CountLabel
						{
							Item = pickupDef.itemIndex,
							Text = label2
						};
					}
				}
				eggPoolCounts.nextRefresh = 0f;
				eggPoolCounts.Update();
				eggPoolCounts.RefreshLabels();
			}
		}

		private CountLabel[] labels;

		private float nextRefresh;

		private string previousLanguage;

		private Inventory subscribed;

		private void Update()
		{
			if (labels != null && !(Time.unscaledTime < nextRefresh))
			{
				nextRefresh = Time.unscaledTime + 0.2f;
				Inventory val = SharedInventory.DisplayPool();
				if (val != subscribed)
				{
					Subscribe(val);
				}
			}
		}

		private void OnEnable()
		{
			Language.onCurrentLanguageChanged += RefreshLabels;
			nextRefresh = 0f;
		}

		private void OnDisable()
		{
			Language.onCurrentLanguageChanged -= RefreshLabels;
			Subscribe(null);
		}

		private void Subscribe(Inventory inventory)
		{
			if (Object.op_Implicit((Object)(object)subscribed))
			{
				subscribed.onInventoryChanged -= RefreshLabels;
			}
			subscribed = inventory;
			if (Object.op_Implicit((Object)(object)subscribed))
			{
				subscribed.onInventoryChanged += RefreshLabels;
			}
			RefreshLabels();
		}

		private void RefreshLabels()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (labels == null)
			{
				return;
			}
			string currentLanguageName = Language.currentLanguageName;
			bool flag = currentLanguageName != previousLanguage;
			previousLanguage = currentLanguageName;
			CountLabel[] array = labels;
			foreach (CountLabel countLabel in array)
			{
				if (countLabel != null && Object.op_Implicit((Object)(object)countLabel.Text))
				{
					int num = (Object.op_Implicit((Object)(object)subscribed) ? subscribed.GetItemCountPermanent(countLabel.Item) : 0);
					if (num != countLabel.Previous || flag)
					{
						countLabel.Previous = num;
						((TMP_Text)countLabel.Text).text = Settings.Text("Pool", "Пул") + " ×" + num;
					}
				}
			}
		}

		private static HGTextMeshProUGUI GetLabel(MPButton button)
		{
			//IL_0045: 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)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)button).transform.Find("LemurTeamPoolCount");
			if (Object.op_Implicit((Object)(object)val))
			{
				return ((Component)val).GetComponent<HGTextMeshProUGUI>();
			}
			HGTextMeshProUGUI component = new GameObject("LemurTeamPoolCount", new Type[2]
			{
				typeof(RectTransform),
				typeof(HGTextMeshProUGUI)
			}).GetComponent<HGTextMeshProUGUI>();
			RectTransform rectTransform = ((TMP_Text)component).rectTransform;
			((Transform)rectTransform).SetParent(((Component)button).transform, false);
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = new Vector2(0.85f, 0.28f);
			rectTransform.offsetMin = new Vector2(3f, 1f);
			rectTransform.offsetMax = Vector2.zero;
			((TMP_Text)component).alignment = (TextAlignmentOptions)1025;
			((TMP_Text)component).enableAutoSizing = true;
			((TMP_Text)component).fontSizeMin = 7f;
			((TMP_Text)component).fontSizeMax = 15f;
			((Graphic)component).raycastTarget = false;
			((Graphic)component).color = new Color(0.76f, 0.93f, 1f);
			return component;
		}
	}
	internal sealed class FlockPrinter : MonoBehaviour
	{
		[HarmonyPatch(typeof(InteractableSpawnCard), "Spawn")]
		private static class ReplacePrinter
		{
			private static void Prefix(InteractableSpawnCard __instance, out GameObject __state)
			{
				__state = null;
				if (NetworkServer.active && stageRng != null && !replacedThisStage && Object.op_Implicit((Object)(object)((SpawnCard)__instance).prefab) && Variants.TryGetValue(((SpawnCard)__instance).prefab, out var value) && !(stageRng.nextNormalizedFloat >= 0.1f))
				{
					__state = ((SpawnCard)__instance).prefab;
					((SpawnCard)__instance).prefab = value;
				}
			}

			private static void Postfix(ref SpawnResult result, GameObject __state)
			{
				if (Object.op_Implicit((Object)(object)__state) && result.success)
				{
					replacedThisStage = true;
				}
			}

			private static void Finalizer(InteractableSpawnCard __instance, GameObject __state)
			{
				if (Object.op_Implicit((Object)(object)__state))
				{
					((SpawnCard)__instance).prefab = __state;
				}
			}
		}

		[HarmonyPatch(typeof(ShopTerminalBehavior), "Start")]
		private static class VerifyOutput
		{
			private static void Postfix(ShopTerminalBehavior __instance)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: 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)
				if (!NetworkServer.active || !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<FlockPrinter>()))
				{
					return;
				}
				for (int i = 0; i < 16; i++)
				{
					if (ValidItem(ItemFor(__instance.CurrentPickup().pickupIndex)))
					{
						break;
					}
					__instance.GenerateNewPickupServer();
				}
				if (!ValidItem(ItemFor(__instance.CurrentPickup().pickupIndex)))
				{
					((Component)__instance).GetComponent<PickupPickerController>().SetAvailable(false);
				}
			}
		}

		[HarmonyPatch(typeof(PurchaseInteraction), "GetInteractability")]
		private static class InteractabilityRedirect
		{
			private static bool Prefix(PurchaseInteraction __instance, Interactor activator, ref Interactability __result)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Expected I4, but got Unknown
				FlockPrinter flockPrinter = default(FlockPrinter);
				if (!((Component)__instance).TryGetComponent<FlockPrinter>(ref flockPrinter))
				{
					return true;
				}
				__result = (Interactability)(int)flockPrinter.GetInteractability(activator);
				return false;
			}
		}

		[HarmonyPatch(typeof(PickupPickerController), "GetInteractability")]
		private static class SuppressSecondInteraction
		{
			private static void Postfix(PickupPickerController __instance, ref Interactability __result)
			{
				if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<FlockPrinter>()))
				{
					__result = (Interactability)0;
				}
			}
		}

		[HarmonyPatch(typeof(PurchaseInteraction), "OnInteractionBegin")]
		private static class OpenPicker
		{
			private static bool Prefix(PurchaseInteraction __instance, Interactor activator)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Invalid comparison between Unknown and I4
				FlockPrinter flockPrinter = default(FlockPrinter);
				if (!((Component)__instance).TryGetComponent<FlockPrinter>(ref flockPrinter))
				{
					return true;
				}
				if (NetworkServer.active && (int)flockPrinter.GetInteractability(activator) == 2)
				{
					flockPrinter.Open(activator);
					if (Object.op_Implicit((Object)(object)flockPrinter.participant))
					{
						((Component)__instance).GetComponent<NetworkUIPromptController>().SetParticipantMaster(flockPrinter.participant);
					}
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(PurchaseInteraction), "GetContextString")]
		private static class Context
		{
			private static bool Prefix(PurchaseInteraction __instance, ref string __result)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				FlockPrinter flockPrinter = default(FlockPrinter);
				if (!((Component)__instance).TryGetComponent<FlockPrinter>(ref flockPrinter))
				{
					return true;
				}
				ItemDef val = ItemFor(((Component)flockPrinter).GetComponent<ShopTerminalBehavior>().CurrentPickup().pickupIndex);
				__result = (Object.op_Implicit((Object)(object)val) ? Settings.Text("Print for the flock: " + Language.GetString(val.nameToken), "Печатать для стаи: " + Language.GetString(val.nameToken)) : Settings.Text("Flock printer", "Принтер стаи"));
				return false;
			}
		}

		[HarmonyPatch(typeof(PickupPickerController), "HandlePickupSelected")]
		private static class Selection
		{
			private static bool Prefix(PickupPickerController __instance, int choiceIndex)
			{
				FlockPrinter flockPrinter = default(FlockPrinter);
				if (!NetworkServer.active || !((Component)__instance).TryGetComponent<FlockPrinter>(ref flockPrinter))
				{
					return true;
				}
				flockPrinter.Select(__instance, choiceIndex);
				return false;
			}
		}

		private static readonly string[] PrinterNames = new string[4] { "Duplicator", "DuplicatorLarge", "DuplicatorMilitary", "DuplicatorWild" };

		private static readonly Dictionary<GameObject, GameObject> Variants = new Dictionary<GameObject, GameObject>();

		private static Xoroshiro128Plus stageRng;

		private static bool replacedThisStage;

		private PickupIndex openedOutput = PickupIndex.none;

		private CharacterMaster participant;

		private readonly OperationGate operation = new OperationGate();

		internal static IEnumerator LoadPrefabs(GameObject egg, List<GameObject> prefabs)
		{
			PickupPickerController eggPicker = default(PickupPickerController);
			if (!egg.TryGetComponent<PickupPickerController>(ref eggPicker))
			{
				yield break;
			}
			string[] printerNames = PrinterNames;
			foreach (string name in printerNames)
			{
				AsyncOperationHandle<GameObject> handle = Addressables.LoadAssetAsync<GameObject>((object)("RoR2/Base/" + name + "/" + name + ".prefab"));
				yield return handle;
				GameObject result = handle.Result;
				if (!Object.op_Implicit((Object)(object)result))
				{
					Plugin.Log("Could not load flock printer source " + name);
					continue;
				}
				GameObject val = PrefabAPI.InstantiateClone(result, "LemurTeamFlock" + name, false);
				val.GetComponent<PurchaseInteraction>().costType = (CostTypeIndex)0;
				val.AddComponent<FlockPrinter>();
				PickupPickerController obj = val.AddComponent<PickupPickerController>();
				obj.panelPrefab = eggPicker.panelPrefab;
				obj.cutoffDistance = eggPicker.cutoffDistance;
				obj.allowRemoteOpInteraction = false;
				obj.canUseRentalItems = false;
				obj.canUseTemporaryItems = false;
				SpecialTextures.Apply(val, isEgg: false);
				prefabs.Add(val);
				Variants.Add(result, val);
			}
		}

		internal static void BeginPopulation()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			replacedThisStage = false;
			stageRng = new Xoroshiro128Plus(Run.instance.seed ^ (ulong)Run.instance.stageClearCount ^ 0xF10C7);
		}

		internal static void EndPopulation()
		{
			stageRng = null;
		}

		private static ItemDef ItemFor(PickupIndex index)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			PickupDef pickupDef = PickupCatalog.GetPickupDef(index);
			if (pickupDef == null || (int)pickupDef.itemIndex == -1)
			{
				return null;
			}
			return ItemCatalog.GetItemDef(pickupDef.itemIndex);
		}

		private static bool ValidItem(ItemDef item)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)item) && item.canRemove && !item.hidden && !item.ContainsTag((ItemTag)13) && !item.ContainsTag((ItemTag)23))
			{
				return !EggItemTiers.IsRestricted(item.itemIndex);
			}
			return false;
		}

		private void Open(Interactor activator)
		{
			//IL_003a: 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_0044: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
			participant = ((Object.op_Implicit((Object)(object)component) && component.isPlayerControlled && component.healthComponent.alive) ? component.master : null);
			openedOutput = ((Component)this).GetComponent<ShopTerminalBehavior>().CurrentPickup().pickupIndex;
			ItemDef val = ItemFor(openedOutput);
			Inventory pool = SharedInventory.Pool;
			List<Option> list = new List<Option>();
			if (Object.op_Implicit((Object)(object)participant) && Object.op_Implicit((Object)(object)pool) && ValidItem(val))
			{
				foreach (ItemIndex item in pool.itemAcquisitionOrder)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(item);
					if (ValidPayment(itemDef, val) && pool.GetItemCountPermanent(item) > 0 && SharedInventory.Contributions(((Object)itemDef).name).Any())
					{
						PickupIndex val2 = PickupCatalog.FindPickupIndex(item);
						if (val2 != PickupIndex.none)
						{
							list.Add(new Option
							{
								available = true,
								pickup = new UniquePickup(val2)
							});
						}
					}
				}
			}
			((Component)this).GetComponent<PickupPickerController>().SetOptionsServer(list.ToArray());
		}

		private static bool ValidPayment(ItemDef input, ItemDef output)
		{
			//IL_001a: 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)
			if (ValidItem(input) && ValidItem(output) && (Object)(object)input != (Object)(object)output)
			{
				return input.tier == output.tier;
			}
			return false;
		}

		private void Select(PickupPickerController picker, int choice)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			NetworkUIPromptController component = ((Component)this).GetComponent<NetworkUIPromptController>();
			CharacterMaster currentParticipantMaster = component.currentParticipantMaster;
			CharacterBody body = (Object.op_Implicit((Object)(object)currentParticipantMaster) ? currentParticipantMaster.GetBody() : null);
			if (operation.Pending || (Object)(object)currentParticipantMaster != (Object)(object)participant || !InteractionOperation.ValidParticipant(picker, body) || (uint)choice >= picker.options.Length || !picker.options[choice].available)
			{
				return;
			}
			PickupIndex pickupIndex = ((Component)this).GetComponent<ShopTerminalBehavior>().CurrentPickup().pickupIndex;
			if (pickupIndex != openedOutput)
			{
				return;
			}
			ItemDef input = ItemFor(picker.options[choice].pickup.pickupIndex);
			ItemDef output = ItemFor(pickupIndex);
			if (!ValidPayment(input, output) || !operation.TryBegin())
			{
				return;
			}
			try
			{
				if (SharedInventory.TryPrint(input, output, currentParticipantMaster))
				{
					participant = null;
					component.ClearParticipant();
				}
			}
			finally
			{
				operation.Finish();
			}
		}

		private Interactability GetInteractability(Interactor activator)
		{
			if (Object.op_Implicit((Object)(object)activator) && !activator.isRemoteOp && ((Component)this).GetComponent<PickupPickerController>().available)
			{
				if (((Component)this).GetComponent<NetworkUIPromptController>().inUse)
				{
					return (Interactability)1;
				}
				return (Interactability)2;
			}
			return (Interactability)0;
		}
	}
	internal static class Followers
	{
		[HarmonyPatch(typeof(DevotedLemurianController), "Start")]
		private static class ReplaceLeash
		{
			private static bool Prefix()
			{
				return false;
			}
		}

		[HarmonyPatch(typeof(HealthComponent), "TakeDamage")]
		private static class VoidDamage
		{
			private static bool Prefix(HealthComponent __instance, DamageInfo damageInfo)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				if (Plugin.VoidProtection.Value && IsDevoted(__instance.body) && DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)65536)) != 0L)
				{
					damageInfo.rejected = true;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(HealthComponent), "Suicide", new Type[]
		{
			typeof(GameObject),
			typeof(GameObject),
			typeof(DamageTypeCombo)
		})]
		private static class VoidSuicide
		{
			private static bool Prefix(HealthComponent __instance, DamageTypeCombo damageType)
			{
				//IL_0019: 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_0024: Unknown result type (might be due to invalid IL or missing references)
				if (Plugin.VoidProtection.Value && IsDevoted(__instance.body))
				{
					return DamageTypeCombo.op_Implicit(damageType & DamageTypeCombo.op_Implicit((DamageType)65536)) == 0;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Infest), "FixedUpdate")]
		private static class Infestation
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				List<CodeInstruction> list = instructions.ToList();
				FieldInfo flags = AccessTools.Field(typeof(CharacterBody), "bodyFlags");
				CodeInstruction[] array = list.Where((CodeInstruction instruction) => CodeInstructionExtensions.LoadsField(instruction, flags, false)).ToArray();
				if (array.Length != 1)
				{
					throw new InvalidOperationException("Expected one body flags check in the Void Infestor attack.");
				}
				array[0].opcode = OpCodes.Call;
				array[0].operand = AccessTools.Method(typeof(Infestation), "GetInfestationFlags", (Type[])null, (Type[])null);
				return list;
			}

			private static BodyFlags GetInfestationFlags(CharacterBody body)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: 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)
				if (!Plugin.InfestationProtection.Value || !IsDevoted(body))
				{
					return body.bodyFlags;
				}
				return (BodyFlags)(body.bodyFlags | 2);
			}
		}

		internal static bool IsDevoted(CharacterBody body)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.master) && (int)body.teamComponent.teamIndex == 1)
			{
				if (!NetworkServer.active)
				{
					return Object.op_Implicit((Object)(object)((Component)body.master).GetComponent<DevotedLemurianController>());
				}
				return PetRegistry.Owns(body.master);
			}
			return false;
		}

		internal static bool IsAlliedMob(CharacterBody body)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.teamComponent) && (int)body.teamComponent.teamIndex == 1)
			{
				return !body.isPlayerControlled;
			}
			return false;
		}

		internal static bool IsAlliedMob(CharacterBody player, CharacterBody body)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			if (IsAlliedMob(body) && Object.op_Implicit((Object)(object)player.teamComponent))
			{
				return (int)player.teamComponent.teamIndex == 1;
			}
			return false;
		}

		private static CharacterBody NearestPlayer(CharacterBody[] players, Vector3 position)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			CharacterBody result = null;
			float num = float.PositiveInfinity;
			foreach (CharacterBody val in players)
			{
				Vector3 val2 = val.corePosition - position;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (!(sqrMagnitude >= num))
				{
					num = sqrMagnitude;
					result = val;
				}
			}
			return result;
		}

		internal static void Tick()
		{
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody[] players = (from x in PlayerCharacterMasterController.instances
				select (!Object.op_Implicit((Object)(object)x.master)) ? null : x.master.GetBody() into x
				where Object.op_Implicit((Object)(object)x) && x.healthComponent.alive
				select x).ToArray();
			bool isCurrentStage = VoidFields.IsCurrentStage;
			Vector3 val5 = default(Vector3);
			foreach (DevotedLemurianController minion in SharedInventory.Minions)
			{
				CharacterMaster component = ((Component)minion).GetComponent<CharacterMaster>();
				CharacterBody val = component.GetBody();
				if (!Object.op_Implicit((Object)(object)val) && isCurrentStage)
				{
					val = VoidFields.RestorePet(minion, component, players);
				}
				if (!Object.op_Implicit((Object)(object)val) || !val.healthComponent.alive)
				{
					continue;
				}
				Heresy.CheckTransformation(component, val);
				val = component.GetBody();
				if (!Object.op_Implicit((Object)(object)val) || !val.healthComponent.alive)
				{
					continue;
				}
				if (minion.DevotedEvolutionLevel > 0)
				{
					LemurProgress.For(minion).ApplyAspects(minion);
				}
				CharacterMaster ownerMaster = component.minionOwnership.ownerMaster;
				CharacterBody val2 = (Object.op_Implicit((Object)(object)ownerMaster) ? ownerMaster.GetBody() : null);
				if (!Object.op_Implicit((Object)(object)val2) || !val2.healthComponent.alive)
				{
					val2 = NearestPlayer(players, val.corePosition);
				}
				if (!Object.op_Implicit((Object)(object)val2))
				{
					continue;
				}
				BaseAI[] components = ((Component)component).GetComponents<BaseAI>();
				for (int num = 0; num < components.Length; num++)
				{
					components[num].leader.gameObject = ((Component)val2).gameObject;
				}
				Vector3 val3 = val2.corePosition - val.corePosition;
				if (((Vector3)(ref val3)).sqrMagnitude <= Plugin.LeashDistance.Value * Plugin.LeashDistance.Value || !Object.op_Implicit((Object)(object)SceneInfo.instance))
				{
					continue;
				}
				NodeGraph val4 = SceneInfo.instance.GetNodeGraph((GraphType)(val.isFlying ? 1 : 0)) ?? SceneInfo.instance.GetNodeGraph((GraphType)0);
				if (!Object.op_Implicit((Object)(object)val4))
				{
					continue;
				}
				foreach (NodeIndex item in from x in val4.FindNodesInRangeWithFlagConditions(val2.corePosition, 3f, 20f, (HullMask)0, (NodeFlags)0, (NodeFlags)4, false)
					orderby Random.value
					select x)
				{
					if (val4.GetNodePosition(item, ref val5))
					{
						TeleportBodyArgs val6 = default(TeleportBodyArgs);
						((TeleportBodyArgs)(ref val6)).body = val;
						val6.targetPosition = val5;
						val6.targetRotation = ((Component)val).transform.rotation;
						val6.forceOutOfVehicle = true;
						val6.teleportMinions = false;
						TeleportHelper.TeleportBody(val6);
						GameObject teleportEffectPrefab = Run.instance.GetTeleportEffectPrefab(((Component)val).gameObject);
						if (Object.op_Implicit((Object)(object)teleportEffectPrefab))
						{
							EffectManager.SimpleEffect(teleportEffectPrefab, val5, Quaternion.identity, true);
						}
						break;
					}
				}
			}
		}
	}
	internal static class GroundProtection
	{
		[HarmonyPatch(typeof(HealthComponent), "TakeDamageProcess")]
		private static class HazardDamage
		{
			private static void Prefix(HealthComponent __instance, DamageInfo damageInfo, out DamageTypeCombo? __state)
			{
				//IL_004a: 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_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				__state = null;
				if (Plugin.GroundProtection.Value && Followers.IsDevoted(__instance.body) && (IsGroundHazard(damageInfo.inflictor) || (!Object.op_Implicit((Object)(object)damageInfo.attacker) && (Object)(object)clayFloorVictim == (Object)(object)__instance)))
				{
					__state = damageInfo.damageType;
					damageInfo.damageType |= Dam