plugins\Mina.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;

[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("Mina")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Bopl Battle landmine. Arms after 2s, then a faint red laser. Explodes when stepped on.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("Mina")]
[assembly: AssemblyTitle("Mina")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[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 Mina
{
	public static class MinaAbility
	{
		public const string AbilityName = "mina";

		public const string TemplateNameFragment = "invis";

		public const string IconTextureName = "MinaIcon";

		public static float CooldownSeconds = 5.5f;

		public const float ExtraCooldownSeconds = 1f;

		public const int ArmSeconds = 2;

		public const int FlipHoldSeconds = 2;

		public const int TicksPerSecond = 60;

		public const int ArmTicks = 120;

		public const int FlipHoldTicks = 120;

		public const float PlantedWorldSize = 1.7f;

		public const float IconFill = 0.5f;

		public const float LaserLength = 4.75f;

		public static readonly Fix TriggerPad = (Fix)0.2f;

		public static readonly Vector4 CircleExtents = new Vector4(0.04882813f, 0.04882813f, 0.08300781f, 0.9287109f);

		public static Explosion ExplosionPrefab;

		public static string DetonationSound;

		public static bool IsMina(GameObject go)
		{
			if ((Object)(object)go != (Object)null)
			{
				return ((Object)go).name.ToLower().Contains("mina");
			}
			return false;
		}

		public static bool IsMinaIcon(Sprite sprite)
		{
			if ((Object)(object)sprite != (Object)null && (Object)(object)sprite.texture != (Object)null)
			{
				return ((Object)sprite.texture).name == "MinaIcon";
			}
			return false;
		}

		public static void CaptureVanilla(NamedSpriteList icons)
		{
			//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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_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)
			//IL_008b: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			CaptureExplosion(icons);
			if ((Object)(object)icons == (Object)null || icons.sprites == null)
			{
				return;
			}
			foreach (NamedSprite sprite in icons.sprites)
			{
				if (sprite.name == null || (Object)(object)sprite.associatedGameObject == (Object)null)
				{
					continue;
				}
				string text = sprite.name.ToLower();
				if (!text.Contains("mine") || text.Contains("mina"))
				{
					continue;
				}
				AbilityMonoBehaviour componentInChildren = sprite.associatedGameObject.GetComponentInChildren<AbilityMonoBehaviour>(true);
				if (!((Object)(object)componentInChildren == (Object)null))
				{
					Fix cooldown = componentInChildren.GetCooldown();
					if (cooldown > Fix.Zero)
					{
						CooldownSeconds = (float)cooldown + 1f;
						break;
					}
				}
			}
		}

		public static void CaptureExplosion(NamedSpriteList icons)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0046: 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)
			if ((Object)(object)ExplosionPrefab != (Object)null || (Object)(object)icons == (Object)null || icons.sprites == null)
			{
				return;
			}
			foreach (NamedSprite sprite in icons.sprites)
			{
				if (!((Object)(object)sprite.associatedGameObject == (Object)null))
				{
					Mine componentInChildren = sprite.associatedGameObject.GetComponentInChildren<Mine>(true);
					if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.Explosion != (Object)null)
					{
						ExplosionPrefab = componentInChildren.Explosion;
						DetonationSound = componentInChildren.SoundToPlayOnDetonation;
						break;
					}
					GrenadeExplode componentInChildren2 = sprite.associatedGameObject.GetComponentInChildren<GrenadeExplode>(true);
					if ((Object)(object)componentInChildren2 != (Object)null && (Object)(object)componentInChildren2.explosion != (Object)null)
					{
						ExplosionPrefab = componentInChildren2.explosion;
						break;
					}
				}
			}
		}

		public static Explosion ResolveExplosionPrefab()
		{
			if ((Object)(object)ExplosionPrefab != (Object)null)
			{
				return ExplosionPrefab;
			}
			Explosion[] array = Resources.FindObjectsOfTypeAll<Explosion>();
			foreach (Explosion val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.explosionAnimation == (Object)null))
				{
					ExplosionPrefab = val;
					return val;
				}
			}
			return null;
		}

		public static Sprite LoadIcon(Sprite template)
		{
			//IL_002c: 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_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)
			Texture2D val = LoadTexture("Mina.AbilityIcon.png");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			int size = 128;
			float pixelsPerUnit = 100f;
			if ((Object)(object)template != (Object)null)
			{
				Rect rect = template.rect;
				if (((Rect)(ref rect)).width > 8f)
				{
					rect = template.rect;
					size = Mathf.RoundToInt(((Rect)(ref rect)).width);
				}
				pixelsPerUnit = template.pixelsPerUnit;
			}
			Texture2D obj = BlitCentered(val, size, 0.5f);
			((Object)obj).name = "MinaIcon";
			((Texture)obj).filterMode = (FilterMode)1;
			((Texture)obj).wrapMode = (TextureWrapMode)1;
			obj.Apply(false, false);
			Sprite obj2 = Build(obj, pixelsPerUnit);
			((Object)obj2).name = "mina";
			return obj2;
		}

		public static Sprite LoadPlantedSprite()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadTexture("Mina.AbilityIcon.png");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			((Object)val).name = "MinaPlanted";
			return Build(val, (float)((Texture)val).width / 1.7f, new Vector2(0.5f, 0f));
		}

		public static Sprite LoadLaserSprite()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			int num = 48;
			int num2 = 160;
			float num3 = (float)(num - 1) * 0.5f;
			Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false);
			Color val2 = default(Color);
			for (int i = 0; i < num2; i++)
			{
				float num4 = (float)i / (float)(num2 - 1);
				float num5 = Mathf.Lerp(7.5f, 1.6f, num4);
				float num6 = Mathf.Lerp(0.78f, 0.18f, num4);
				((Color)(ref val2))..ctor(1f, 0.02f, 0.02f, num6);
				for (int j = 0; j < num; j++)
				{
					float num7 = Mathf.Abs((float)j - num3);
					float num8 = 1f - Mathf.Clamp01((num7 - (num5 - 1.1f)) / 1.6f);
					if (num8 <= 0.001f)
					{
						val.SetPixel(j, i, Color.clear);
						continue;
					}
					Color val3 = val2;
					val3.a *= num8;
					val.SetPixel(j, i, val3);
				}
			}
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			val.Apply(false, false);
			((Object)val).name = "MinaLaser";
			return Build(val, (float)num2 / 4.75f, new Vector2(0.5f, 0f));
		}

		private static Texture2D BlitCentered(Texture2D source, int size, float fill)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0089: 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_0090: 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)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			Color[] pixels = (Color[])(object)new Color[size * size];
			val.SetPixels(pixels);
			int num = Mathf.Max(1, Mathf.RoundToInt((float)size * fill));
			int num2 = (size - num) / 2;
			int num3 = (size - num) / 2;
			Color[] pixels2 = source.GetPixels();
			int width = ((Texture)source).width;
			int height = ((Texture)source).height;
			for (int i = 0; i < num; i++)
			{
				int num4 = Mathf.Clamp(i * height / num, 0, height - 1);
				for (int j = 0; j < num; j++)
				{
					int num5 = Mathf.Clamp(j * width / num, 0, width - 1);
					Color val2 = pixels2[num4 * width + num5];
					if (!(val2.a < 0.05f))
					{
						val.SetPixel(num2 + j, num3 + i, val2);
					}
				}
			}
			return val;
		}

		private static Sprite Build(Texture2D texture, float pixelsPerUnit)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return Build(texture, pixelsPerUnit, new Vector2(0.5f, 0.5f));
		}

		private static Sprite Build(Texture2D texture, float pixelsPerUnit, Vector2 pivot)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			((Texture)texture).filterMode = (FilterMode)1;
			((Texture)texture).wrapMode = (TextureWrapMode)1;
			return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), pivot, pixelsPerUnit, 0u, (SpriteMeshType)0);
		}

		private static Texture2D LoadTexture(string resourceName)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				Plugin.Log.LogError((object)("Mina: embedded resource '" + resourceName + "' not found."));
				return null;
			}
			byte[] array;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				stream.CopyTo(memoryStream);
				array = memoryStream.ToArray();
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, array))
			{
				Plugin.Log.LogError((object)("Mina: '" + resourceName + "' failed to decode as a PNG."));
				return null;
			}
			val.Apply(false, false);
			return val;
		}
	}
	[HarmonyPatch(typeof(AbilityGrid), "Awake")]
	public static class MinaInjectionPatch
	{
		private static bool hasInjected;

		public static void Prefix(AbilityGrid __instance)
		{
			//IL_0038: 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_0058: 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_0079: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_0118: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			if (hasInjected)
			{
				return;
			}
			NamedSpriteList abilityIcons = __instance.abilityIcons;
			if ((Object)(object)abilityIcons == (Object)null || abilityIcons.sprites == null)
			{
				Plugin.Log.LogWarning((object)"Mina: AbilityGrid.abilityIcons was empty this Awake; not injecting yet (will retry on the next grid build).");
				return;
			}
			MinaAbility.CaptureVanilla(abilityIcons);
			NamedSprite val = default(NamedSprite);
			bool flag = false;
			foreach (NamedSprite sprite in abilityIcons.sprites)
			{
				if (sprite.name != null && sprite.name.ToLower().Contains("invis"))
				{
					val = sprite;
					flag = true;
					break;
				}
			}
			if (!flag || (Object)(object)val.associatedGameObject == (Object)null)
			{
				Plugin.Log.LogError((object)"Mina: could not find a native instant ability to clone, so the mine was not added. (Looked for an ability whose name contains 'invis'.)");
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val.associatedGameObject);
			Object.DontDestroyOnLoad((Object)(object)val2);
			((Object)val2).name = "mina";
			StripTemplateEffect(val2);
			InstantAbility component = val2.GetComponent<InstantAbility>();
			if ((Object)(object)component == (Object)null)
			{
				Plugin.Log.LogError((object)"Mina: the cloned ability has no InstantAbility component.");
				return;
			}
			component.SetCoolDown((Fix)MinaAbility.CooldownSeconds);
			((AbilityMonoBehaviour)component).OnlyCastableOnGround = true;
			Sprite val3 = MinaAbility.LoadIcon(val.sprite) ?? val.sprite;
			abilityIcons.sprites.Add(new NamedSprite("mina", val3, val2, true));
			hasInjected = true;
			Plugin.Log.LogInfo((object)("Mina: ability injected (cloned '" + val.name + "', " + $"arm {2}s, cooldown {MinaAbility.CooldownSeconds}s)."));
		}

		private static void StripTemplateEffect(GameObject clone)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			InstantAbility component = clone.GetComponent<InstantAbility>();
			if ((Object)(object)component != (Object)null)
			{
				component.funcOnEnter = new UnityEvent();
				component.isInvisibilty = false;
				component.EffectOnEnter = null;
			}
			Invisibility component2 = clone.GetComponent<Invisibility>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.Destroy((Object)(object)component2);
			}
			SpriteRenderer[] componentsInChildren = clone.GetComponentsInChildren<SpriteRenderer>(true);
			foreach (SpriteRenderer obj in componentsInChildren)
			{
				obj.sprite = null;
				((Renderer)obj).enabled = false;
			}
		}
	}
	[HarmonyPatch(typeof(AbilityReadyIndicator), "SetSprite")]
	public static class MinaCirclePatch
	{
		public static void Postfix(AbilityReadyIndicator __instance, Sprite sprite)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (MinaAbility.IsMinaIcon(sprite))
			{
				SpriteRenderer spriteRen = __instance.GetSpriteRen();
				if (!((Object)(object)spriteRen == (Object)null) && !((Object)(object)((Renderer)spriteRen).material == (Object)null))
				{
					((Renderer)spriteRen).material.SetVector("_CircleExtents", MinaAbility.CircleExtents);
				}
			}
		}
	}
	[HarmonyPatch(typeof(InstantAbility), "EnterAbility")]
	public static class MinaCastPatch
	{
		public static void Postfix(InstantAbility __instance)
		{
			if (MinaAbility.IsMina(((Component)__instance).gameObject))
			{
				SpriteRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<SpriteRenderer>(true);
				foreach (SpriteRenderer obj in componentsInChildren)
				{
					obj.sprite = null;
					((Renderer)obj).enabled = false;
				}
				MineCharge.TryBegin(__instance.playerInfo.playerId, __instance.playerInfo.AbilityButtonUsedIndex012);
			}
		}
	}
	[HarmonyPatch(typeof(Updater), "TickSimulation")]
	public static class MinaTickPatch
	{
		public static void Postfix()
		{
			MineCharge.Tick();
			MineField.Tick();
		}
	}
	[HarmonyPatch(typeof(PlayerHandler), "ResetForNextStage")]
	public static class MinaResetPatch
	{
		public static void Prefix()
		{
			MineCharge.ForgetAll();
			MineField.ForgetAll();
		}
	}
	[HarmonyPatch(typeof(Updater), "PreLevelLoad")]
	public static class MinaLevelLoadPatch
	{
		public static void Prefix()
		{
			MineCharge.ForgetAll();
			MineField.ForgetAll();
		}
	}
	internal static class MineCharge
	{
		private sealed class Charge
		{
			public int playerId;

			public int slot;

			public int ticksHeld;

			public int holdArmedTicks = 2;
		}

		private static readonly List<Charge> live = new List<Charge>();

		private static readonly FieldInfo TimersField = AccessTools.Field(typeof(SlimeController), "abilityCooldownTimers");

		public static void TryBegin(int playerId, int slot)
		{
			if (Find(playerId) == null)
			{
				PlayerPhysics val = PlayerBodies.PhysicsOf(playerId);
				if ((Object)(object)val == (Object)null || !val.IsGrounded() || (Object)(object)val.getAttachedGround() == (Object)null)
				{
					Refund(playerId, slot);
					return;
				}
				live.Add(new Charge
				{
					playerId = playerId,
					slot = slot,
					ticksHeld = 0,
					holdArmedTicks = 2
				});
			}
		}

		public static void Tick()
		{
			for (int num = live.Count - 1; num >= 0; num--)
			{
				Charge charge = live[num];
				PlayerPhysics val = PlayerBodies.PhysicsOf(charge.playerId);
				if ((Object)(object)val == (Object)null || !val.IsGrounded() || (Object)(object)val.getAttachedGround() == (Object)null)
				{
					Refund(charge.playerId, charge.slot);
					live.RemoveAt(num);
				}
				else
				{
					charge.ticksHeld++;
					if (charge.ticksHeld >= 120)
					{
						MineField.Plant(charge.playerId, otherSide: true);
						live.RemoveAt(num);
					}
					else if (charge.holdArmedTicks > 0)
					{
						charge.holdArmedTicks--;
					}
					else if (!IsHolding(charge))
					{
						MineField.Plant(charge.playerId, otherSide: false);
						live.RemoveAt(num);
					}
				}
			}
		}

		public static void FreezeIfCharging(SlimeController slime)
		{
			//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)
			if ((Object)(object)slime == (Object)null)
			{
				return;
			}
			Charge charge = Find(slime.GetPlayerId());
			if (charge == null || TimersField == null || slime.abilities == null)
			{
				return;
			}
			int slot = charge.slot;
			if (slot < 0 || slot >= slime.abilities.Count)
			{
				return;
			}
			AbilityMonoBehaviour val = slime.abilities[slot];
			if ((Object)(object)val == (Object)null || !MinaAbility.IsMina(((Component)val).gameObject) || !(TimersField.GetValue(slime) is Fix[] array) || slot >= array.Length)
			{
				return;
			}
			array[slot] = Fix.Zero;
			if (slime.AbilityReadyIndicators != null && slot < slime.AbilityReadyIndicators.Length)
			{
				AbilityReadyIndicator val2 = slime.AbilityReadyIndicators[slot];
				if ((Object)(object)val2 != (Object)null)
				{
					val2.SetCooldownProgress(0f);
				}
			}
		}

		public static void ForgetAll()
		{
			live.Clear();
		}

		private static void Refund(int playerId, int slot)
		{
			//IL_005b: 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)
			SlimeController val = SlimeOf(playerId);
			if ((Object)(object)val == (Object)null || TimersField == null || val.abilities == null || slot < 0 || slot >= val.abilities.Count || !(TimersField.GetValue(val) is Fix[] array) || slot >= array.Length)
			{
				return;
			}
			array[slot] = (Fix)MinaAbility.CooldownSeconds;
			if (val.AbilityReadyIndicators != null && slot < val.AbilityReadyIndicators.Length)
			{
				AbilityReadyIndicator val2 = val.AbilityReadyIndicators[slot];
				if ((Object)(object)val2 != (Object)null)
				{
					val2.SetCooldownProgress(1f);
				}
			}
		}

		private static bool IsHolding(Charge charge)
		{
			PlayerHandler val = PlayerHandler.Get();
			Player val2 = ((val == null) ? null : val.GetPlayer(charge.playerId));
			if (val2 != null)
			{
				return val2.AbilityButtonIsDown(charge.slot);
			}
			return false;
		}

		private static Charge Find(int playerId)
		{
			for (int i = 0; i < live.Count; i++)
			{
				if (live[i].playerId == playerId)
				{
					return live[i];
				}
			}
			return null;
		}

		private static SlimeController SlimeOf(int playerId)
		{
			SlimeController[] array = Object.FindObjectsOfType<SlimeController>();
			foreach (SlimeController val in array)
			{
				if ((Object)(object)val != (Object)null && val.GetPlayerId() == playerId)
				{
					return val;
				}
			}
			return null;
		}
	}
	internal static class MineField
	{
		internal sealed class Planted
		{
			public int ownerId;

			public Vec2 position;

			public Vec2 up = Vec2.up;

			public StickyRoundedRectangle ground;

			public Fix localPos;

			public Fix attachRadius;

			public int ticksToArm = 120;

			public bool armed;

			public GameObject visual;
		}

		private static readonly List<Planted> live = new List<Planted>();

		public static void Plant(int playerId, bool otherSide)
		{
			//IL_005d: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0092: 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_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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_0109: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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)
			//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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0104: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: 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_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			PlayerPhysics val = PlayerBodies.PhysicsOf(playerId);
			if ((Object)(object)val == (Object)null || !val.IsGrounded())
			{
				return;
			}
			StickyRoundedRectangle attachedGround = val.getAttachedGround();
			if ((Object)(object)attachedGround == (Object)null)
			{
				return;
			}
			PlayerBody playerBody = val.GetPlayerBody();
			List<Vec2> list = PlayerBodies.PositionsOf(playerId);
			if (!((Object)(object)playerBody == (Object)null) || list.Count != 0)
			{
				Vec2 val2 = (((Object)(object)playerBody != (Object)null) ? playerBody.position : list[0]);
				Fix val3 = ((val.radius > Fix.Zero) ? val.radius : ((Fix)1.1f));
				Vec2 val4 = attachedGround.currentNormal(val2);
				val4 = ((!(Vec2.SqrMagnitude(val4) <= Fix.Zero)) ? Vec2.Normalized(val4) : Vec2.up);
				Fix localPlatformPos = val.LocalPlatformPos;
				Fix val5 = val3;
				Vec2 val6 = val4;
				Vec2 val7 = val2 - val4 * val3;
				if (otherSide && TryOtherSide(attachedGround, val2, val4, out var farHit, out var localPos))
				{
					localPlatformPos = localPos;
					val5 = Fix.Zero;
					val6 = -val4;
					val7 = farHit;
				}
				else
				{
					localPlatformPos = val.LocalPlatformPos;
					val5 = val3;
					Vec2 val8 = attachedGround.PositionFromLocalPlayerPos(localPlatformPos, val3);
					Vec2 val9 = attachedGround.currentNormal(val8);
					val6 = ((!(Vec2.SqrMagnitude(val9) > Fix.Zero)) ? val4 : Vec2.Normalized(val9));
					val7 = val8 - val6 * val3;
				}
				Planted planted = new Planted
				{
					ownerId = playerId,
					position = val7,
					up = val6,
					ground = attachedGround,
					localPos = localPlatformPos,
					attachRadius = val5,
					ticksToArm = 120,
					armed = false
				};
				planted.visual = MineVisuals.Create(planted);
				live.Add(planted);
			}
		}

		private static bool TryOtherSide(StickyRoundedRectangle ground, Vec2 playerPos, Vec2 normal, out Vec2 farHit, out Fix localPos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_002c: 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_0037: 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_0039: 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_003f: 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_005b: 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)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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)
			farHit = playerPos;
			localPos = Fix.Zero;
			DPhysicsRoundedRect component = ((Component)ground).GetComponent<DPhysicsRoundedRect>();
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			RoundedRect roundedRect = component.GetRoundedRect();
			Fix zero = Fix.Zero;
			Fix zero2 = Fix.Zero;
			if (!Raycast.RayCastRoundedRect(playerPos, -normal, roundedRect, ref zero, ref zero2))
			{
				return false;
			}
			farHit = playerPos - normal * zero2;
			localPos = ground.LocalPlayerPosFromPos(farHit, Fix.Zero);
			return true;
		}

		public static void Tick()
		{
			for (int num = live.Count - 1; num >= 0; num--)
			{
				Planted planted = live[num];
				UpdatePose(planted);
				MineVisuals.Place(planted);
				if (!planted.armed)
				{
					planted.ticksToArm--;
					if (planted.ticksToArm <= 0)
					{
						planted.armed = true;
						MineVisuals.Arm(planted);
					}
				}
				else if (SteppedOn(planted))
				{
					Explode(num);
				}
			}
		}

		public static void ForgetAll()
		{
			for (int i = 0; i < live.Count; i++)
			{
				MineVisuals.Destroy(live[i]);
			}
			live.Clear();
		}

		private static void UpdatePose(Planted mine)
		{
			//IL_003b: 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_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)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0079: 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: 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_008b: 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)
			if ((Object)(object)mine.ground == (Object)null)
			{
				return;
			}
			GameObject val = mine.ground.ThisGameObject();
			if ((Object)(object)val == (Object)null || !val.activeInHierarchy)
			{
				mine.ground = null;
				return;
			}
			Vec2 val2 = mine.ground.PositionFromLocalPlayerPos(mine.localPos, mine.attachRadius);
			Vec2 val3 = mine.ground.currentNormal(val2);
			if (!(Vec2.SqrMagnitude(val3) <= Fix.Zero))
			{
				mine.up = Vec2.Normalized(val3);
				mine.position = val2 - mine.up * mine.attachRadius;
			}
		}

		private static bool SteppedOn(Planted mine)
		{
			//IL_007a: 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)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			PlayerCollision[] array = Object.FindObjectsOfType<PlayerCollision>();
			foreach (PlayerCollision val in array)
			{
				if ((Object)(object)val == (Object)null || ((MonoUpdatable)val).IsDestroyed || !((Component)val).gameObject.activeInHierarchy)
				{
					continue;
				}
				FixTransform component = ((Component)val).GetComponent<FixTransform>();
				if (!((Object)(object)component == (Object)null) && !component.IsDestroyed)
				{
					PlayerPhysics component2 = ((Component)val).GetComponent<PlayerPhysics>();
					Fix val2 = (((Object)(object)component2 != (Object)null && component2.radius > Fix.Zero) ? component2.radius : ((Fix)1.1f)) + MinaAbility.TriggerPad;
					if (Vec2.SqrMagnitude(component.position - mine.position) <= val2 * val2)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static void Explode(int index)
		{
			//IL_000c: 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)
			//IL_005a: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			Planted planted = live[index];
			Vec2 position = planted.position;
			int ownerId = planted.ownerId;
			MineVisuals.Destroy(planted);
			live.RemoveAt(index);
			Explosion val = MinaAbility.ResolveExplosionPrefab();
			if ((Object)(object)val != (Object)null)
			{
				Explosion val2 = FixTransform.InstantiateFixed<Explosion>(val, position);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.PlayerOwnerId = ownerId;
					val2.canHurtOwner = true;
				}
			}
			else
			{
				KillNear(ownerId, position, (Fix)2.4f);
			}
			if (!string.IsNullOrEmpty(MinaAbility.DetonationSound))
			{
				AudioManager obj = AudioManager.Get();
				if (obj != null)
				{
					obj.Play(MinaAbility.DetonationSound);
				}
			}
		}

		private static void KillNear(int ownerId, Vec2 position, Fix radius)
		{
			//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_0002: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			Fix val = radius * radius;
			PlayerCollision[] array = Object.FindObjectsOfType<PlayerCollision>();
			foreach (PlayerCollision val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null) && !((MonoUpdatable)val2).IsDestroyed && ((Component)val2).gameObject.activeInHierarchy && !PlayerBodies.IsProtected(val2.GetPlayerId()))
				{
					FixTransform component = ((Component)val2).GetComponent<FixTransform>();
					if (!((Object)(object)component == (Object)null) && !component.IsDestroyed && !(Vec2.SqrMagnitude(component.position - position) > val))
					{
						val2.killPlayer(ownerId, true, false, (CauseOfDeath)0);
					}
				}
			}
		}
	}
	internal static class MineVisuals
	{
		private static Sprite plantedSprite;

		private static Sprite laserSprite;

		public static GameObject Create(MineField.Planted mine)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)plantedSprite == (Object)null)
			{
				plantedSprite = MinaAbility.LoadPlantedSprite();
			}
			GameObject val = new GameObject("MinaPlanted");
			SpriteRenderer obj = val.AddComponent<SpriteRenderer>();
			obj.sprite = plantedSprite;
			obj.color = Color.white;
			((Renderer)obj).sortingOrder = 70;
			Place(mine, val);
			return val;
		}

		public static void Arm(MineField.Planted mine)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)mine.visual == (Object)null))
			{
				if ((Object)(object)laserSprite == (Object)null)
				{
					laserSprite = MinaAbility.LoadLaserSprite();
				}
				SpriteRenderer component = mine.visual.GetComponent<SpriteRenderer>();
				if ((Object)(object)component != (Object)null)
				{
					component.sprite = laserSprite;
					component.color = new Color(1f, 0.12f, 0.12f, 1f);
					((Renderer)component).sortingOrder = 55;
				}
				((Object)mine.visual).name = "MinaLaser";
				Place(mine);
			}
		}

		public static void Place(MineField.Planted mine)
		{
			Place(mine, mine.visual);
		}

		public static void Destroy(MineField.Planted mine)
		{
			if (mine != null && (Object)(object)mine.visual != (Object)null)
			{
				Object.Destroy((Object)(object)mine.visual);
				mine.visual = null;
			}
		}

		private static void Place(MineField.Planted mine, GameObject go)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_008c: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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)
			if (mine != null && !((Object)(object)go == (Object)null))
			{
				Vector3 position = default(Vector3);
				((Vector3)(ref position))..ctor((float)mine.position.x, (float)mine.position.y, 0f);
				Vector3 up = default(Vector3);
				((Vector3)(ref up))..ctor((float)mine.up.x, (float)mine.up.y, 0f);
				if (((Vector3)(ref up)).sqrMagnitude < 0.0001f)
				{
					up = Vector3.up;
				}
				else
				{
					((Vector3)(ref up)).Normalize();
				}
				float num = Mathf.Atan2(up.y, up.x) * 57.29578f - 90f;
				go.transform.rotation = Quaternion.Euler(0f, 0f, num);
				if (mine.armed)
				{
					go.transform.position = position;
					go.transform.localScale = Vector3.one;
				}
				else
				{
					go.transform.position = position;
					go.transform.localScale = Vector3.one;
				}
			}
		}
	}
	internal static class PlayerBodies
	{
		public static List<Vec2> PositionsOf(int playerId)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			List<Vec2> list = new List<Vec2>();
			PlayerCollision[] array = Object.FindObjectsOfType<PlayerCollision>();
			foreach (PlayerCollision val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((MonoUpdatable)val).IsDestroyed && ((Component)val).gameObject.activeInHierarchy && val.GetPlayerId() == playerId)
				{
					FixTransform component = ((Component)val).GetComponent<FixTransform>();
					if ((Object)(object)component != (Object)null && !component.IsDestroyed)
					{
						list.Add(component.position);
					}
				}
			}
			return list;
		}

		public static PlayerPhysics PhysicsOf(int playerId)
		{
			PlayerCollision[] array = Object.FindObjectsOfType<PlayerCollision>();
			foreach (PlayerCollision val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((MonoUpdatable)val).IsDestroyed && ((Component)val).gameObject.activeInHierarchy && val.GetPlayerId() == playerId)
				{
					PlayerPhysics component = ((Component)val).GetComponent<PlayerPhysics>();
					if ((Object)(object)component != (Object)null)
					{
						return component;
					}
				}
			}
			return null;
		}

		public static Fix RadiusOf(int playerId, Fix fallback)
		{
			//IL_0029: 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)
			//IL_0016: 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)
			PlayerPhysics val = PhysicsOf(playerId);
			if ((Object)(object)val != (Object)null && val.radius > Fix.Zero)
			{
				return val.radius;
			}
			return fallback;
		}

		public static bool IsProtected(int playerId)
		{
			PlayerHandler val = PlayerHandler.Get();
			Player val2 = ((val == null) ? null : val.GetPlayer(playerId));
			if (val2 != null && val2.InPlatformTransform)
			{
				return true;
			}
			ControlPlatform[] array = Object.FindObjectsOfType<ControlPlatform>();
			foreach (ControlPlatform val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null) && ((Behaviour)val3).isActiveAndEnabled)
				{
					IPlayerIdHolder component = ((Component)val3).GetComponent<IPlayerIdHolder>();
					if (component != null && component.GetPlayerId() == playerId)
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	[BepInPlugin("com.solsticio.boplbattle.mina", "Mina", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.solsticio.boplbattle.mina";

		public const string PluginName = "Mina";

		public const string PluginVersion = "1.0.1";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Mina: loading...");
			new Harmony("com.solsticio.boplbattle.mina").PatchAll();
			Log.LogInfo((object)$"Mina: loaded (arm {2}s, cooldown {MinaAbility.CooldownSeconds}s).");
		}
	}
	internal static class UniqueMinaSlots
	{
		public static void Ensure(SlimeController slime)
		{
			if ((Object)(object)slime == (Object)null || slime.abilities == null)
			{
				return;
			}
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 0; i < slime.abilities.Count; i++)
			{
				AbilityMonoBehaviour val = slime.abilities[i];
				if ((Object)(object)val == (Object)null || !MinaAbility.IsMina(((Component)val).gameObject))
				{
					continue;
				}
				int instanceID = ((Object)val).GetInstanceID();
				if (!hashSet.Add(instanceID))
				{
					InstantAbility val2 = Clone(val);
					if ((Object)(object)val2 != (Object)null)
					{
						slime.abilities[i] = (AbilityMonoBehaviour)(object)val2;
					}
				}
			}
		}

		public static AbilityMonoBehaviour CloneIfMina(AbilityMonoBehaviour ability)
		{
			if ((Object)(object)ability == (Object)null || !MinaAbility.IsMina(((Component)ability).gameObject))
			{
				return ability;
			}
			return (AbilityMonoBehaviour)(((object)Clone(ability)) ?? ((object)ability));
		}

		private static InstantAbility Clone(AbilityMonoBehaviour ability)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(((Component)ability).gameObject);
			Object.DontDestroyOnLoad((Object)(object)obj);
			((Object)obj).name = "mina";
			InstantAbility component = obj.GetComponent<InstantAbility>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetCoolDown((Fix)MinaAbility.CooldownSeconds);
				((AbilityMonoBehaviour)component).OnlyCastableOnGround = true;
			}
			return component;
		}
	}
	[HarmonyPatch(typeof(SlimeController), "AddAbility")]
	public static class MinaAddAbilityPatch
	{
		public static void Prefix(ref AbilityMonoBehaviour ability)
		{
			ability = UniqueMinaSlots.CloneIfMina(ability);
		}
	}
	[HarmonyPatch(typeof(SlimeController), "AddAdditionalAbility")]
	public static class MinaAddAdditionalAbilityPatch
	{
		public static void Prefix(ref AbilityMonoBehaviour ability)
		{
			ability = UniqueMinaSlots.CloneIfMina(ability);
		}
	}
	[HarmonyPatch(typeof(SlimeController), "OldUpdate")]
	public static class MinaUniqueSlotsPatch
	{
		public static void Postfix(SlimeController __instance)
		{
			UniqueMinaSlots.Ensure(__instance);
			MineCharge.FreezeIfCharging(__instance);
		}
	}
}