Decompiled source of FATE MeleeSpells v0.8.54

BepInEx/plugins/FATE_MeleeSpells/mikhailkillszombies.FateMeleeSpells.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cleverous.Prodigy;
using Cleverous.Prodigy.Input;
using Cleverous.ThatHurtModule;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Tableflip;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[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("MikhailKillsZombies")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) 2026 MikhailKillsZombies")]
[assembly: AssemblyFileVersion("0.8.54.0")]
[assembly: AssemblyInformationalVersion("0.8.54")]
[assembly: AssemblyProduct("mikhailkillszombies.FateMeleeSpells")]
[assembly: AssemblyTitle("mikhailkillszombies.FateMeleeSpells")]
[assembly: AssemblyVersion("0.8.54.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MikhailKillsZombies.FateMeleeSpells
{
	internal static class AegisStance
	{
		internal const float Duration = 0.35f;

		internal const float StaminaPerSecond = 4.5f;

		internal const float KnockbackForceBase = 1f;

		internal const float KnockbackForcePerSkill = 0.1f;

		internal const float KnockbackForceMax = 12f;

		internal const float ShockwaveRadius = 6f;

		internal const float ShieldRaiseDegrees = 55f;

		private static readonly MethodInfo ModifyStamina = typeof(Character).GetMethod("ModifyStamina", BindingFlags.Instance | BindingFlags.NonPublic);

		private static Character guard;

		private static float endsAt;

		private static int denialId = -1;

		private static NavMeshAgent guardAgent;

		private static Transform shield;

		private static Quaternion shieldRest;

		private static Animator animator;

		private static float nextBlockText;

		private static Transform guardUpperArm;

		private static Transform guardForearm;

		private static Quaternion upperArmRest;

		private static Quaternion forearmRest;

		private static AegisGuardPose guardPose;

		private static readonly string[] HandBoneNames = new string[1] { "hand" };

		private static readonly string[] ForearmBoneNames = new string[2] { "forearm", "lowerarm" };

		private static readonly string[] UpperArmBoneNames = new string[4] { "upperarm", "shoulder", "clavicle", "arm" };

		internal static bool Guarding(Character character)
		{
			if ((Object)(object)guard != (Object)null && (Object)(object)character != (Object)null && character == guard && guard.Alive())
			{
				return Time.time < endsAt;
			}
			return false;
		}

		internal static bool HasShield(Character character)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			try
			{
				if ((Object)(object)character == (Object)null || character.inventory == null)
				{
					return false;
				}
				foreach (Item item in character.inventory)
				{
					if (item != null && item.equipped && (int)item.itemType == 17 && item.IsInOffHand)
					{
						return true;
					}
				}
				return false;
			}
			catch
			{
				return false;
			}
		}

		internal static void Begin(Character caster)
		{
			if ((Object)(object)caster == (Object)null || !caster.Alive())
			{
				return;
			}
			if (!HasShield(caster))
			{
				MeleeSpellDebug.Pop("Parry: a shield is needed");
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"Parry refused: no shield in the off-hand.");
				}
				return;
			}
			if (Guarding(caster))
			{
				endsAt = Time.time + 0.35f;
				return;
			}
			End("restarted", quiet: true);
			guard = caster;
			endsAt = Time.time + 0.35f;
			Root(caster);
			Pose(caster, up: true);
			MeleeSpellSfx.PlayBlock(caster);
			MeleeSpellDebug.Pop("Parry");
			ManualLogSource log2 = MeleeSpellPlugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)("Parry up for " + 0.35f.ToString("0.00") + "s (shield in the off-hand)."));
			}
		}

		internal static void Tick()
		{
			if ((Object)(object)guard == (Object)null)
			{
				return;
			}
			if (!guard.Alive())
			{
				End("the caster is down");
				return;
			}
			if (Time.time >= endsAt)
			{
				End("expired");
				return;
			}
			HoldStill();
			try
			{
				if (ModifyStamina != null)
				{
					ModifyStamina.Invoke(guard, new object[1] { -4.5f * Time.deltaTime });
				}
				if ((float)guard.Stamina() <= 0f)
				{
					End("out of stamina");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Parry upkeep failed: " + ex.Message));
				}
			}
		}

		internal static void Blocked(Character target, Character attacker, int damage)
		{
			//IL_00ac: 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_003c: 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_0053: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null)
			{
				return;
			}
			Vector3 val = (((Object)(object)attacker != (Object)null && (Object)(object)attacker.myTransform != (Object)null) ? attacker.myTransform.position : (target.myTransform.position + target.myTransform.forward * 1.2f));
			if (Time.time >= nextBlockText)
			{
				nextBlockText = Time.time + 0.25f;
				try
				{
					ThatHurt.PopText(target.myTransform.position, I2Loca.Get("Blocked"), 1f, 2f, (ThatHurtColor)0, 0f);
					SingletonBehaviour<AudioManager>.Instance.PlayAudioClipOnLocation((AudioClipName)101, val);
				}
				catch
				{
				}
				MeleeSpellVfx.Impact(val);
			}
			List<Character> list = new List<Character>();
			if ((Object)(object)attacker != (Object)null && (Object)(object)attacker != (Object)(object)target && attacker.Alive() && !attacker.IsPlayer() && !list.Contains(attacker))
			{
				list.Add(attacker);
			}
			try
			{
				Collider[] array = Physics.OverlapSphere(target.myTransform.position, 6f);
				foreach (Collider val2 in array)
				{
					Character componentInParent;
					try
					{
						componentInParent = ((Component)val2).GetComponentInParent<Character>();
					}
					catch
					{
						continue;
					}
					if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent == (Object)(object)target) && componentInParent.Alive() && !componentInParent.IsPlayer() && !list.Contains(componentInParent) && Hostile(componentInParent, target))
					{
						list.Add(componentInParent);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Parry shockwave sweep failed: " + ex.Message));
				}
			}
			float num = KnockbackForceOf(target);
			int num2 = 0;
			foreach (Character item in list)
			{
				if (ApplyKnockback(target, item, num))
				{
					num2++;
				}
			}
			if (num2 > 0)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogInfo((object)("Parry blocked " + damage + " damage and knocked back " + num2 + " enemy/enemies (force " + Mathf.RoundToInt(num) + ", shield skill " + Stat(target, (Attribute)19) + ")."));
				}
			}
		}

		private static bool Hostile(Character candidate, Character guard)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0034: Invalid comparison between Unknown and I4
			//IL_0036: 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)
			try
			{
				if (candidate.HasMaster())
				{
					Character val = candidate.Master();
					if ((Object)(object)val != (Object)null && val.IsPlayer())
					{
						return false;
					}
				}
				Alignment alignment = guard.GetAlignment();
				Alignment alignment2 = candidate.GetAlignment();
				return (int)alignment2 != 3 && alignment2 != alignment;
			}
			catch
			{
				return false;
			}
		}

		private static float KnockbackForceOf(Character guard)
		{
			return Mathf.Min(12f, 1f + (float)Stat(guard, (Attribute)19) * 0.1f);
		}

		private static int Stat(Character character, Attribute attribute)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return ((Object)(object)character != (Object)null && character.attributes != null) ? character.attributes.GetAttribute(attribute, true, true) : 0;
			}
			catch
			{
				return 0;
			}
		}

		private static bool ApplyKnockback(Character source, Character enemy, float force)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0019: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			try
			{
				enemy.AddEffect(new EffectData
				{
					name = "MeleeSpellAegisKnockback",
					buffType = (EffectType)57,
					value = Mathf.RoundToInt(force),
					chance = 100,
					activationType = (ActivationType)1,
					target = (ItemTarget)1
				}, 0, source, -1, true);
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Parry could not knock back " + (((Object)(object)enemy != (Object)null) ? ((Object)enemy).name : "?") + ": " + ex.Message));
				}
				return false;
			}
		}

		internal static void End(string reason, bool quiet = false)
		{
			if ((Object)(object)guard == (Object)null)
			{
				return;
			}
			Character caster = guard;
			Unroot(caster);
			Pose(caster, up: false);
			guard = null;
			endsAt = 0f;
			if (!quiet)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)("Parry down (" + reason + ")."));
				}
			}
		}

		private static void Root(Character caster)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			try
			{
				ProdigyAgent component = ((Component)caster).GetComponent<ProdigyAgent>();
				if ((Object)(object)component == (Object)null)
				{
					ManualLogSource log = MeleeSpellPlugin.Log;
					if (log != null)
					{
						log.LogWarning((object)"Parry: no ProdigyAgent; the caster is not rooted.");
					}
				}
				else
				{
					denialId = component.AddDenial(new RuntimeDenial(true, false, false, false, false));
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Parry could not root the caster: " + ex.Message));
				}
			}
			HoldStill();
		}

		private static void HoldStill()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)guardAgent == (Object)null && (Object)(object)guard != (Object)null)
				{
					guardAgent = ((Component)guard).GetComponent<NavMeshAgent>();
				}
				if (!((Object)(object)guardAgent == (Object)null) && ((Behaviour)guardAgent).enabled && guardAgent.isOnNavMesh && !guardAgent.isStopped)
				{
					guardAgent.isStopped = true;
					guardAgent.velocity = Vector3.zero;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Parry could not stop the caster: " + ex.Message));
				}
			}
		}

		private static void Unroot(Character caster)
		{
			try
			{
				if (denialId >= 0 && (Object)(object)caster != (Object)null)
				{
					ProdigyAgent component = ((Component)caster).GetComponent<ProdigyAgent>();
					if ((Object)(object)component != (Object)null)
					{
						component.RemoveDenialById(denialId);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Parry could not release the root: " + ex.Message));
				}
			}
			denialId = -1;
			try
			{
				if ((Object)(object)guardAgent != (Object)null && ((Behaviour)guardAgent).enabled && guardAgent.isOnNavMesh)
				{
					guardAgent.isStopped = false;
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Parry could not release the caster: " + ex2.Message));
				}
			}
			guardAgent = null;
		}

		private static void Pose(Character caster, bool up)
		{
			//IL_010b: 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_00ca: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)animator == (Object)null)
				{
					animator = ((Component)caster).GetComponentInChildren<Animator>();
				}
				if (up)
				{
					if (!RaiseGuardArm(caster) && (Object)(object)animator != (Object)null)
					{
						animator.SetBool("IsCasting", true);
					}
				}
				else
				{
					ReleaseGuardArm();
					if ((Object)(object)animator != (Object)null)
					{
						animator.SetBool("IsCasting", false);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Parry pose failed: " + ex.Message));
				}
			}
			try
			{
				if (up)
				{
					EquipmentHandle leftWeaponHandle = caster.leftWeaponHandle;
					if (!((Object)(object)leftWeaponHandle == (Object)null) && !((Object)(object)leftWeaponHandle.CurrentEquipment == (Object)null))
					{
						shield = leftWeaponHandle.CurrentEquipment.transform;
						shieldRest = shield.localRotation;
						shield.localRotation = shieldRest * Quaternion.Euler(0f, 0f, 55f);
					}
				}
				else if ((Object)(object)shield != (Object)null)
				{
					shield.localRotation = shieldRest;
					shield = null;
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Parry shield raise failed: " + ex2.Message));
				}
			}
		}

		private static bool RaiseGuardArm(Character caster)
		{
			//IL_010b: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				EquipmentHandle leftWeaponHandle = caster.leftWeaponHandle;
				if ((Object)(object)leftWeaponHandle == (Object)null)
				{
					return false;
				}
				List<Transform> list = new List<Transform>();
				Transform parent = ((Component)leftWeaponHandle).transform.parent;
				while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)((Component)caster).transform && list.Count < 7)
				{
					list.Add(parent);
					parent = parent.parent;
				}
				Transform val = Pick(list, 0, HandBoneNames) ?? First(list, 0);
				int num = (((Object)(object)val != (Object)null) ? list.IndexOf(val) : (-1));
				Transform val2 = Pick(list, num + 1, ForearmBoneNames) ?? First(list, num + 1);
				int num2 = (((Object)(object)val2 != (Object)null) ? list.IndexOf(val2) : (-1));
				Transform val3 = Pick(list, num2 + 1, UpperArmBoneNames) ?? First(list, num2 + 1);
				if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
				{
					return false;
				}
				guardForearm = val2;
				guardUpperArm = val3;
				forearmRest = val2.localRotation;
				upperArmRest = val3.localRotation;
				guardPose = ((Component)caster).GetComponent<AegisGuardPose>();
				if ((Object)(object)guardPose == (Object)null)
				{
					guardPose = ((Component)caster).gameObject.AddComponent<AegisGuardPose>();
				}
				guardPose.Begin(guardUpperArm, guardForearm);
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)("Parry raises " + ((Object)val3).name + " / " + ((Object)val2).name + " (shield mount: " + ((Object)leftWeaponHandle).name + ")"));
				}
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Parry could not find the shield arm: " + ex.Message));
				}
				return false;
			}
		}

		private static void ReleaseGuardArm()
		{
			//IL_0039: 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)
			try
			{
				if ((Object)(object)guardPose != (Object)null)
				{
					guardPose.Stop();
					Object.Destroy((Object)(object)guardPose);
					guardPose = null;
				}
				if ((Object)(object)guardUpperArm != (Object)null)
				{
					guardUpperArm.localRotation = upperArmRest;
				}
				if ((Object)(object)guardForearm != (Object)null)
				{
					guardForearm.localRotation = forearmRest;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Parry could not lower the shield arm: " + ex.Message));
				}
			}
			guardUpperArm = null;
			guardForearm = null;
		}

		private static Transform First(List<Transform> chain, int from)
		{
			if (from < 0 || from >= chain.Count)
			{
				return null;
			}
			return chain[from];
		}

		private static Transform Pick(List<Transform> chain, int from, string[] names)
		{
			for (int i = Mathf.Max(0, from); i < chain.Count; i++)
			{
				string text = ((Object)chain[i]).name.ToLowerInvariant().Replace("_", string.Empty).Replace(" ", string.Empty);
				foreach (string value in names)
				{
					if (text.Contains(value))
					{
						return chain[i];
					}
				}
			}
			return null;
		}
	}
	internal sealed class AegisGuardPose : MonoBehaviour
	{
		private Transform upperArm;

		private Transform forearm;

		private bool live;

		internal void Begin(Transform upperArm, Transform forearm)
		{
			this.upperArm = upperArm;
			this.forearm = forearm;
			live = true;
		}

		internal void Stop()
		{
			live = false;
		}

		private void LateUpdate()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0060: 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_006f: 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_007f: 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_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_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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			if (live && !((Object)(object)upperArm == (Object)null) && !((Object)(object)forearm == (Object)null))
			{
				Vector3 val = forearm.position - upperArm.position;
				if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
				{
					Vector3 val2 = ((Component)this).transform.forward * 0.6f + Vector3.up * 0.45f + ((Component)this).transform.right * 0.1f;
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					upperArm.rotation = Quaternion.FromToRotation(((Vector3)(ref val)).normalized, normalized) * upperArm.rotation;
				}
			}
		}
	}
	internal static class DualBladeSlash
	{
		internal const float SlashRadius = 3.2f;

		internal const float SlashLengthFallback = 4f;

		internal const float SpinSeconds = 0.3f;

		internal static void Cast(Character caster, MeleeSpellDef def, bool ignoreEquipment = false)
		{
			//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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)caster == (Object)null || !caster.Alive())
			{
				return;
			}
			if (!ignoreEquipment && !caster.IsDualWielding)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"Dual Blade Slash refused: the caster is not dual wielding.");
				}
				return;
			}
			Vector3 val = AimDirection(caster);
			((Component)caster).transform.rotation = Quaternion.LookRotation(val);
			int num = Stat(caster, (Attribute)2);
			int num2 = Stat(caster, (Attribute)18);
			int num3 = Stat(caster, (Attribute)8);
			int num4 = Stat(caster, (Attribute)1);
			int damage = Mathf.RoundToInt(8f + 0.9f * (float)num + 1.6f * (float)num2 + 0.35f * (float)num3 + 0.4f * (float)num4);
			float seconds = Mathf.Clamp(0.45f + 0.02f * (float)num, 0.45f, 1.2f);
			int percent = Mathf.Clamp(30 + num, 30, 90);
			Swing(caster);
			Character player = ((caster is Player) ? caster : null);
			MeleeSpellSfx.Play((Player)(object)player);
			MeleeSpellVfx.BeginSelected((Player)(object)player);
			MeleeSpellSpin.Run((Player)(object)player, 360f, 0.3f);
			float num5 = DashDistanceFor(num);
			int num6 = Strike(caster, val, damage, num5);
			if (num6 > 0)
			{
				PlayStrikeSound(caster);
			}
			ApplySpeed(caster, percent, seconds);
			Dash(caster, val, num5);
			MeleeSpellDebug.Pop("Slash " + num6 + " hit(s) " + damage + " dmg, aim " + val.x.ToString("0.0") + "," + val.z.ToString("0.0"));
			ManualLogSource log2 = MeleeSpellPlugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)("Dual Blade Slash: " + num6 + " hit(s) for " + damage + " damage, aim (" + val.x.ToString("0.00") + ", " + val.z.ToString("0.00") + "), dash " + num5.ToString("0.0") + "m, +" + percent + "% speed for " + seconds.ToString("0.0") + "s (Dex " + num + ", dual wield " + num2 + ")."));
			}
		}

		private static int Stat(Character caster, Attribute attribute)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return (caster.attributes != null) ? caster.attributes.GetAttribute(attribute, true, true) : 0;
			}
			catch
			{
				return 0;
			}
		}

		internal static Vector3 AimDirection(Character caster)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0079: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			if (MeleeSpellControl.ControllerActive)
			{
				return MeleeSpellControl.MoveDirection(caster);
			}
			try
			{
				Camera val = (((Object)(object)ProdigyCamera.GameCamera != (Object)null) ? ProdigyCamera.GameCamera : Camera.main);
				Vector2 val2 = Vector2.zero;
				bool flag = false;
				try
				{
					if (Mouse.current != null)
					{
						val2 = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
						flag = true;
					}
				}
				catch
				{
				}
				if (!flag)
				{
					try
					{
						val2 = Vector2.op_Implicit(Input.mousePosition);
						flag = true;
					}
					catch
					{
					}
				}
				if ((Object)(object)val != (Object)null && flag)
				{
					Ray val3 = val.ScreenPointToRay(Vector2.op_Implicit(val2));
					RaycastHit val4 = default(RaycastHit);
					if (Physics.Raycast(val3, ref val4, 500f, -1, (QueryTriggerInteraction)1))
					{
						Vector3 val5 = ((RaycastHit)(ref val4)).point - ((Component)caster).transform.position;
						val5.y = 0f;
						if (((Vector3)(ref val5)).sqrMagnitude > 0.05f)
						{
							return ((Vector3)(ref val5)).normalized;
						}
					}
					Vector3 val6 = ((Ray)(ref val3)).origin + ((Ray)(ref val3)).direction * 40f - ((Component)caster).transform.position;
					val6.y = 0f;
					if (((Vector3)(ref val6)).sqrMagnitude > 0.05f)
					{
						return ((Vector3)(ref val6)).normalized;
					}
				}
			}
			catch
			{
			}
			Vector3 forward = ((Component)caster).transform.forward;
			forward.y = 0f;
			if (!(((Vector3)(ref forward)).sqrMagnitude > 0.001f))
			{
				return Vector3.forward;
			}
			return ((Vector3)(ref forward)).normalized;
		}

		private static int Strike(Character caster, Vector3 aim, int damage, float length)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			Vector3 position = ((Component)caster).transform.position;
			int num = 0;
			Vector3 val = position - aim * 0.5f;
			Vector3 val2 = position + aim * Mathf.Max(length, 4f);
			Collider[] array;
			try
			{
				array = Physics.OverlapCapsule(val, val2, 3.2f);
			}
			catch
			{
				return 0;
			}
			HashSet<Character> hashSet = new HashSet<Character>();
			Collider[] array2 = array;
			foreach (Collider val3 in array2)
			{
				Character componentInParent;
				try
				{
					componentInParent = ((Component)val3).GetComponentInParent<Character>();
				}
				catch
				{
					continue;
				}
				if ((Object)(object)componentInParent == (Object)null || (Object)(object)componentInParent == (Object)(object)caster || !componentInParent.Alive() || componentInParent.IsPlayer() || !hashSet.Add(componentInParent))
				{
					continue;
				}
				try
				{
					if (MeleeSpellDamage.Hit(caster, componentInParent, damage) > 0)
					{
						num++;
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log = MeleeSpellPlugin.Log;
					if (log != null)
					{
						log.LogWarning((object)("Dual Blade Slash could not damage " + ((Object)componentInParent).name + ": " + ex.Message));
					}
				}
			}
			return num;
		}

		internal static void PlayStrikeSound(Character caster)
		{
			try
			{
				Item activeWeapon = caster.activeWeapon;
				if (activeWeapon != null)
				{
					activeWeapon.PlayStrikeSound();
					return;
				}
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"Dual Blade Slash: no active weapon to take the strike sound from.");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Dual Blade Slash strike sound failed: " + ex.Message));
				}
			}
		}

		private static void ApplySpeed(Character caster, int percent, float seconds)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_003c: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			try
			{
				caster.AddEffect(new EffectData
				{
					name = "DualBladeSlashSpeed",
					buffType = (EffectType)34,
					value = percent,
					duration = Mathf.Max(1, Mathf.RoundToInt(seconds)),
					chance = 100,
					activationType = (ActivationType)1,
					target = (ItemTarget)0
				}, 0, caster, -1, true);
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Dual Blade Slash speed buff failed: " + ex.Message));
				}
			}
		}

		private static float DashDistanceFor(int dexterity)
		{
			return Mathf.Clamp(2.5f + 0.1f * (float)dexterity, 2.5f, 10f);
		}

		private static float Dash(Character caster, Vector3 aim, float distance)
		{
			//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)
			//IL_002e: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			try
			{
				Player val = (Player)(object)((caster is Player) ? caster : null);
				if ((Object)(object)val != (Object)null)
				{
					MeleeSpellDash.Run(val, aim, distance, 0.2f);
					return distance;
				}
				Vector3 val2 = ((Component)caster).transform.position + aim * distance;
				caster.SetDestination(val2.x, val2.z);
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Dual Blade Slash dash failed: " + ex.Message));
				}
			}
			return distance;
		}

		internal static void Swing(Character caster)
		{
			Player val = (Player)(object)((caster is Player) ? caster : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			try
			{
				if (!(((Character)val).castTimer > 0f) && !(((Character)val).attackTimer > 0f))
				{
					val.AttackDone();
					((Character)val).SelectAttack();
					val.StartAttack();
					Item activeWeapon = ((Character)val).activeWeapon;
					if (activeWeapon != null)
					{
						activeWeapon.PlayAttackSound();
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Dual Blade Slash animation failed: " + ex.Message));
				}
			}
		}
	}
	internal static class MeleeSpellControl
	{
		private static Vector3 lastMove;

		private static float lastMoveAt;

		internal static bool ControllerActive
		{
			get
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Invalid comparison between Unknown and I4
				try
				{
					if (!SingletonBehaviour<InputBroker>.InstanceExists())
					{
						return false;
					}
					return (int)SingletonBehaviour<InputBroker>.Instance.LocalInputBehavior == 0;
				}
				catch
				{
					return false;
				}
			}
		}

		internal static void Tick()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			try
			{
				if (!ControllerActive)
				{
					lastMove = Vector3.zero;
					return;
				}
				Vector3 move = SingletonBehaviour<InputBroker>.Instance.Move;
				move.y = 0f;
				if (((Vector3)(ref move)).sqrMagnitude > 0.0025f)
				{
					lastMove = ((Vector3)(ref move)).normalized;
					lastMoveAt = Time.unscaledTime;
				}
			}
			catch
			{
			}
		}

		internal static Vector3 MoveDirection(Character caster)
		{
			//IL_0034: 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_0018: 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_005c: 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)
			if (ControllerActive && ((Vector3)(ref lastMove)).sqrMagnitude > 0.001f)
			{
				return lastMove;
			}
			Vector3 val = (((Object)(object)caster != (Object)null) ? ((Component)caster).transform.forward : Vector3.forward);
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude > 0.001f))
			{
				return Vector3.forward;
			}
			return ((Vector3)(ref val)).normalized;
		}
	}
	internal static class MeleeSpellDamage
	{
		internal static bool RollCritical(Character caster)
		{
			try
			{
				if ((Object)(object)caster == (Object)null)
				{
					return false;
				}
				int num = caster.SkillPoints((Attribute)16);
				float num2 = 50f - 50f / ((float)num * 0.03f + 1f);
				if (num2 > 50f)
				{
					num2 = 50f;
				}
				return num2 > 0f && Random.Range(0f, 100f) < num2;
			}
			catch
			{
				return false;
			}
		}

		internal static int Roll(Character caster, float baseDamage, out bool critical)
		{
			float num = 0.8f;
			float num2 = 1.2f;
			try
			{
				Item val = (((Object)(object)caster != (Object)null) ? caster.activeWeapon : null);
				if (val != null && val.minimumDamage > 0f && val.maximumDamage > val.minimumDamage)
				{
					float num3 = (val.minimumDamage + val.maximumDamage) * 0.5f;
					num = Mathf.Clamp(val.minimumDamage / num3, 0.1f, 1f);
					num2 = Mathf.Clamp(val.maximumDamage / num3, 1f, 3f);
				}
			}
			catch
			{
			}
			int num4 = Mathf.Max(1, Mathf.RoundToInt(Random.Range(baseDamage * num, baseDamage * num2)));
			try
			{
				if ((Object)(object)caster != (Object)null)
				{
					num4 += Mathf.CeilToInt((float)num4 * caster.EffectValue((EffectType)38) / 100f);
					num4 += (int)caster.EffectValue((EffectType)10);
				}
			}
			catch
			{
			}
			critical = RollCritical(caster);
			if (critical)
			{
				num4 += num4;
			}
			return Mathf.Max(1, num4);
		}

		internal static int Hit(Character caster, Character target, float baseDamage)
		{
			//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_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_0052: 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_0067: Expected O, but got Unknown
			if ((Object)(object)caster == (Object)null || (Object)(object)target == (Object)null)
			{
				return 0;
			}
			bool critical;
			int num = Roll(caster, baseDamage, out critical);
			try
			{
				if (critical)
				{
					SingletonBehaviour<AudioManager>.Instance.PlayAudioClip((AudioClipName)23, true);
				}
			}
			catch
			{
			}
			try
			{
				target.MyVitals.ApplyDamage(new Damage
				{
					damageType = (DamageType)0,
					source = caster.MyVitals,
					value = num,
					isCritical = critical
				}, true, false);
				return num;
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Spell damage could not be applied to " + ((Object)target).name + ": " + ex.Message));
				}
				return 0;
			}
		}
	}
	internal sealed class MeleeSpellDash : MonoBehaviour
	{
		private bool running;

		internal static void Run(Player player, Vector3 direction, float distance, float seconds)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || distance <= 0f)
			{
				return;
			}
			try
			{
				MeleeSpellDash meleeSpellDash = ((Component)player).GetComponent<MeleeSpellDash>();
				if ((Object)(object)meleeSpellDash == (Object)null)
				{
					meleeSpellDash = ((Component)player).gameObject.AddComponent<MeleeSpellDash>();
				}
				meleeSpellDash.Begin(player, direction, distance, seconds);
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Dual Blade Slash dash could not start: " + ex.Message));
				}
			}
		}

		internal void Begin(Player player, Vector3 direction, float distance, float seconds)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (running)
			{
				((MonoBehaviour)this).StopAllCoroutines();
			}
			((MonoBehaviour)this).StartCoroutine(Slide(player, direction, distance, seconds));
		}

		private IEnumerator Slide(Player player, Vector3 direction, float distance, float seconds)
		{
			//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)
			running = true;
			MeleeSpellMovement.Free(player);
			NavMeshAgent agent = ((Component)player).GetComponent<NavMeshAgent>();
			float travelled = 0f;
			float speed = distance / Mathf.Max(0.05f, seconds);
			ManualLogSource log = MeleeSpellPlugin.Log;
			if (log != null)
			{
				log.LogInfo((object)("Dash starting: " + distance.ToString("0.0") + "m over " + seconds.ToString("0.00") + "s, direction (" + direction.x.ToString("0.00") + ", " + direction.z.ToString("0.00") + "), agent " + (((Object)(object)agent == (Object)null) ? "missing" : ((((Behaviour)agent).enabled ? "ready" : "disabled") + "/" + (agent.isOnNavMesh ? "on navmesh" : "off navmesh"))) + ", start " + ((object)((Component)player).transform.position/*cast due to .constrained prefix*/).ToString()));
			}
			if ((Object)(object)agent == (Object)null)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)"Dual Blade Slash: the player has no NavMeshAgent; the dash cannot move it.");
				}
			}
			while ((Object)(object)player != (Object)null && travelled < distance)
			{
				float num = Mathf.Min(speed * Time.deltaTime, distance - travelled);
				if (num <= 0f)
				{
					break;
				}
				if ((Object)(object)agent != (Object)null && ((Behaviour)agent).enabled && agent.isOnNavMesh)
				{
					agent.Move(direction * num);
				}
				else
				{
					Transform transform = ((Component)player).transform;
					transform.position += direction * num;
				}
				travelled += num;
				MeleeSpellMovement.Free(player);
				yield return null;
			}
			ManualLogSource log3 = MeleeSpellPlugin.Log;
			if (log3 != null)
			{
				log3.LogInfo((object)("Dash finished: travelled " + travelled.ToString("0.0") + "m, at " + (((Object)(object)player != (Object)null) ? ((object)((Component)player).transform.position/*cast due to .constrained prefix*/).ToString() : "no player")));
			}
			MeleeSpellDebug.Pop("Dash " + travelled.ToString("0.0") + "m");
			if ((Object)(object)player != (Object)null)
			{
				MeleeSpellVfx.EndSelected(((Component)player).transform.position);
			}
			ReleaseAttack(player);
			MeleeSpellFreeWalk.Run(player, 0.75f);
			running = false;
		}

		private static void ReleaseAttack(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			try
			{
				((Character)player).attackTimer = 0f;
				player.AttackDone();
				Animator componentInChildren = ((Component)player).GetComponentInChildren<Animator>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.SetBool("IsAttacking", false);
					componentInChildren.speed = 1f;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Could not release the attack state: " + ex.Message));
				}
			}
		}
	}
	internal static class MeleeSpellDebug
	{
		internal const string Version = "0.8.54";

		private static float lastPopTime;

		private static string markerPath;

		internal static void WriteMarker(string note)
		{
			try
			{
				if (markerPath == null)
				{
					markerPath = Path.Combine(Paths.PluginPath ?? Paths.BepInExRootPath, "FATE_MeleeSpells-version.txt");
				}
				File.AppendAllText(markerPath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "  v0.8.54  " + note + Environment.NewLine);
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Could not write the version marker: " + ex.Message));
				}
			}
		}

		internal static void Pop(string text)
		{
			//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_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)
			try
			{
				if (!(Time.unscaledTime - lastPopTime < 0.4f))
				{
					Player playerChar = Player.PlayerChar;
					if (!((Object)(object)playerChar == (Object)null))
					{
						lastPopTime = Time.unscaledTime;
						ThatHurt.PopText(((Component)playerChar).transform.position + Vector3.up * 2.4f, text, 1f, (ThatHurtColor)0, 2.5f);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("On-screen diagnostic failed: " + ex.Message));
				}
			}
		}
	}
	internal static class MeleeSpellHooks
	{
		internal static MethodBase CompleteSpellMethod;

		private static float lastProbeLog;

		internal static MethodBase TryCastMethod;

		internal static void Apply(Harmony harmony)
		{
			//IL_0092: 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_00b4: Expected O, but got Unknown
			//IL_00b4: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Expected O, but got Unknown
			//IL_037f: Expected O, but got Unknown
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(Character), "CompleteSpell", new Type[5]
				{
					typeof(Vector3?),
					typeof(Vector3?),
					typeof(Character),
					typeof(Item),
					typeof(SpellData)
				}, (Type[])null);
				if (methodInfo == null)
				{
					ManualLogSource log = MeleeSpellPlugin.Log;
					if (log != null)
					{
						log.LogWarning((object)"Character.CompleteSpell was not found; melee spells will do nothing.");
					}
					return;
				}
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MeleeSpellRuntime), "BeforeComplete", (Type[])null), new HarmonyMethod(typeof(MeleeSpellHooks), "AfterCast", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(MeleeSpellHooks), "CompleteSpellThrew", (Type[])null), (HarmonyMethod)null);
				CompleteSpellMethod = methodInfo;
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogInfo((object)"Cast hook installed on Character.CompleteSpell.");
				}
				ManualLogSource log3 = MeleeSpellPlugin.Log;
				if (log3 != null)
				{
					log3.LogInfo((object)("Patched \"" + methodInfo.DeclaringType?.FullName + "\" in " + methodInfo.DeclaringType?.Assembly.Location));
				}
				Report();
				MethodInfo methodInfo2 = AccessTools.Method(typeof(Character), "SpawnImpactVfxForSpell", new Type[5]
				{
					typeof(SpellData),
					typeof(float),
					typeof(Vector3),
					typeof(Quaternion),
					typeof(Character)
				}, (Type[])null);
				if (methodInfo2 != null)
				{
					harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(MeleeSpellHooks), "VfxProbe", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					ManualLogSource log4 = MeleeSpellPlugin.Log;
					if (log4 != null)
					{
						log4.LogInfo((object)("Impact VFX probe installed on " + methodInfo2.DeclaringType?.Assembly.Location));
					}
				}
				else
				{
					ManualLogSource log5 = MeleeSpellPlugin.Log;
					if (log5 != null)
					{
						log5.LogWarning((object)"SpawnImpactVfxForSpell was not found; the probe is missing.");
					}
				}
				int num = 0;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					Type type = null;
					try
					{
						type = assembly.GetType("Tableflip.Character", throwOnError: false);
					}
					catch
					{
					}
					if (!(type == null))
					{
						num++;
						ManualLogSource log6 = MeleeSpellPlugin.Log;
						if (log6 != null)
						{
							log6.LogInfo((object)("Tableflip.Character copy " + num + " from " + assembly.Location + " (matches our reference: " + (type == typeof(Character)) + ")"));
						}
					}
				}
				ManualLogSource log7 = MeleeSpellPlugin.Log;
				if (log7 != null)
				{
					log7.LogInfo((object)("Tableflip.Character copies loaded: " + num + "."));
				}
				MethodInfo methodInfo3 = AccessTools.Method(typeof(Character), "TryCastCurrentSpell", new Type[4]
				{
					typeof(Vector3?),
					typeof(Vector3?),
					typeof(Character),
					typeof(Item)
				}, (Type[])null);
				if (methodInfo3 != null)
				{
					harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(MeleeSpellRuntime), "BeforeCast", (Type[])null), new HarmonyMethod(typeof(MeleeSpellRuntime), "AfterCastAccepted", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					TryCastMethod = methodInfo3;
					ManualLogSource log8 = MeleeSpellPlugin.Log;
					if (log8 != null)
					{
						log8.LogInfo((object)"Cast gate installed on Character.TryCastCurrentSpell.");
					}
					Report();
				}
				else
				{
					ManualLogSource log9 = MeleeSpellPlugin.Log;
					if (log9 != null)
					{
						log9.LogWarning((object)"Character.TryCastCurrentSpell was not found; melee spells can be spammed.");
					}
				}
				MethodInfo methodInfo4 = AccessTools.Method(typeof(CharacterVitals), "ApplyDamage", new Type[3]
				{
					typeof(Damage),
					typeof(bool),
					typeof(bool)
				}, (Type[])null);
				if (methodInfo4 != null)
				{
					harmony.Patch((MethodBase)methodInfo4, new HarmonyMethod(typeof(MeleeSpellHooks), "BeforeVitalsDamage", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					ManualLogSource log10 = MeleeSpellPlugin.Log;
					if (log10 != null)
					{
						log10.LogInfo((object)"Guard hook installed on CharacterVitals.ApplyDamage.");
					}
				}
				else
				{
					ManualLogSource log11 = MeleeSpellPlugin.Log;
					if (log11 != null)
					{
						log11.LogWarning((object)"CharacterVitals.ApplyDamage was not found; Parry cannot block.");
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log12 = MeleeSpellPlugin.Log;
				if (log12 != null)
				{
					log12.LogWarning((object)("Could not hook CompleteSpell: " + ex.Message));
				}
			}
		}

		private static bool BeforeVitalsDamage(CharacterVitals __instance, Damage data)
		{
			try
			{
				if (!MeleeSpellPlugin.ModEnabled || (Object)(object)__instance == (Object)null || data == null)
				{
					return true;
				}
				Character val = __instance.Char;
				if ((Object)(object)val == (Object)null || !AegisStance.Guarding(val))
				{
					return true;
				}
				Character attacker = (((Object)(object)data.source != (Object)null) ? data.source.Char : null);
				AegisStance.Blocked(val, attacker, data.value);
				return false;
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Parry block check failed: " + ex.Message));
				}
				return true;
			}
		}

		private static void VfxProbe(object __instance, SpellData chosenSpell)
		{
			try
			{
				if (!(Time.unscaledTime - lastProbeLog < 1f))
				{
					lastProbeLog = Time.unscaledTime;
					Type type = __instance?.GetType();
					ManualLogSource log = MeleeSpellPlugin.Log;
					if (log != null)
					{
						log.LogInfo((object)("VFX probe: spell=" + (((Object)(object)chosenSpell == (Object)null) ? "none" : chosenSpell.spellName) + " caster type=" + type?.FullName + " caster asm=" + type?.Assembly.Location + " same type as ours=" + (type == typeof(Character)) + " patched asm=" + typeof(Character).Assembly.Location));
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("VFX probe failed: " + ex.Message));
				}
			}
		}

		internal static void Report()
		{
			try
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)("Hook check: CompleteSpell prefixes=" + Count(CompleteSpellMethod) + " (ours=" + HasOurs(CompleteSpellMethod) + "), TryCastCurrentSpell prefixes=" + Count(TryCastMethod) + " (ours=" + HasOurs(TryCastMethod) + "), owners=" + Owners(CompleteSpellMethod) + "."));
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Hook check failed: " + ex.Message));
				}
			}
		}

		internal static void Ensure()
		{
			if (!HasOurs(CompleteSpellMethod) || !HasOurs(TryCastMethod))
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)"Melee spell hooks were removed by something else; reinstalling them.");
				}
				Apply(MeleeSpellPlugin.HarmonyInstance);
			}
		}

		private static bool HasOurs(MethodBase method)
		{
			if (method == null)
			{
				return false;
			}
			Patches patchInfo = Harmony.GetPatchInfo(method);
			if (patchInfo == null)
			{
				return false;
			}
			foreach (Patch prefix in patchInfo.Prefixes)
			{
				if (prefix.owner == "mikhailkillszombies.fate.meleespells")
				{
					return true;
				}
			}
			return false;
		}

		private static string Owners(MethodBase method)
		{
			if (method == null)
			{
				return "?";
			}
			Patches patchInfo = Harmony.GetPatchInfo(method);
			if (patchInfo == null)
			{
				return "none";
			}
			List<string> list = new List<string>();
			foreach (Patch prefix in patchInfo.Prefixes)
			{
				if (!list.Contains(prefix.owner))
				{
					list.Add(prefix.owner);
				}
			}
			return string.Join(",", list.ToArray());
		}

		private static int Count(MethodBase method)
		{
			if (method == null)
			{
				return -1;
			}
			return Harmony.GetPatchInfo(method)?.Prefixes.Count ?? 0;
		}

		private static Exception CompleteSpellThrew(Exception __exception)
		{
			if (__exception != null)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogError((object)("Character.CompleteSpell threw: " + __exception));
				}
			}
			return __exception;
		}

		private static void AfterCast(Character __instance, SpellData overrideSpell)
		{
			try
			{
				if (!MeleeSpellPlugin.ModEnabled)
				{
					return;
				}
				SpellData val = (((Object)(object)overrideSpell != (Object)null) ? overrideSpell : ((__instance != null) ? __instance.GetActiveSpell : null));
				if (!((Object)(object)val == (Object)null) && val.spellName != null && val.spellName.StartsWith("MeleeSpell_", StringComparison.Ordinal))
				{
					string text = (((Object)(object)__instance != (Object)null && __instance.IsPlayer()) ? "the player" : (((Object)(object)__instance != (Object)null) ? ((Object)__instance).name : "nobody"));
					if (MeleeSpellPlugin.Diagnostics != null && MeleeSpellPlugin.Diagnostics.Value)
					{
						MeleeSpellPlugin.Log.LogInfo((object)("Cast " + val.spellName + " from " + text + " (mana " + (((Object)(object)__instance != (Object)null) ? __instance.Mana().ToString() : "?") + ", stamina " + (((Object)(object)__instance != (Object)null) ? __instance.Stamina().ToString() : "?") + ")."));
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Melee spell dispatch failed: " + ex.Message));
				}
			}
		}
	}
	internal static class MeleeSpellIcons
	{
		internal const string DualBladeSpellIcon = "DualBladeSlashIcon";

		internal const string DualBladeScrollIcon = "dualslashscroll";

		internal const string AegisSpellIcon = "AegisShieldIcon";

		internal const string AegisScrollIcon = "aegisshieldscroll";

		internal const string WhirlingSpellIcon = "WhirlingMaelstromIcon";

		internal const string WhirlingScrollIcon = "whirlingmaelstromscroll";

		internal const string PiercingSpellIcon = "PiercingStepIcon";

		internal const string PiercingScrollIcon = "piercingstepscroll";

		internal const string ReturningSpellIcon = "ReturningEdgeIcon";

		internal const string ReturningScrollIcon = "returningedgescroll";

		internal const string ShadowstepSpellIcon = "ShadowstepIcon";

		internal const string ShadowstepScrollIcon = "shadowstepscroll";

		internal static bool DualBladeSpellReady { get; private set; }

		internal static bool DualBladeScrollReady { get; private set; }

		internal static bool AegisSpellReady { get; private set; }

		internal static bool AegisScrollReady { get; private set; }

		internal static bool WhirlingSpellReady { get; private set; }

		internal static bool WhirlingScrollReady { get; private set; }

		internal static bool PiercingSpellReady { get; private set; }

		internal static bool PiercingScrollReady { get; private set; }

		internal static bool ReturningSpellReady { get; private set; }

		internal static bool ReturningScrollReady { get; private set; }

		internal static bool ShadowstepSpellReady { get; private set; }

		internal static bool ShadowstepScrollReady { get; private set; }

		internal static void Load(FateDB db, ManualLogSource log)
		{
			if (!((Object)(object)db == (Object)null))
			{
				string text = Path.Combine(Path.GetDirectoryName(typeof(MeleeSpellIcons).Assembly.Location) ?? ".", "assets");
				DualBladeSpellReady = Add(db, log, text, "DualBladeSlashIcon.png", "DualBladeSlashIcon");
				DualBladeScrollReady = Add(db, log, text, "dualslashscroll.png", "dualslashscroll");
				AegisSpellReady = Add(db, log, text, "AegisShieldIcon.png", "AegisShieldIcon");
				AegisScrollReady = Add(db, log, text, "aegisshieldscroll.png", "aegisshieldscroll");
				WhirlingSpellReady = Add(db, log, text, "WhirlingMaelstromIcon.png", "WhirlingMaelstromIcon");
				WhirlingScrollReady = Add(db, log, text, "whirlingmaelstromscroll.png", "whirlingmaelstromscroll");
				PiercingSpellReady = Add(db, log, text, "PiercingStepIcon.png", "PiercingStepIcon");
				PiercingScrollReady = Add(db, log, text, "piercingstepscroll.png", "piercingstepscroll");
				ReturningSpellReady = Add(db, log, text, "ReturningEdgeIcon.png", "ReturningEdgeIcon");
				ReturningScrollReady = Add(db, log, text, "returningedgescroll.png", "returningedgescroll");
				ShadowstepSpellReady = Add(db, log, text, "ShadowstepIcon.png", "ShadowstepIcon");
				ShadowstepScrollReady = Add(db, log, text, "shadowstepscroll.png", "shadowstepscroll");
				if (log != null)
				{
					log.LogInfo((object)("Custom art: Dual Blade Slash spell " + Loaded(DualBladeSpellReady) + ", scroll " + Loaded(DualBladeScrollReady) + "; Parry spell " + Loaded(AegisSpellReady) + ", scroll " + Loaded(AegisScrollReady) + "; Spinning Maelstrom spell " + Loaded(WhirlingSpellReady) + ", scroll " + Loaded(WhirlingScrollReady) + "; Piercing Step spell " + Loaded(PiercingSpellReady) + ", scroll " + Loaded(PiercingScrollReady) + "; Returning Throw spell " + Loaded(ReturningSpellReady) + ", scroll " + Loaded(ReturningScrollReady) + "; Shadowstep spell " + Loaded(ShadowstepSpellReady) + ", scroll " + Loaded(ShadowstepScrollReady) + " (" + text + ")"));
				}
			}
		}

		private static string Loaded(bool ready)
		{
			if (!ready)
			{
				return "missing";
			}
			return "loaded";
		}

		private static bool Add(FateDB db, ManualLogSource log, string directory, string file, string name)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (db.spriteStash != null)
				{
					Sprite[] spriteStash = db.spriteStash;
					foreach (Sprite val in spriteStash)
					{
						if ((Object)(object)val != (Object)null && string.Equals(((Object)val).name, name, StringComparison.Ordinal))
						{
							return true;
						}
					}
				}
				string text = Path.Combine(directory, file);
				if (!File.Exists(text))
				{
					if (log != null)
					{
						log.LogWarning((object)("Icon asset not found: " + text));
					}
					return false;
				}
				Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val2, File.ReadAllBytes(text)))
				{
					if (log != null)
					{
						log.LogWarning((object)("Could not decode icon: " + text));
					}
					return false;
				}
				((Object)val2).name = name;
				((Texture)val2).wrapMode = (TextureWrapMode)1;
				((Texture)val2).filterMode = (FilterMode)1;
				Sprite val3 = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)val3).name = name;
				Sprite[] array = (Sprite[])(((object)db.spriteStash) ?? ((object)new Sprite[0]));
				Sprite[] array2 = (Sprite[])(object)new Sprite[array.Length + 1];
				Array.Copy(array, array2, array.Length);
				array2[array.Length] = val3;
				db.spriteStash = array2;
				if (log != null)
				{
					log.LogInfo((object)("Icon loaded: " + name + " (" + ((Texture)val2).width + "x" + ((Texture)val2).height + ")"));
				}
				return true;
			}
			catch (Exception ex)
			{
				if (log != null)
				{
					log.LogWarning((object)("Could not load icon " + file + ": " + ex.Message));
				}
				return false;
			}
		}
	}
	internal static class MeleeSpellMovement
	{
		internal const float FreeAfterSpellSeconds = 0.75f;

		private static readonly FieldInfo DenialListField = FindDenialList();

		private static FieldInfo FindDenialList()
		{
			Type type = typeof(ProdigyAgent);
			while (type != null)
			{
				FieldInfo field = type.GetField("DenialList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					return field;
				}
				type = type.BaseType;
			}
			return null;
		}

		internal static ProdigyAgent AgentOf(Player player)
		{
			try
			{
				return ((Object)(object)player != (Object)null) ? ((Component)player).GetComponent<ProdigyAgent>() : null;
			}
			catch
			{
				return null;
			}
		}

		internal static void Free(Player player)
		{
			Free(AgentOf(player));
		}

		internal static void Free(ProdigyAgent agent)
		{
			try
			{
				if ((Object)(object)agent == (Object)null || DenialListField == null || !(DenialListField.GetValue(agent) is List<RuntimeDenial> list))
				{
					return;
				}
				for (int i = 0; i < list.Count; i++)
				{
					RuntimeDenial val = list[i];
					if (val != null && val.DenyMove)
					{
						val.DenyMove = false;
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Could not lift the movement denial: " + ex.Message));
				}
			}
		}
	}
	internal sealed class MeleeSpellFreeWalk : MonoBehaviour
	{
		private Player player;

		private float endsAt;

		private bool running;

		internal static void Run(Player player, float seconds)
		{
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			try
			{
				MeleeSpellFreeWalk meleeSpellFreeWalk = ((Component)player).GetComponent<MeleeSpellFreeWalk>();
				if ((Object)(object)meleeSpellFreeWalk == (Object)null)
				{
					meleeSpellFreeWalk = ((Component)player).gameObject.AddComponent<MeleeSpellFreeWalk>();
				}
				meleeSpellFreeWalk.Begin(player, seconds);
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Could not keep the player walking: " + ex.Message));
				}
			}
		}

		private void Begin(Player caster, float seconds)
		{
			player = caster;
			endsAt = Mathf.Max(endsAt, Time.time + Mathf.Max(0.1f, seconds));
			if (!running)
			{
				((MonoBehaviour)this).StartCoroutine(Tick());
			}
		}

		private IEnumerator Tick()
		{
			running = true;
			while ((Object)(object)player != (Object)null && Time.time < endsAt)
			{
				MeleeSpellMovement.Free(player);
				yield return null;
			}
			running = false;
			player = null;
		}
	}
	[BepInPlugin("mikhailkillszombies.fate.meleespells", "FATE Melee Spells", "0.8.54")]
	public sealed class MeleeSpellPlugin : BaseUnityPlugin
	{
		private sealed class Driver : MonoBehaviour
		{
			private float nextLookup;

			private float nextHookReport;

			private bool bannerShown;

			private bool particleDumpDone;

			private void Update()
			{
				if (!ModEnabled)
				{
					return;
				}
				MeleeSpellControl.Tick();
				MeleeSpellSfx.EnsureLoaded((MonoBehaviour)(object)this);
				AegisStance.Tick();
				MeleeSpellSfx.Enabled = CustomSound == null || CustomSound.Value;
				MeleeSpellVfx.Enabled = SlashEffects == null || SlashEffects.Value;
				if (!bannerShown && (Object)(object)Player.PlayerChar != (Object)null)
				{
					bannerShown = true;
					MeleeSpellDebug.Pop("Melee Spells 0.8.54 loaded");
					MeleeSpellDebug.WriteMarker("player present, registered=" + SpellCatalog.Installed);
				}
				if (!particleDumpDone && (Object)(object)Player.PlayerChar != (Object)null)
				{
					particleDumpDone = true;
					MeleeSpellVfx.DumpFateParticles();
				}
				if (Time.unscaledTime >= nextHookReport)
				{
					nextHookReport = Time.unscaledTime + 5f;
					MeleeSpellHooks.Ensure();
					MeleeSpellHooks.Report();
				}
				if (SpellCatalog.Installed)
				{
					if (!MerchantStock.Stocked && Time.unscaledTime >= nextLookup)
					{
						nextLookup = Time.unscaledTime + 1f;
						MerchantStock.Stock(Log);
					}
				}
				else
				{
					if (Time.unscaledTime < nextLookup)
					{
						return;
					}
					nextLookup = Time.unscaledTime + 1f;
					try
					{
						FateDB instance = SingletonBehaviour<FateDB>.Instance;
						if ((Object)(object)instance != (Object)null)
						{
							SpellCatalog.Install(instance, Log);
						}
					}
					catch (Exception ex)
					{
						Log.LogWarning((object)("Spell registration tick failed: " + ex.Message));
					}
				}
			}

			private void OnDestroy()
			{
				Harmony harmony = MeleeSpellPlugin.harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
		}

		public const string Guid = "mikhailkillszombies.fate.meleespells";

		internal const int DefaultReturningThrowManaPerHit = 2;

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> Diagnostics;

		internal static ConfigEntry<bool> SlashEffects;

		internal static ConfigEntry<bool> CustomSound;

		internal static ConfigEntry<int> ReturningThrowManaPerHitConfig;

		private static Driver driver;

		private static Harmony harmony;

		internal static int ReturningThrowManaPerHit
		{
			get
			{
				if (ReturningThrowManaPerHitConfig != null)
				{
					return Math.Max(0, ReturningThrowManaPerHitConfig.Value);
				}
				return 2;
			}
		}

		internal static Harmony HarmonyInstance => harmony;

		internal static bool ModEnabled
		{
			get
			{
				if (Enabled != null)
				{
					return Enabled.Value;
				}
				return true;
			}
		}

		private void Awake()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Register the melee spells and scrolls. Off leaves the game exactly as it shipped.");
			Diagnostics = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Diagnostics", true, "Log when a melee spell is cast, and what the registration did. Turn off once it works.");
			ReturningThrowManaPerHitConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Returning Throw", "ManaPerHit", 2, new ConfigDescription("Mana drained each time Returning Throw lands a hit.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50), Array.Empty<object>()));
			CustomSound = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "CustomSound", true, "Play the bundled MP3s (assets/dualslash.mp3 for Dual Blade Slash, assets/spearstab.mp3 for Piercing Step) in addition to the equipped weapon's own strike sound.");
			SlashEffects = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "Particles", true, "Spawn the game's Drain particle cloud along the slash (a short trail during the slide and a puff where it stops).");
			MeleeSpellSfx.Enabled = CustomSound.Value;
			MeleeSpellVfx.Enabled = SlashEffects.Value;
			harmony = new Harmony("mikhailkillszombies.fate.meleespells");
			MeleeSpellHooks.Apply(harmony);
			MeleeSpellDebug.WriteMarker("plugin awake");
			EnsureDriver();
			SceneManager.sceneLoaded += delegate
			{
				EnsureDriver();
			};
			Log.LogInfo((object)"FATE Melee Spells 0.8.54 loaded. Waiting for the game database.");
		}

		private static void EnsureDriver()
		{
			//IL_0013: 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_001e: Expected O, but got Unknown
			if (!((Object)(object)driver != (Object)null))
			{
				GameObject val = new GameObject("FATE.MeleeSpellsDriver");
				Object.DontDestroyOnLoad((Object)val);
				driver = val.AddComponent<Driver>();
			}
		}
	}
	internal static class MeleeSpellRuntime
	{
		private static readonly Dictionary<string, float> ReadyAt = new Dictionary<string, float>();

		private static readonly MethodInfo ModifyMana = typeof(Character).GetMethod("ModifyMana", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo ModifyStamina = typeof(Character).GetMethod("ModifyStamina", BindingFlags.Instance | BindingFlags.NonPublic);

		private static float lastEntryLog;

		internal static void EntryLog(string text)
		{
			if (!(Time.unscaledTime - lastEntryLog < 0.5f))
			{
				lastEntryLog = Time.unscaledTime;
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)text);
				}
			}
		}

		private static string Name(SpellData spell)
		{
			object obj;
			if (!((Object)(object)spell == (Object)null))
			{
				obj = spell.spellName;
				if (obj == null)
				{
					return ((Object)spell).name;
				}
			}
			else
			{
				obj = "none";
			}
			return (string)obj;
		}

		internal static MeleeSpellDef DefOf(SpellData spell)
		{
			if (spell == null || spell.spellName == null)
			{
				return null;
			}
			MeleeSpellDef[] spells = SpellCatalog.Spells;
			foreach (MeleeSpellDef meleeSpellDef in spells)
			{
				if (meleeSpellDef.Id == spell.spellName)
				{
					return meleeSpellDef;
				}
			}
			return null;
		}

		internal static bool IsOurs(SpellData spell)
		{
			if (spell != null && spell.spellName != null)
			{
				return spell.spellName.StartsWith("MeleeSpell_", StringComparison.Ordinal);
			}
			return false;
		}

		internal static bool BeforeCast(Character __instance, ref bool __result)
		{
			EntryLog("gate entered: active=" + Name((__instance != null) ? __instance.GetActiveSpell : null));
			if (!MeleeSpellPlugin.ModEnabled || (Object)(object)__instance == (Object)null)
			{
				return true;
			}
			SpellData getActiveSpell = __instance.GetActiveSpell;
			if (!IsOurs(getActiveSpell))
			{
				return true;
			}
			MeleeSpellDef meleeSpellDef = DefOf(getActiveSpell);
			if (meleeSpellDef != null && !meleeSpellDef.Implemented)
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: no behaviour yet.", "Melee Spells: " + meleeSpellDef.DisplayName + " cannot be cast yet", ref __result);
			}
			if (meleeSpellDef != null && meleeSpellDef.RequiresDualWield && !__instance.IsDualWielding)
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: not dual wielding.", "Melee Spells: " + meleeSpellDef.DisplayName + " needs a weapon in each hand", ref __result);
			}
			if (meleeSpellDef != null && meleeSpellDef.RequiresShield && !AegisStance.HasShield(__instance))
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: no shield equipped.", "Melee Spells: " + meleeSpellDef.DisplayName + " needs a shield in the off-hand", ref __result);
			}
			if (meleeSpellDef != null && meleeSpellDef.RequiresSpearOrPolearm && !PiercingStep.HasSpearOrPolearm(__instance))
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: no spear or polearm equipped.", PiercingStep.RefusalText(__instance), ref __result);
			}
			if (meleeSpellDef != null && meleeSpellDef.RequiresWhirlingWeapon && !WhirlingMaelstrom.HasEligibleWeapon(__instance))
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: no eligible melee weapon.", WhirlingMaelstrom.RefusalText(__instance), ref __result);
			}
			if (meleeSpellDef != null && meleeSpellDef.RequiresReturningWeapon && !ReturningThrow.HasEligibleWeapon(__instance))
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: unsuitable right-hand weapon.", ReturningThrow.RefusalText(__instance), ref __result);
			}
			if (meleeSpellDef != null && meleeSpellDef.RequiresReturningWeapon && ReturningThrow.InFlight(__instance))
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: the weapon is still in flight.", null, ref __result);
			}
			if (meleeSpellDef != null && meleeSpellDef.Id == "MeleeSpell_Shadowstep" && !Shadowstep.HasGroundTarget(__instance))
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: no ground under the cursor.", "Melee Spells: Shadowstep needs ground under the cursor", ref __result);
			}
			if (ReadyAt.TryGetValue(getActiveSpell.spellName, out var value) && Time.time < value)
			{
				return Refuse(__instance, getActiveSpell.spellName + " refused: on cooldown for " + (value - Time.time).ToString("0.00") + "s.", null, ref __result);
			}
			return true;
		}

		private static bool Refuse(Character caster, string log, string pop, ref bool result)
		{
			ManualLogSource log2 = MeleeSpellPlugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)log);
			}
			if (pop != null)
			{
				MeleeSpellDebug.Pop(pop);
			}
			ResumeWalking(caster);
			result = false;
			return false;
		}

		internal static void ResumeWalking(Character caster)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			//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_0060: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)caster == (Object)null || !caster.IsPlayer())
				{
					return;
				}
				InputBroker instance = SingletonBehaviour<InputBroker>.Instance;
				if ((Object)(object)instance == (Object)null || (int)instance.LocalInputBehavior != 1)
				{
					return;
				}
				NavMeshAgent component = ((Component)caster).GetComponent<NavMeshAgent>();
				if (!((Object)(object)component == (Object)null) && ((Behaviour)component).enabled && component.isOnNavMesh)
				{
					Vector3 destination = component.destination;
					Vector3 val = destination - ((Component)caster).transform.position;
					if (!(((Vector3)(ref val)).sqrMagnitude < 0.25f))
					{
						instance.SetMoveDestination(destination);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Could not resume the walk after a refused cast: " + ex.Message));
				}
			}
		}

		internal static void AfterCastAccepted(Character __instance, bool __result)
		{
			if (!__result || (Object)(object)__instance == (Object)null || !MeleeSpellPlugin.ModEnabled)
			{
				return;
			}
			SpellData getActiveSpell = __instance.GetActiveSpell;
			if (IsOurs(getActiveSpell))
			{
				MeleeSpellDef meleeSpellDef = DefOf(getActiveSpell);
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)("Cast accepted: " + getActiveSpell.spellName + " (castTime " + getActiveSpell.castTime.ToString("0.00") + ")"));
				}
				if (meleeSpellDef != null)
				{
					ReadyAt[getActiveSpell.spellName] = Time.time + Mathf.Max(meleeSpellDef.Cooldown, meleeSpellDef.CastTime);
				}
			}
		}

		private static void Charge(Character caster, MeleeSpellDef def)
		{
			try
			{
				if (def.Mana > 0)
				{
					ModifyMana?.Invoke(caster, new object[1] { 0f - (float)def.Mana });
				}
				if (def.Stamina > 0)
				{
					ModifyStamina?.Invoke(caster, new object[1] { 0f - (float)def.Stamina });
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Could not charge " + def.DisplayName + ": " + ex.Message));
				}
			}
		}

		internal static void DrainMana(Character caster, int amount)
		{
			if ((Object)(object)caster == (Object)null || amount <= 0 || ModifyMana == null)
			{
				return;
			}
			try
			{
				ModifyMana.Invoke(caster, new object[1] { 0f - (float)amount });
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Could not drain hit mana: " + ex.Message));
				}
			}
		}

		internal static bool BeforeComplete(Character __instance, SpellData overrideSpell)
		{
			EntryLog("CompleteSpell prefix entered: active=" + Name((__instance != null) ? __instance.GetActiveSpell : null) + ", override=" + Name(overrideSpell) + ", caster type=" + (((Object)(object)__instance != (Object)null) ? ((object)__instance).GetType().FullName : "none"));
			if (!MeleeSpellPlugin.ModEnabled || (Object)(object)__instance == (Object)null)
			{
				return true;
			}
			SpellData val = (((Object)(object)overrideSpell != (Object)null) ? overrideSpell : __instance.GetActiveSpell);
			if (!IsOurs(val))
			{
				return true;
			}
			MeleeSpellDef meleeSpellDef = DefOf(val);
			if (meleeSpellDef == null || !meleeSpellDef.Implemented)
			{
				return false;
			}
			if (meleeSpellDef.RequiresDualWield && !__instance.IsDualWielding)
			{
				return false;
			}
			if (meleeSpellDef.RequiresShield && !AegisStance.HasShield(__instance))
			{
				return false;
			}
			if (meleeSpellDef.RequiresSpearOrPolearm && !PiercingStep.HasSpearOrPolearm(__instance))
			{
				return false;
			}
			if (meleeSpellDef.RequiresWhirlingWeapon && !WhirlingMaelstrom.HasEligibleWeapon(__instance))
			{
				return false;
			}
			if (meleeSpellDef.RequiresReturningWeapon && (!ReturningThrow.HasEligibleWeapon(__instance) || ReturningThrow.InFlight(__instance)))
			{
				return false;
			}
			if (meleeSpellDef.RequiresWhirlingWeapon)
			{
				WhirlingMaelstrom.lastCompleteCall = Time.time;
			}
			if (ReadyAt.TryGetValue(val.spellName, out var value) && Time.time < value)
			{
				return false;
			}
			ReadyAt[val.spellName] = Time.time + Mathf.Max(meleeSpellDef.Cooldown, meleeSpellDef.CastTime);
			MeleeSpellDebug.Pop(meleeSpellDef.DisplayName + " cast");
			Charge(__instance, meleeSpellDef);
			ManualLogSource log = MeleeSpellPlugin.Log;
			if (log != null)
			{
				log.LogInfo((object)("Casting " + meleeSpellDef.DisplayName + " for " + (__instance.IsPlayer() ? "the player" : ((Object)__instance).name) + ": paid " + meleeSpellDef.Mana + " mana / " + meleeSpellDef.Stamina + " stamina, cooldown " + (ReadyAt[val.spellName] - Time.time).ToString("0.00") + "s."));
			}
			Begin(val, __instance);
			return false;
		}

		internal static void Begin(SpellData spell, Character caster)
		{
			if ((Object)(object)caster == (Object)null || (Object)(object)spell == (Object)null)
			{
				return;
			}
			MeleeSpellDef meleeSpellDef = DefOf(spell);
			ManualLogSource log = MeleeSpellPlugin.Log;
			if (log != null)
			{
				log.LogInfo((object)("CompleteSpell reached for " + spell.spellName + " (caster " + (caster.IsPlayer() ? "player" : ((Object)caster).name) + ")."));
			}
			if (meleeSpellDef != null && !meleeSpellDef.Implemented)
			{
				return;
			}
			switch (spell.spellName)
			{
			case "MeleeSpell_DualBladeSlash":
				DualBladeSlash.Cast(caster, meleeSpellDef);
				return;
			case "MeleeSpell_AegisStance":
				AegisStance.Begin(caster);
				return;
			case "MeleeSpell_PiercingStep":
				PiercingStep.Cast(caster, meleeSpellDef);
				return;
			case "MeleeSpell_Shadowstep":
				Shadowstep.Cast(caster, meleeSpellDef);
				return;
			case "MeleeSpell_WhirlingMaelstrom":
				WhirlingMaelstrom.Start(caster);
				return;
			case "MeleeSpell_ReturningEdge":
				ReturningThrow.Cast(caster, meleeSpellDef);
				return;
			}
			ManualLogSource log2 = MeleeSpellPlugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)(spell.spellName + ": no behaviour implemented yet."));
			}
		}
	}
	internal static class MeleeSpellSfx
	{
		internal const string SlashFileName = "dualslash.mp3";

		internal const string SpearFileName = "spearstab.mp3";

		internal const string TeleportFileName = "teleport.mp3";

		internal const string SpinFileName = "spin.mp3";

		internal const string PoofFileName = "poof.mp3";

		internal const string PoofWavFileName = "poof.wav";

		internal const string BlockFileName = "block.mp3";

		internal const string ThrowFileName = "throw.mp3";

		internal const string CatchFileName = "catch.mp3";

		internal static bool Enabled = true;

		private static AudioClip slashClip;

		private static AudioClip spearClip;

		private static AudioClip teleportClip;

		private static AudioClip spinClip;

		private static AudioClip poofClip;

		private static AudioClip blockClip;

		private static AudioClip throwClip;

		private static AudioClip catchClip;

		private static AudioSource spinSource;

		private static GameObject spinHost;

		private static bool loadRequested;

		internal static void EnsureLoaded(MonoBehaviour host)
		{
			if (loadRequested || (Object)(object)host == (Object)null)
			{
				return;
			}
			loadRequested = true;
			try
			{
				string text = Path.Combine(Path.GetDirectoryName(typeof(MeleeSpellSfx).Assembly.Location) ?? ".", "assets");
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)("Melee sound loader starting from " + text + "."));
				}
				host.StartCoroutine(Load(MeleeSpellPlugin.Log, text));
			}
			catch (Exception ex)
			{
				loadRequested = false;
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Could not start the melee sound loader: " + ex.Message));
				}
			}
		}

		private static IEnumerator Load(ManualLogSource log, string directory)
		{
			yield return LoadOne(log, directory, "dualslash.mp3", "DualBladeSlashSfx", delegate(AudioClip clip)
			{
				slashClip = clip;
			}, (AudioType)13);
			yield return LoadOne(log, directory, "spearstab.mp3", "PiercingStepSfx", delegate(AudioClip clip)
			{
				spearClip = clip;
			}, (AudioType)13);
			yield return LoadOne(log, directory, "teleport.mp3", "ShadowstepSfx", delegate(AudioClip clip)
			{
				teleportClip = clip;
			}, (AudioType)13);
			yield return LoadOne(log, directory, "spin.mp3", "WhirlingMaelstromSfx", delegate(AudioClip clip)
			{
				spinClip = clip;
			}, (AudioType)13);
			yield return LoadOne(log, directory, "poof.mp3", "ShadowstepPoofSfx", delegate(AudioClip clip)
			{
				poofClip = clip;
			}, (AudioType)13);
			if ((Object)(object)poofClip == (Object)null)
			{
				yield return LoadOne(log, directory, "poof.wav", "ShadowstepPoofSfx", delegate(AudioClip clip)
				{
					poofClip = clip;
				}, (AudioType)20);
			}
			yield return LoadOne(log, directory, "block.mp3", "AegisBlockSfx", delegate(AudioClip clip)
			{
				blockClip = clip;
			}, (AudioType)13);
			yield return LoadOne(log, directory, "throw.mp3", "ReturningThrowSfx", delegate(AudioClip clip)
			{
				throwClip = clip;
			}, (AudioType)13);
			yield return LoadOne(log, directory, "catch.mp3", "ReturningThrowCatchSfx", delegate(AudioClip clip)
			{
				catchClip = clip;
			}, (AudioType)13);
		}

		private static IEnumerator LoadOne(ManualLogSource log, string directory, string fileName, string clipName, Action<AudioClip> assign, AudioType type = (AudioType)13)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(directory, fileName);
			if (!File.Exists(path))
			{
				if (log != null)
				{
					log.LogWarning((object)("Melee sound not found: " + path));
				}
				yield break;
			}
			string absoluteUri = new Uri(path).AbsoluteUri;
			UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(absoluteUri, type);
			try
			{
				yield return request.SendWebRequest();
				if ((int)request.result != 1)
				{
					if (log != null)
					{
						log.LogWarning((object)("Could not load the melee sound " + fileName + ": " + request.error));
					}
					yield break;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(request);
				if ((Object)(object)content == (Object)null)
				{
					if (log != null)
					{
						log.LogWarning((object)("The melee sound loaded as an empty clip: " + path));
					}
					yield break;
				}
				((Object)content).name = clipName;
				assign(content);
				if (log != null)
				{
					log.LogInfo((object)("Melee sound loaded: " + content.length.ToString("0.00") + "s from " + path));
				}
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}

		internal static void Play(Player player)
		{
			PlayAt(slashClip, (Character)(object)player, "Dual Blade Slash");
		}

		internal static void PlaySpear(Player player)
		{
			PlayAt(spearClip, (Character)(object)player, "Piercing Step");
		}

		internal static void PlaySpinLoop(Character caster)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			StopSpin();
			if (!Enabled || (Object)(object)caster == (Object)null)
			{
				return;
			}
			if ((Object)(object)spinClip == (Object)null)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"Spinning Maelstrom: the custom sound is still loading.");
				}
				return;
			}
			try
			{
				spinHost = new GameObject("FATE.MeleeSpellSpinAudio");
				spinHost.transform.SetParent(((Component)caster).transform, false);
				spinSource = spinHost.AddComponent<AudioSource>();
				spinSource.clip = spinClip;
				spinSource.loop = true;
				spinSource.playOnAwake = false;
				spinSource.spatialBlend = 1f;
				spinSource.volume = 1f;
				spinSource.minDistance = 2f;
				spinSource.maxDistance = 30f;
				spinSource.Play();
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Spinning Maelstrom spin loop failed: " + ex.Message));
				}
				StopSpin();
			}
		}

		internal static GameObject PlaySpinLoopOn(Transform parent)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_003d: 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_0098: Expected O, but got Unknown
			if (!Enabled || (Object)(object)parent == (Object)null || (Object)(object)spinClip == (Object)null)
			{
				return null;
			}
			try
			{
				GameObject val = new GameObject("FATE.ReturningThrowSpinAudio");
				val.transform.SetParent(parent, false);
				val.transform.localPosition = Vector3.zero;
				AudioSource obj = val.AddComponent<AudioSource>();
				obj.clip = spinClip;
				obj.loop = true;
				obj.playOnAwake = false;
				obj.spatialBlend = 1f;
				obj.volume = 1f;
				obj.minDistance = 2f;
				obj.maxDistance = 30f;
				obj.Play();
				return val;
			}
			catch (Exception ex)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Returning Throw spin sound failed: " + ex.Message));
				}
				return null;
			}
		}

		internal static void StopSpin()
		{
			try
			{
				if ((Object)(object)spinSource != (Object)null)
				{
					spinSource.Stop();
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)spinHost != (Object)null)
				{
					Object.Destroy((Object)(object)spinHost);
				}
			}
			catch
			{
			}
			spinSource = null;
			spinHost = null;
		}

		internal static void PlayTeleport(Character caster)
		{
			PlayAt(teleportClip, caster, "Shadowstep");
		}

		internal static void PlayPoof(Character caster)
		{
			PlayAt(poofClip, caster, "Shadowstep poof");
		}

		internal static void PlayBlock(Character caster)
		{
			PlayAt(blockClip, caster, "Aegis block");
		}

		internal static void PlayThrow(Character caster)
		{
			PlayAt(throwClip, caster, "Returning Throw");
		}

		internal static void PlayCatch(Character caster)
		{
			PlayAt(catchClip, caster, "Returning Throw catch");
		}

		private static void PlayAt(AudioClip clip, Character player, string label)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			if (!Enabled || (Object)(object)player == (Object)null)
			{
				return;
			}
			if ((Object)(object)clip == (Object)null)
			{
				ManualLogSource log = MeleeSpellPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)(label + ": the custom sound is still loading."));
				}
				return;
			}
			try
			{
				AudioSource.PlayClipAtPoint(clip, ((Component)player).transform.position + Vector3.up, 1f);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)(label + " sound failed: " + ex.Message));
				}
			}
		}
	}
	internal sealed class MeleeSpellSpin : MonoBehaviour
	{
		private Transform visual;

		private float startedAt;

		private float seconds;

		private float degrees;

		private bool running;

		private Quaternion baseRotation;

		private Quaternion applied;

		private bool hasApplied;

		internal static void Run(Player player, float degrees, float seconds)
		{
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			try
			{
				Transform val = VisualRoot(player);
				if ((Object)(object)val == (Object)null)
				{
					ManualLogSource log = MeleeSpellPlugin.Log;
					if (log != null)
					{
						log.LogInfo((object)"Dual Blade Slash spin skipped: no visual root was found.");
					}
					return;
				}
				MeleeSpellSpin meleeSpellSpin = ((Component)player).GetComponent<MeleeSpellSpin>();
				if ((Object)(object)meleeSpellSpin == (Object)null)
				{
					meleeSpellSpin = ((Component)player).gameObject.AddComponent<MeleeSpellSpin>();
				}
				meleeSpellSpin.Begin(val, degrees, seconds);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = MeleeSpellPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Dual Blade Slash spin could not start: " + ex.Message));
				}
			}
		}

		private static Transform VisualRoot(Player player)
		{
			Transform val = null;
			try
			{
				SkinnedMeshRenderer componentInChildren = ((Component)player).GetComponentInChildren<SkinnedMeshRenderer>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					val = componentInChildren.rootBone;
					if ((Object)(object)val == (Object)null && componentInChildren.bones != null && componentInChildren.bones.Length != 0)
					{
						val = componentInChildren.bones[0];
					}
				}
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null)
			{
				try
				{
					Animator component = ((Component)player).GetComponent<Animator>();
					if ((Object)(object)component != (Object)null)
					{
						val = component.GetBoneTransform((HumanBodyBones)0);
					}
				}
				catch
				{
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				Transform val2 = val;
				while ((Object)(object)val2.parent != (Object)null && (Object)(object)val2.parent != (Object)(object)((Component)player).transform)
				{
					val2 = val2.parent;
				}
				if ((Object)(object)val2.parent == (Object)(object)((Component)player).transform && (Object)(object)val2 != (Object)(object)((Component)player).transform)
				{
					return val2;
				}
			}
			try
			{
				CharacterCustomizationDefaults componentInChildren2 = ((Component)player).GetComponentInChildren<CharacterCustomizationDefaults>(true);
				if ((Object)(object)componentInChildren2 != (Object)null && (Object)(object)((Component)componentInChildren2).transform != (Object)(object)((Component)player).transform && ((Component)componentInChildren2).transform.IsChildOf(((Component)player).transform))
				{
					return ((Component)componentInChildren2).transform;
				}
			}
			catch
			{
			}
			return null;
		}

		internal void Begin(Transform root, float degrees, float seconds)
		{
			//IL_003c: 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_0041: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			visual = root;
			this.degrees = degrees;
			this.seconds = Mathf.Max(0.05f, seconds);
			startedAt = Time.time;
			baseRotation = (((Object)(object)root != (Object)null) ? root.localRotation : Quaternion.identity);
			applied = Quaternion.identity;
			hasApplied = false;
			running = true;
		}

		private void LateUpdate()
		{
			//IL_0059: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			if (!running || (Object)(object)visual == (Object)null)
			{
				return;
			}
			float num = (Time.time - startedAt) / seconds;
			if (num >= 1f)
			{
				visual.localRotation = baseRotation;
				running = false;
				visual = null;
				return;
			}
			Quaternion localRotation = visual.localRotation;
			if (hasApplied && Quaternion.Angle(localRotation, applied) > 0.01f)
			{
				baseRotation = localRotation;
			}
			float num2 = degrees * Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num));
			Quaternion val = (((Object)(object)visual.parent != (Object)null) ? visual.parent.rotation : Quaternion.identity);
			applied = Quaternion.Inverse(val) * Quaternion.AngleAxis(num2, Vector3.up) * val * baseRotation;
			visual.localRotation = applied;
			hasApplied = true;
		}
	}
	internal static class MeleeSpellVfx
	{
		internal static bool Enabled = true;

		internal static readonly string[] TornadoNames = new string[6] { "Twister", "Tkala_Whirlwind", "Whirlwind", "Dervish", "DustStorm", "Shockwave" };

		private static readonly string[] TrailNames = new string[5] { "EdgeStream", "SparckleTrail", "Spinspark", "Spark", "Glint" };

		private static readonly string[] BurstNames = new string[5] { "EdgeBurst", "Spinspark", "Spark", "Explosion", "Shockwave" };

		private static readonly string[] ImpactNames = new string[6] { "Orb_HitSpark", "LightSpark", "Glint", "ImpactSpark_01", "Spark", "Spinspark" };

		private static readonly string[] PoofNames = new string[8] { "EvilMagicSmoke", "Fear", "OrbSpark", "Orb_HitSpark", "Spark", "Spinspark", "PoisonPuff", "Poison" };

		internal static readonly Color ShadowstepPoof = new Color(0.62f, 0.3f, 0.95f, 1f);

		private static readonly string[] SlashTrail = N("Drain");

		private static readonly string[] SlashBurst = N("Drain", "EdgeBurst", "Spinspark");

		private static float lastMissingLog;

		private static string[] N(params string[] names)
		{
			return names;
		}

		inter