Decompiled source of MinionMeld v1.1.5

MinionMeld.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Drone;
using IL.RoR2;
using KinematicCharacterController;
using Microsoft.CodeAnalysis;
using MinionMeld.Components;
using MinionMeld.Modules;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.EntityStates.Drone;
using On.RoR2;
using R2API;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Navigation;
using UnityEngine;
using UnityEngine.Networking;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MinionMeld
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

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

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

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

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

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

		internal static void Warning(string data)
		{
			_logSource.LogWarning((object)data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.score.MinionMeld", "MinionMeld", "1.1.5")]
	public class MinionMeldPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.score.MinionMeld";

		public const string PluginAuthor = "score";

		public const string PluginName = "MinionMeld";

		public const string PluginVersion = "1.1.5";

		public static ItemDef meldStackItem;

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

		public static MinionMeldPlugin Instance { get; private set; }

		public void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			PluginConfig.Init(((BaseUnityPlugin)this).Config);
			meldStackItem = ScriptableObject.CreateInstance<ItemDef>();
			meldStackItem.deprecatedTier = (ItemTier)5;
			meldStackItem.canRemove = true;
			meldStackItem.hidden = true;
			meldStackItem.nameToken = "ITEM_MINIONMELD_STACK_NAME";
			meldStackItem.loreToken = "";
			meldStackItem.descriptionToken = "";
			meldStackItem.pickupToken = "";
			((Object)meldStackItem).name = "MinionMeldInternalStackItem";
			meldStackItem.tags = (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)11,
				(ItemTag)12
			};
			ContentAddition.AddItemDef(meldStackItem);
			Hooks.Init();
			TurretHooks.Init();
			MultiEquipDrone.Init();
		}
	}
	public static class PluginConfig
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Init <0>__MasterCatalog_Init;
		}

		public const string permaBlackList = "DevotedLemurianMaster,DevotedLemurianBruiserMaster,NemMercCloneMaster,";

		public static ConfigFile myConfig;

		public static ConfigEntry<bool> perPlayer;

		public static ConfigEntry<bool> teleturret;

		public static ConfigEntry<bool> respawnSummon;

		public static ConfigEntry<int> maxDronesPerType;

		public static ConfigEntry<bool> enableTurretLeash;

		public static ConfigEntry<int> minionLeashRange;

		public static ConfigEntry<MeldingTime.DronemeldPriorityOrder> priorityOrder;

		public static ConfigEntry<int> statMultHealth;

		public static ConfigEntry<int> statMultDamage;

		public static ConfigEntry<int> statMultAttackSpeed;

		public static ConfigEntry<int> statMultCDR;

		public static ConfigEntry<int> vfxResize;

		public static ConfigEntry<string> blacklistMasters;

		public static ConfigEntry<string> blacklistTurrets;

		public static ConfigEntry<bool> printMasterNames;

		public static ConfigEntry<bool> useWhitelist;

		public static ConfigEntry<string> whitelistMasters;

		public static ConfigEntry<string> whitelistTurrets;

		public static HashSet<MasterIndex> MasterBlacklist { get; } = new HashSet<MasterIndex>();


		public static HashSet<MasterIndex> TurretBlacklist { get; } = new HashSet<MasterIndex>();


		public static HashSet<MasterIndex> MasterWhitelist { get; } = new HashSet<MasterIndex>();


		public static HashSet<MasterIndex> TurretWhitelist { get; } = new HashSet<MasterIndex>();


		private static void RebuildBlacklist(HashSet<MasterIndex> list, string option)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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)
			list.Clear();
			if (string.IsNullOrEmpty(option?.Replace(" ", string.Empty)))
			{
				return;
			}
			string[] array = option.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				if (!string.IsNullOrEmpty(array[i]))
				{
					string text = array[i].Replace("(Clone)", string.Empty);
					MasterIndex val = MasterCatalog.FindMasterIndex(text);
					if (val == MasterIndex.none)
					{
						val = MasterCatalog.FindMasterIndex(text + "Master");
					}
					if (val != MasterIndex.none)
					{
						list.Add(val);
					}
				}
			}
		}

		public static void Init(ConfigFile cfg)
		{
			//IL_0229: 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_0234: Expected O, but got Unknown
			string section = "Stats";
			string section2 = "BlackList";
			string section3 = "WhiteList";
			myConfig = cfg;
			perPlayer = BindOption("General", "Limit Drones Per Player", defaultValue: true, "If false, then the team's collective drones will be limited");
			teleturret = BindOption("General", "Teleporting Turrets", defaultValue: true, "Turrets, Squids, etc (anything immobile) remember their previous spawn locations and follow when you start a scripted combat event (teleporter, mithrix etc)");
			respawnSummon = BindOption("General", "Spawn In New Location", defaultValue: true, "Summoned allies will 'respawn' in the location that that they are summoned.");
			maxDronesPerType = BindOptionSlider("General", "Max Minions Per Type", 1, "Max Number of Minions you (or your team) can control of that type before melding is applied.", 1f);
			enableTurretLeash = BindOption("General", "Enable Turret Leash", defaultValue: true, "Allows turrets to teleport to their owner when too far.");
			minionLeashRange = BindOptionSlider("General", "Minion Leash Range", 200, "Max distance a minion should be from their owner before teleporting. Applies to turrets.", 50f, 1000f);
			priorityOrder = BindOption("General", "Selection Priority", MeldingTime.DronemeldPriorityOrder.RoundRobin, "Used for deciding which drone should be selected for melding.");
			statMultHealth = BindOptionSlider(section, "Health Multiplier", 20, "Stacks additively.", 0f, 200f);
			statMultDamage = BindOptionSlider(section, "Damage Multiplier", 20, "Stacks additively.", 0f, 200f);
			statMultAttackSpeed = BindOptionSlider(section, "Attack Speed Multiplier", 20, "Stacks additively.", 0f, 200f);
			statMultCDR = BindOptionSlider(section, "Cooldown Reduction Multiplier", 20, "Stacks additively.", 0f, 200f);
			vfxResize = BindOptionSlider(section, "Size Multiplier", 20, "Visual size increase per meld, in percent. Stacks additively.", 0f, 200f);
			blacklistMasters = BindOption(section2, "Blacklist", "EngiTurretMaster,EngiWalkerTurretMaster,GhoulMaster,TombstoneMaster", "Put the broken shit in here, or just things you want duplicates of. For Devotion Artifact, download LemurFusion.\r\nTo find these, download the DebugToolKit mod, open the console (Ctrl Alt ~), then type list_ai or enable the print option below.");
			blacklistTurrets = BindOption(section2, "Blacklist Teleporting Turret", "", "Makes teleporting turret component unable to be applied to these guys. Typically applied to characters without the ability to move on their own.");
			printMasterNames = BindOption(section2, "Print Master Names To Console", defaultValue: true, "Prints the name to the console (Ctrl Alt ~) when preforming a successful meld. Helpful for setting up the blacklist.");
			useWhitelist = BindOption(section3, "Use Whitelist", defaultValue: false, "Use a custom whitelist of allowed CharacterMaster names instead of the default blacklist.");
			whitelistMasters = BindOption(section3, "Whitelist", "", "CharacterMaster names that should be allowed to meld. Teleporting turrets will not be affected by this list.");
			whitelistTurrets = BindOption(section3, "Whitelist Teleporting Turret", "", "CharacterMaster names of the immobile turret-like allies that should teleport around with you during combat events.");
			object obj = <>O.<0>__MasterCatalog_Init;
			if (obj == null)
			{
				hook_Init val = MasterCatalog_Init;
				<>O.<0>__MasterCatalog_Init = val;
				obj = (object)val;
			}
			MasterCatalog.Init += (hook_Init)obj;
		}

		private static void MasterCatalog_Init(orig_Init orig)
		{
			orig.Invoke();
			RebuildBlacklist(MasterBlacklist, "DevotedLemurianMaster,DevotedLemurianBruiserMaster,NemMercCloneMaster," + blacklistMasters.Value);
			blacklistMasters.SettingChanged += delegate
			{
				RebuildBlacklist(MasterBlacklist, "DevotedLemurianMaster,DevotedLemurianBruiserMaster,NemMercCloneMaster," + blacklistMasters.Value);
			};
			RebuildBlacklist(TurretBlacklist, blacklistTurrets.Value);
			blacklistTurrets.SettingChanged += delegate
			{
				RebuildBlacklist(TurretBlacklist, blacklistTurrets.Value);
			};
			RebuildBlacklist(MasterWhitelist, whitelistMasters.Value);
			whitelistMasters.SettingChanged += delegate
			{
				RebuildBlacklist(MasterWhitelist, whitelistMasters.Value);
			};
			RebuildBlacklist(TurretWhitelist, whitelistTurrets.Value);
			whitelistTurrets.SettingChanged += delegate
			{
				RebuildBlacklist(TurretWhitelist, whitelistTurrets.Value);
			};
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static ConfigEntry<T> BindOption<T>(string section, string name, T defaultValue, string description = "", bool restartRequired = false)
		{
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			if (restartRequired)
			{
				description += " (restart required)";
			}
			ConfigEntry<T> val = myConfig.Bind<T>(section, name, defaultValue, description);
			if (MinionMeldPlugin.RooInstalled)
			{
				TryRegisterOption<T>(val, restartRequired);
			}
			return val;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static ConfigEntry<T> BindOptionSlider<T>(string section, string name, T defaultValue, string description = "", float min = 0f, float max = 20f, bool restartRequired = false)
		{
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			string text = description;
			T val = defaultValue;
			description = text + " (Default: " + val?.ToString() + ")";
			if (restartRequired)
			{
				description += " (restart required)";
			}
			ConfigEntry<T> val2 = myConfig.Bind<T>(section, name, defaultValue, description);
			if (MinionMeldPlugin.RooInstalled)
			{
				TryRegisterOptionSlider<T>(val2, min, max, restartRequired);
			}
			return val2;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void InitRoO()
		{
			ModSettingsManager.SetModDescription("Devotion Artifact but better.");
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void TryRegisterOption<T>(ConfigEntry<T> entry, bool restartRequired)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			if (entry is ConfigEntry<string> val)
			{
				ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(val, restartRequired));
			}
			else if (entry is ConfigEntry<float> val2)
			{
				ModSettingsManager.AddOption((BaseOption)new SliderOption(val2, new SliderConfig
				{
					min = 0f,
					max = 20f,
					FormatString = "{0:0.00}",
					restartRequired = restartRequired
				}));
			}
			else if (entry is ConfigEntry<int> val3)
			{
				ModSettingsManager.AddOption((BaseOption)new IntSliderOption(val3, restartRequired));
			}
			else if (entry is ConfigEntry<bool> val4)
			{
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(val4, restartRequired));
			}
			else if (entry is ConfigEntry<KeyboardShortcut> val5)
			{
				ModSettingsManager.AddOption((BaseOption)new KeyBindOption(val5, restartRequired));
			}
			else if (typeof(T).IsEnum)
			{
				ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)entry, restartRequired));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void TryRegisterOptionSlider<T>(ConfigEntry<T> entry, float min, float max, bool restartRequired)
		{
			//IL_000b: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0048: 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_0054: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			if (entry is ConfigEntry<int> val)
			{
				ModSettingsManager.AddOption((BaseOption)new IntSliderOption(val, new IntSliderConfig
				{
					min = (int)min,
					max = (int)max,
					formatString = "{0:0.00}",
					restartRequired = restartRequired
				}));
			}
			else if (entry is ConfigEntry<float> val2)
			{
				ModSettingsManager.AddOption((BaseOption)new SliderOption(val2, new SliderConfig
				{
					min = min,
					max = max,
					FormatString = "{0:0.00}",
					restartRequired = restartRequired
				}));
			}
		}
	}
}
namespace MinionMeld.Modules
{
	public class Hooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action<CharacterBody> <0>__CharacterBody_ResizeBody;

			public static hook_Perform <1>__MasterSummon_Perform;

			public static hook_TrySpawnObject <2>__DirectorCore_TrySpawnObject;
		}

		private const string SPAWN_STRING = "{0} | Spawning Meldable Minion: {1}";

		private const string MELD_STRING = "{0} | Performing Minion Meld: {1}";

		public static Hooks Instance { get; private set; }

		public static void Init()
		{
			if (Instance == null)
			{
				Instance = new Hooks();
			}
		}

		private Hooks()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//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_00a3: Expected O, but got Unknown
			CharacterBody.GetDisplayName += new hook_GetDisplayName(CharacterBody_GetDisplayName);
			CharacterBody.onBodyStartGlobal += CharacterBody_ResizeBody;
			CharacterBody.onBodyInventoryChangedGlobal += CharacterBody_ResizeBody;
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(RecalculateStatsAPI_GetStatCoefficients);
			object obj = <>O.<1>__MasterSummon_Perform;
			if (obj == null)
			{
				hook_Perform val = MasterSummon_Perform;
				<>O.<1>__MasterSummon_Perform = val;
				obj = (object)val;
			}
			MasterSummon.Perform += (hook_Perform)obj;
			object obj2 = <>O.<2>__DirectorCore_TrySpawnObject;
			if (obj2 == null)
			{
				hook_TrySpawnObject val2 = DirectorCore_TrySpawnObject;
				<>O.<2>__DirectorCore_TrySpawnObject = val2;
				obj2 = (object)val2;
			}
			DirectorCore.TrySpawnObject += (hook_TrySpawnObject)obj2;
		}

		private static CharacterMaster MasterSummon_Perform(orig_Perform orig, MasterSummon self)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody val = default(CharacterBody);
			if (!Object.op_Implicit((Object)(object)self.masterPrefab) || !Object.op_Implicit((Object)(object)self.summonerBodyObject) || !self.summonerBodyObject.TryGetComponent<CharacterBody>(ref val) || !Object.op_Implicit((Object)(object)val.master))
			{
				return orig.Invoke(self);
			}
			MasterIndex masterIdx = MasterCatalog.FindMasterIndex(self.masterPrefab);
			if (!MeldingTime.CanApply(masterIdx, val.teamComponent.teamIndex, self.teamIndexOverride))
			{
				return orig.Invoke(self);
			}
			if (MeldingTime.PerformMeld(masterIdx, val.master, out var newSummon))
			{
				TeleportingTurret teleportingTurret = default(TeleportingTurret);
				if (PluginConfig.teleturret.Value && newSummon.hasBody && newSummon.bodyInstanceObject.TryGetComponent<TeleportingTurret>(ref teleportingTurret))
				{
					teleportingTurret.RegisterLocation(self.position);
				}
				else if (PluginConfig.respawnSummon.Value)
				{
					TeleportHelper.TeleportBody(newSummon.GetBody(), self.position, false);
				}
				int itemCount = newSummon.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
				newSummon.inventory.CleanInventory();
				newSummon.inventory.GiveItem(MinionMeldPlugin.meldStackItem, itemCount);
				if (Object.op_Implicit((Object)(object)self.inventoryToCopy))
				{
					newSummon.inventory.CopyItemsFrom(self.inventoryToCopy, self.inventoryItemCopyFilter ?? Inventory.defaultItemCopyFilterDelegate);
				}
				IInventorySetupCallback inventorySetupCallback = self.inventorySetupCallback;
				if (inventorySetupCallback != null)
				{
					inventorySetupCallback.SetupSummonedInventory(self, newSummon.inventory);
				}
				self.preSpawnSetupCallback?.Invoke(newSummon);
				int itemCount2 = newSummon.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
				if (itemCount2 != itemCount)
				{
					newSummon.inventory.GiveItem(MinionMeldPlugin.meldStackItem, itemCount - itemCount2);
				}
				if (PluginConfig.printMasterNames.Value)
				{
					Log.Info(string.Format("{0} | Performing Minion Meld: {1}", "MasterSummon", ((Object)newSummon).name));
				}
				return newSummon;
			}
			newSummon = orig.Invoke(self);
			if (Object.op_Implicit((Object)(object)newSummon))
			{
				if (MeldingTime.CanApplyTurret(newSummon))
				{
					MeldingTime.TryAddTeleTurret(newSummon.GetBody());
				}
				if (PluginConfig.printMasterNames.Value)
				{
					Log.Info(string.Format("{0} | Spawning Meldable Minion: {1}", "MasterSummon", ((Object)newSummon).name));
				}
			}
			return newSummon;
		}

		private static GameObject DirectorCore_TrySpawnObject(orig_TrySpawnObject orig, DirectorCore self, DirectorSpawnRequest spawnReq)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody val = default(CharacterBody);
			if (!Object.op_Implicit((Object)(object)spawnReq?.spawnCard) || !Object.op_Implicit((Object)(object)spawnReq.spawnCard.prefab) || !Object.op_Implicit((Object)(object)spawnReq.summonerBodyObject) || spawnReq.placementRule == null || !spawnReq.summonerBodyObject.TryGetComponent<CharacterBody>(ref val) || !Object.op_Implicit((Object)(object)val.master))
			{
				return orig.Invoke(self, spawnReq);
			}
			MasterIndex masterIdx = MasterCatalog.FindMasterIndex(spawnReq.spawnCard.prefab);
			if (!MeldingTime.CanApply(masterIdx, val.teamComponent.teamIndex, spawnReq.teamIndexOverride))
			{
				return orig.Invoke(self, spawnReq);
			}
			if (MeldingTime.PerformMeld(masterIdx, val.master, out var newSummon))
			{
				CharacterBody body = newSummon.GetBody();
				if (Object.op_Implicit((Object)(object)body))
				{
					Vector3? val2 = MeldingTime.FindSpawnDestination(body, spawnReq.placementRule, spawnReq.rng);
					if (val2.HasValue)
					{
						TeleportingTurret teleportingTurret = default(TeleportingTurret);
						if (PluginConfig.teleturret.Value && ((Component)body).TryGetComponent<TeleportingTurret>(ref teleportingTurret))
						{
							teleportingTurret.RegisterLocation(val2.Value);
						}
						else if (PluginConfig.respawnSummon.Value)
						{
							TeleportHelper.TeleportBody(body, val2.Value, false);
						}
					}
					int itemCount = newSummon.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
					newSummon.inventory.CleanInventory();
					newSummon.inventory.GiveItem(MinionMeldPlugin.meldStackItem, itemCount);
					spawnReq.onSpawnedServer?.Invoke(new SpawnResult
					{
						spawnedInstance = ((Component)newSummon).gameObject,
						spawnRequest = spawnReq,
						position = body.footPosition,
						success = true,
						rotation = body.transform.rotation
					});
					int itemCount2 = newSummon.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
					if (itemCount2 != itemCount)
					{
						newSummon.inventory.GiveItem(MinionMeldPlugin.meldStackItem, itemCount - itemCount2);
					}
				}
				if (PluginConfig.printMasterNames.Value)
				{
					Log.Info(string.Format("{0} | Performing Minion Meld: {1}", "DirectorCore", ((Object)newSummon).name));
				}
				return ((Component)newSummon).gameObject;
			}
			GameObject val3 = orig.Invoke(self, spawnReq);
			if (Object.op_Implicit((Object)(object)val3))
			{
				newSummon = val3.GetComponent<CharacterMaster>();
				if (MeldingTime.CanApplyTurret(newSummon))
				{
					MeldingTime.TryAddTeleTurret(newSummon.GetBody());
				}
				if (PluginConfig.printMasterNames.Value)
				{
					Log.Info(string.Format("{0} | Spawning Meldable Minion: {1}", "DirectorCore", ((Object)val3).name));
				}
			}
			return val3;
		}

		private static void CharacterBody_ResizeBody(CharacterBody body)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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)
			if (PluginConfig.vfxResize.Value <= 0 || !NetworkClient.active || !Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)body.inventory))
			{
				return;
			}
			int itemCount = body.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
			if (itemCount > 0 && Object.op_Implicit((Object)(object)body.modelLocator) && Object.op_Implicit((Object)(object)body.modelLocator.modelTransform))
			{
				GameObject bodyPrefab = BodyCatalog.GetBodyPrefab(body.bodyIndex);
				ModelLocator val = (Object.op_Implicit((Object)(object)bodyPrefab) ? bodyPrefab.GetComponent<ModelLocator>() : null);
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.modelTransform))
				{
					Vector3 localScale = val.modelTransform.localScale;
					float num = (float)itemCount * ((float)PluginConfig.vfxResize.Value * 0.01f);
					body.modelLocator.modelTransform.localScale = localScale + localScale * num;
				}
			}
		}

		private string CharacterBody_GetDisplayName(orig_GetDisplayName orig, CharacterBody self)
		{
			string text = orig.Invoke(self);
			if (Object.op_Implicit((Object)(object)self.inventory))
			{
				int itemCount = self.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
				if (itemCount > 0)
				{
					return $"{text} <style=cStack>x{itemCount + 1}</style>";
				}
			}
			return text;
		}

		private void RecalculateStatsAPI_GetStatCoefficients(CharacterBody sender, StatHookEventArgs args)
		{
			if (Object.op_Implicit((Object)(object)sender) && Object.op_Implicit((Object)(object)sender.master) && Object.op_Implicit((Object)(object)sender.master.inventory))
			{
				int itemCount = sender.master.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
				if (itemCount > 0)
				{
					args.baseHealthAdd += (sender.baseMaxHealth + sender.levelMaxHealth * sender.level) * (float)itemCount * (float)PluginConfig.statMultHealth.Value * 0.01f;
					args.baseDamageAdd += (sender.baseDamage + sender.levelDamage * sender.level) * (float)itemCount * (float)PluginConfig.statMultDamage.Value * 0.01f;
					args.baseAttackSpeedAdd += (sender.baseAttackSpeed + sender.levelAttackSpeed * sender.level) * (float)itemCount * (float)PluginConfig.statMultAttackSpeed.Value * 0.01f;
					args.cooldownMultAdd -= Util.ConvertAmplificationPercentageIntoReductionNormalized((float)(itemCount * PluginConfig.statMultCDR.Value) * 0.01f);
				}
			}
		}
	}
	public static class MeldingTime
	{
		public enum DronemeldPriorityOrder
		{
			RoundRobin,
			Random,
			FirstOnly
		}

		public static CharacterMaster ApplyPerPlayer(MasterIndex masterIdx, CharacterMaster summonerMaster)
		{
			//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)
			//IL_003b: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			List<CharacterMaster> list = new List<CharacterMaster>();
			DronemeldPriorityOrder value = PluginConfig.priorityOrder.Value;
			NetworkInstanceId netId = ((NetworkBehaviour)summonerMaster).netId;
			if (Object.op_Implicit((Object)(object)summonerMaster.minionOwnership.ownerMaster))
			{
				netId = ((NetworkBehaviour)summonerMaster.minionOwnership.ownerMaster).netId;
			}
			MinionGroup val = MinionGroup.FindGroup(netId);
			if (val != null)
			{
				MinionOwnership[] members = val.members;
				foreach (MinionOwnership val2 in members)
				{
					if (!Object.op_Implicit((Object)(object)val2))
					{
						continue;
					}
					CharacterMaster component = ((Component)val2).GetComponent<CharacterMaster>();
					if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.inventory) && component.masterIndex == masterIdx)
					{
						if (value == DronemeldPriorityOrder.FirstOnly)
						{
							return component;
						}
						list.Add(component);
					}
				}
			}
			if (list.Any() && list.Count >= PluginConfig.maxDronesPerType.Value)
			{
				return (CharacterMaster)(value switch
				{
					DronemeldPriorityOrder.RoundRobin => list.OrderBy((CharacterMaster m) => m.inventory.GetItemCount(MinionMeldPlugin.meldStackItem)).FirstOrDefault(), 
					DronemeldPriorityOrder.Random => list.ElementAtOrDefault(Random.Range(0, list.Count)), 
					_ => null, 
				});
			}
			return null;
		}

		public static CharacterMaster ApplyGlobal(MasterIndex masterIdx)
		{
			//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)
			List<CharacterMaster> list = new List<CharacterMaster>();
			DronemeldPriorityOrder value = PluginConfig.priorityOrder.Value;
			foreach (TeamComponent teamMember in TeamComponent.GetTeamMembers((TeamIndex)1))
			{
				if (!Object.op_Implicit((Object)(object)teamMember) || !Object.op_Implicit((Object)(object)teamMember.body))
				{
					continue;
				}
				CharacterMaster master = teamMember.body.master;
				if (Object.op_Implicit((Object)(object)master) && Object.op_Implicit((Object)(object)master.inventory) && master.masterIndex == masterIdx)
				{
					if (value == DronemeldPriorityOrder.FirstOnly)
					{
						return master;
					}
					list.Add(master);
				}
			}
			if (list.Any() && list.Count >= PluginConfig.maxDronesPerType.Value)
			{
				return (CharacterMaster)(value switch
				{
					DronemeldPriorityOrder.RoundRobin => list.OrderBy((CharacterMaster m) => m.inventory.GetItemCount(MinionMeldPlugin.meldStackItem)).FirstOrDefault(), 
					DronemeldPriorityOrder.Random => list.ElementAtOrDefault(Random.Range(0, list.Count)), 
					_ => null, 
				});
			}
			return null;
		}

		public static bool CanApply(MasterIndex masterIdx, TeamIndex summonerTeam, TeamIndex? teamIndexOverride)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_0040: 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)
			if (masterIdx != MasterIndex.none && (int)(teamIndexOverride.HasValue ? teamIndexOverride.Value : summonerTeam) == 1)
			{
				if (PluginConfig.useWhitelist.Value)
				{
					return PluginConfig.MasterWhitelist.Contains(masterIdx);
				}
				return !PluginConfig.MasterBlacklist.Contains(masterIdx);
			}
			return false;
		}

		public static bool CanApplyTurret(CharacterMaster master)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (PluginConfig.teleturret.Value && Object.op_Implicit((Object)(object)master) && (int)master.teamIndex == 1 && master.masterIndex != MasterIndex.none)
			{
				if (PluginConfig.useWhitelist.Value)
				{
					return PluginConfig.TurretWhitelist.Contains(master.masterIndex);
				}
				if (!PluginConfig.MasterBlacklist.Contains(master.masterIndex))
				{
					return !PluginConfig.TurretBlacklist.Contains(master.masterIndex);
				}
				return false;
			}
			return false;
		}

		public static bool PerformMeld(MasterIndex masterIdx, CharacterMaster summonerMaster, out CharacterMaster newSummon)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			newSummon = (PluginConfig.perPlayer.Value ? ApplyPerPlayer(masterIdx, summonerMaster) : ApplyGlobal(masterIdx));
			if (Object.op_Implicit((Object)(object)newSummon))
			{
				newSummon.inventory.GiveItem(MinionMeldPlugin.meldStackItem, 1);
				MasterSuicideOnTimer val = default(MasterSuicideOnTimer);
				if (((Component)newSummon).TryGetComponent<MasterSuicideOnTimer>(ref val))
				{
					((Component)newSummon).gameObject.AddComponent<TimedMeldStack>().Activate(val.lifeTimer - val.timer);
					Object.Destroy((Object)(object)val);
				}
				int itemCount = newSummon.inventory.GetItemCount(Items.HealthDecay);
				if (itemCount > 0)
				{
					CharacterBody body = newSummon.GetBody();
					if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent))
					{
						((Component)newSummon).gameObject.AddComponent<TimedMeldStack>().Activate((float)itemCount * body.healthComponent.combinedHealthFraction);
						int num = 1 + newSummon.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
						body.healthComponent.HealFraction(1f / (float)num, default(ProcChainMask));
					}
				}
			}
			return (Object)(object)newSummon != (Object)null;
		}

		public static void TryAddTeleTurret(CharacterBody body)
		{
			if (PluginConfig.teleturret.Value && Object.op_Implicit((Object)(object)body) && !Object.op_Implicit((Object)(object)((Component)body).GetComponent<TeleportingTurret>()) && ((!Object.op_Implicit((Object)(object)body.characterMotor) && !Object.op_Implicit((Object)(object)((Component)body).GetComponent<KinematicCharacterMotor>()) && !Object.op_Implicit((Object)(object)((Component)body).GetComponent<RigidbodyMotor>())) || body.baseMoveSpeed <= 0f))
			{
				((Component)body).gameObject.AddComponent<TeleportingTurret>();
			}
		}

		public static Vector3? FindSpawnDestination(CharacterBody characterBodyOrPrefabComponent, DirectorPlacementRule rule, Xoroshiro128Plus rng)
		{
			//IL_000f: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			Vector3? result = null;
			SpawnCard obj = ScriptableObject.CreateInstance<SpawnCard>();
			obj.hullSize = characterBodyOrPrefabComponent.hullClassification;
			obj.nodeGraphType = (GraphType)0;
			obj.prefab = LegacyResourcesAPI.Load<GameObject>("SpawnCards/HelperPrefab");
			DirectorSpawnRequest val = new DirectorSpawnRequest(obj, rule, rng);
			GameObject val2 = DirectorCore.instance.TrySpawnObject(val);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				if ((int)val.placementRule.placementMode < 2)
				{
					val.placementRule.placementMode = (PlacementMode)2;
					val2 = DirectorCore.instance.TrySpawnObject(val);
				}
				if (!Object.op_Implicit((Object)(object)val2))
				{
					val.placementRule.placementMode = (PlacementMode)5;
					val2 = DirectorCore.instance.TrySpawnObject(val);
				}
			}
			if (Object.op_Implicit((Object)(object)val2))
			{
				result = val2.transform.position;
				Object.Destroy((Object)(object)val2);
			}
			Object.Destroy((Object)(object)obj);
			return result;
		}
	}
	public class TurretHooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_OnImpactServer <0>__DeathState_OnImpactServer;

			public static hook_Respawn <1>__CharacterMaster_Respawn;

			public static hook_DrainConditionMet <2>__HalcyoniteShrineInteractable_DrainConditionMet;

			public static hook_OnEnable <3>__HoldoutZoneController_OnEnable;

			public static hook_BeginEncounter <4>__ScriptedCombatEncounter_BeginEncounter;
		}

		public static TurretHooks Instance { get; private set; }

		public static void Init()
		{
			if (Instance == null)
			{
				Instance = new TurretHooks();
			}
		}

		private TurretHooks()
		{
			//IL_0016: 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_0021: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0056: 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: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			object obj = <>O.<0>__DeathState_OnImpactServer;
			if (obj == null)
			{
				hook_OnImpactServer val = DeathState_OnImpactServer;
				<>O.<0>__DeathState_OnImpactServer = val;
				obj = (object)val;
			}
			DeathState.OnImpactServer += (hook_OnImpactServer)obj;
			object obj2 = <>O.<1>__CharacterMaster_Respawn;
			if (obj2 == null)
			{
				hook_Respawn val2 = CharacterMaster_Respawn;
				<>O.<1>__CharacterMaster_Respawn = val2;
				obj2 = (object)val2;
			}
			CharacterMaster.Respawn += (hook_Respawn)obj2;
			object obj3 = <>O.<2>__HalcyoniteShrineInteractable_DrainConditionMet;
			if (obj3 == null)
			{
				hook_DrainConditionMet val3 = HalcyoniteShrineInteractable_DrainConditionMet;
				<>O.<2>__HalcyoniteShrineInteractable_DrainConditionMet = val3;
				obj3 = (object)val3;
			}
			HalcyoniteShrineInteractable.DrainConditionMet += (hook_DrainConditionMet)obj3;
			object obj4 = <>O.<3>__HoldoutZoneController_OnEnable;
			if (obj4 == null)
			{
				hook_OnEnable val4 = HoldoutZoneController_OnEnable;
				<>O.<3>__HoldoutZoneController_OnEnable = val4;
				obj4 = (object)val4;
			}
			HoldoutZoneController.OnEnable += (hook_OnEnable)obj4;
			object obj5 = <>O.<4>__ScriptedCombatEncounter_BeginEncounter;
			if (obj5 == null)
			{
				hook_BeginEncounter val5 = ScriptedCombatEncounter_BeginEncounter;
				<>O.<4>__ScriptedCombatEncounter_BeginEncounter = val5;
				obj5 = (object)val5;
			}
			ScriptedCombatEncounter.BeginEncounter += (hook_BeginEncounter)obj5;
		}

		private static CharacterBody CharacterMaster_Respawn(orig_Respawn orig, CharacterMaster self, Vector3 footPosition, Quaternion rotation, bool wasRevivedMidStage)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody val = orig.Invoke(self, footPosition, rotation, wasRevivedMidStage);
			if (MeldingTime.CanApplyTurret(self))
			{
				MeldingTime.TryAddTeleTurret(val);
			}
			return val;
		}

		private static void HalcyoniteShrineInteractable_DrainConditionMet(orig_DrainConditionMet orig, HalcyoniteShrineInteractable self)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!NetworkServer.active)
			{
				return;
			}
			foreach (TeleportingTurret instances in TeleportingTurret.instancesList)
			{
				instances.CreateTeleportNode(((Component)self).transform.position);
			}
		}

		private static void HoldoutZoneController_OnEnable(orig_OnEnable orig, HoldoutZoneController self)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!NetworkServer.active)
			{
				return;
			}
			foreach (TeleportingTurret instances in TeleportingTurret.instancesList)
			{
				instances.CreateTeleportNode(((Component)self).transform.position);
			}
		}

		private static void ScriptedCombatEncounter_BeginEncounter(orig_BeginEncounter orig, ScriptedCombatEncounter self)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!NetworkServer.active)
			{
				return;
			}
			foreach (TeleportingTurret instances in TeleportingTurret.instancesList)
			{
				instances.CreateTeleportNode(((Component)self).transform.position);
			}
		}

		private static void DeathState_OnImpactServer(orig_OnImpactServer orig, DeathState self, Vector3 contactPoint)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, contactPoint);
			CharacterMaster val = (Object.op_Implicit((Object)(object)((EntityState)self).characterBody) ? ((EntityState)self).characterBody.master : null);
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.inventory))
			{
				int itemCount = val.inventory.GetItemCount(MinionMeldPlugin.meldStackItem);
				for (int i = 0; i < itemCount; i++)
				{
					orig.Invoke(self, contactPoint);
				}
			}
		}
	}
}
namespace MinionMeld.Components
{
	public class MultiEquipDrone
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action<EquipmentSlot, EquipmentIndex> <0>__ActivateAllEquipment;

			public static hook_SetEquipment <1>__Inventory_SetEquipment;
		}

		public static MultiEquipDrone Instance { get; private set; }

		public static void Init()
		{
			if (Instance == null)
			{
				Instance = new MultiEquipDrone();
			}
		}

		private MultiEquipDrone()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			EquipmentSlot.onServerEquipmentActivated += ActivateAllEquipment;
			CharacterBody.OnInventoryChanged += new Manipulator(CharacterBody_OnInventoryChanged);
			object obj = <>O.<1>__Inventory_SetEquipment;
			if (obj == null)
			{
				hook_SetEquipment val = Inventory_SetEquipment;
				<>O.<1>__Inventory_SetEquipment = val;
				obj = (object)val;
			}
			Inventory.SetEquipment += (hook_SetEquipment)obj;
		}

		private static void Inventory_SetEquipment(orig_SetEquipment orig, Inventory self, EquipmentState equipmentState, uint slot)
		{
			//IL_002f: 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)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || self.GetItemCount(MinionMeldPlugin.meldStackItem) <= 0 || (int)equipmentState.equipmentIndex == -1 || (int)self.GetEquipment(slot).equipmentIndex == -1)
			{
				orig.Invoke(self, equipmentState, slot);
				return;
			}
			for (uint num = 0u; num < self.equipmentStateSlots.Length; num++)
			{
				if (self.equipmentStateSlots[num].equipmentIndex == equipmentState.equipmentIndex)
				{
					orig.Invoke(self, equipmentState, num);
					return;
				}
			}
			for (uint num2 = (uint)self.equipmentStateSlots.Length; num2 > slot; num2--)
			{
				EquipmentState equipment = self.GetEquipment(num2 - 1);
				if (self.SetEquipmentInternal(equipment, num2))
				{
					((NetworkBehaviour)self).SetDirtyBit(16u);
					self.HandleInventoryChanged();
					if (self.spawnedOverNetwork)
					{
						self.CallRpcClientEquipmentChanged(equipment.equipmentIndex, num2);
					}
				}
			}
			orig.Invoke(self, equipmentState, slot);
			if (self.activeEquipmentSlot == slot)
			{
				return;
			}
			EquipmentDef equipmentDef = self.GetEquipment(slot).equipmentDef;
			if (Object.op_Implicit((Object)(object)equipmentDef) && equipmentDef.cooldown > 0f)
			{
				EquipmentDef equipmentDef2 = self.currentEquipmentState.equipmentDef;
				if (!Object.op_Implicit((Object)(object)equipmentDef2) || equipmentDef2.cooldown <= 0f || equipmentDef.cooldown < equipmentDef2.cooldown)
				{
					self.SetActiveEquipmentSlot((byte)slot);
				}
			}
		}

		private static void ActivateAllEquipment(EquipmentSlot self, EquipmentIndex equipmentIndex)
		{
			//IL_0056: 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)
			if (!NetworkServer.active)
			{
				return;
			}
			Inventory val = (Object.op_Implicit((Object)(object)self.characterBody) ? self.characterBody.inventory : null);
			if (!Object.op_Implicit((Object)(object)val) || val.GetItemCount(MinionMeldPlugin.meldStackItem) <= 0)
			{
				return;
			}
			int equipmentSlotCount = val.GetEquipmentSlotCount();
			if (equipmentSlotCount <= 1)
			{
				return;
			}
			for (uint num = 0u; num < equipmentSlotCount; num++)
			{
				if (num != val.activeEquipmentSlot)
				{
					EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(val.GetEquipment(num).equipmentIndex);
					if (Object.op_Implicit((Object)(object)equipmentDef) && equipmentDef.cooldown > 0f)
					{
						self.PerformEquipmentAction(equipmentDef);
					}
				}
			}
		}

		private void CharacterBody_OnInventoryChanged(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchStfld<CharacterBody>(x, "statsDirty")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Action<CharacterBody>>((Action<CharacterBody>)delegate(CharacterBody body)
				{
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					if (body.inventory.GetItemCount(MinionMeldPlugin.meldStackItem) > 0)
					{
						for (uint num = 0u; num < body.inventory.GetEquipmentSlotCount(); num++)
						{
							BuffDef val2 = body.inventory.GetEquipment(num).equipmentDef?.passiveBuffDef;
							if (Object.op_Implicit((Object)(object)val2) && !body.HasBuff(val2))
							{
								body.AddBuff(val2);
							}
						}
					}
				});
			}
			else
			{
				Log.Error("MinionMeld.CharacterBody_OnInventoryChanged: ILHook failed.");
			}
		}
	}
	[RequireComponent(typeof(CharacterBody))]
	public class TeleportingTurret : MonoBehaviour
	{
		private readonly List<Vector3> storedNodes = new List<Vector3>();

		private CharacterBody body;

		private CharacterBody ownerBody;

		private float teleportAttemptTimer;

		private Vector3 currentNode;

		public static List<TeleportingTurret> instancesList = new List<TeleportingTurret>();

		private void OnEnable()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			instancesList.Add(this);
			body = ((Component)this).GetComponent<CharacterBody>();
			storedNodes.Add(body.footPosition);
			currentNode = body.footPosition;
		}

		private void OnDisable()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			instancesList.Remove(this);
			currentNode = Vector3.zero;
			storedNodes.Clear();
		}

		public void FixedUpdate()
		{
			if (!Object.op_Implicit((Object)(object)ownerBody))
			{
				CharacterMaster master = body.master;
				CharacterMaster val = (Object.op_Implicit((Object)(object)master) ? master.minionOwnership.ownerMaster : null);
				ownerBody = (Object.op_Implicit((Object)(object)val) ? val.GetBody() : null);
			}
			teleportAttemptTimer -= Time.fixedDeltaTime;
			if (!(teleportAttemptTimer > 0f))
			{
				teleportAttemptTimer = 2f;
				CheckNodesForTeleport();
			}
		}

		public void RegisterLocation(Vector3 pos)
		{
			//IL_0010: 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)
			//IL_001b: 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)
			foreach (Vector3 storedNode in storedNodes)
			{
				Vector3 val = storedNode - pos;
				if (((Vector3)(ref val)).sqrMagnitude < 400f)
				{
					return;
				}
			}
			storedNodes.Add(pos);
			teleportAttemptTimer = 0f;
		}

		private void CheckNodesForTeleport()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00a7: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ownerBody) || !Object.op_Implicit((Object)(object)body))
			{
				return;
			}
			HealthComponent healthComponent = body.healthComponent;
			if (healthComponent == null || !healthComponent.alive)
			{
				return;
			}
			Vector3 val = currentNode;
			Vector3 position = ownerBody.transform.position;
			Vector3 val2 = val - position;
			float num = ((Vector3)(ref val2)).sqrMagnitude;
			if (PluginConfig.enableTurretLeash.Value && num > (float)(PluginConfig.minionLeashRange.Value * PluginConfig.minionLeashRange.Value))
			{
				Vector3? val3 = MeldingTime.FindSpawnDestination(body, new DirectorPlacementRule
				{
					position = position,
					placementMode = (PlacementMode)1
				}, RoR2Application.rng);
				if (val3.HasValue)
				{
					RegisterLocation(val3.Value);
				}
			}
			foreach (Vector3 storedNode in storedNodes)
			{
				val2 = storedNode - position;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					val = storedNode;
				}
			}
			if (currentNode != val)
			{
				TeleportHelper.TeleportGameObject(((Component)this).gameObject, val);
				((Component)this).transform.rotation = Quaternion.identity;
				currentNode = val;
			}
		}

		public void CreateTeleportNode(Vector3 destination)
		{
			//IL_002b: 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_0031: 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_0033: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)body))
			{
				return;
			}
			HealthComponent healthComponent = body.healthComponent;
			if (healthComponent == null || !healthComponent.alive)
			{
				return;
			}
			Vector3 footPosition = currentNode;
			Vector3 val = footPosition - destination;
			float num = ((Vector3)(ref val)).sqrMagnitude;
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				if (Object.op_Implicit((Object)(object)instance.body))
				{
					if ((Object)(object)instance.body == (Object)(object)ownerBody)
					{
						footPosition = ownerBody.footPosition;
					}
					val = instance.body.footPosition - destination;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						footPosition = instance.body.footPosition;
					}
				}
			}
			Vector3? val2 = null;
			DirectorPlacementRule val3 = new DirectorPlacementRule
			{
				position = footPosition,
				placementMode = (PlacementMode)1
			};
			if (footPosition != currentNode)
			{
				val2 = MeldingTime.FindSpawnDestination(body, val3, RoR2Application.rng);
			}
			val3.position = destination;
			if (!val2.HasValue)
			{
				val2 = MeldingTime.FindSpawnDestination(body, val3, RoR2Application.rng);
			}
			if (val2.HasValue)
			{
				RegisterLocation(val2.Value);
				return;
			}
			Log.Message("Failed to create turret teleport node for " + ((Object)body).name);
			teleportAttemptTimer = 10f;
		}
	}
	[RequireComponent(typeof(CharacterMaster))]
	public class TimedMeldStack : MonoBehaviour
	{
		private float stopwatch;

		private bool started;

		public void Activate(float time)
		{
			if (!started)
			{
				stopwatch = time;
				started = true;
			}
		}

		private void FixedUpdate()
		{
			if (!started)
			{
				return;
			}
			stopwatch -= Time.fixedDeltaTime;
			if (stopwatch <= 0f)
			{
				CharacterMaster component = ((Component)this).GetComponent<CharacterMaster>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.inventory))
				{
					component.inventory.RemoveItem(MinionMeldPlugin.meldStackItem, 1);
				}
				Deployable val = default(Deployable);
				if (((Component)this).TryGetComponent<Deployable>(ref val))
				{
					val.OnDestroy();
					Object.Destroy((Object)(object)val);
				}
				Object.Destroy((Object)(object)this);
			}
		}
	}
}