Decompiled source of Sword Moveset Overhaul v1.0.0

BepInEx/plugins/SwordMovesetOverhaul/SwordMovesetOverhaul.Animation.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using UnityEngine;

[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SwordMovesetOverhaul;

public static class FirstSwing
{
	[HarmonyPatch(typeof(CharacterAnimEvent), "Speed")]
	private static class ClipSpeedPatch
	{
		[HarmonyPriority(0)]
		private static void Prefix(CharacterAnimEvent __instance, ref float __0)
		{
			if (Matches(__instance))
			{
				BaseSpeed = __0;
				__0 *= Multiplier;
			}
		}
	}

	[HarmonyPatch(typeof(CharacterAnimEvent), "CustomFixedUpdate")]
	private static class FixedSpeedPatch
	{
		[HarmonyPriority(0)]
		private static void Postfix(CharacterAnimEvent __instance)
		{
			if (Matches(__instance))
			{
				Tick();
			}
		}
	}

	[HarmonyPatch(typeof(ZSyncAnimation), "SetSpeed")]
	private static class SyncSpeedPatch
	{
		[HarmonyPriority(0)]
		private static void Prefix(ZSyncAnimation __instance, ref float __0)
		{
			if (Active && Object.op_Implicit((Object)(object)Animator) && !((Object)/*isinst with value type is only supported in some contexts*/ != (Object)(object)Animator))
			{
				BaseSpeed = __0;
				__0 *= Multiplier;
			}
		}
	}

	public const float FirstOpeningMultiplier = 3f;

	public const float FirstMultiplier = 1.4f;

	public const float SecondMultiplier = 1.05f;

	public const float ThirdOpeningMultiplier = 0.5f;

	public const float ThirdMultiplier = 0.95f;

	public const float HeavyOpeningMultiplier = 1f;

	public const float HeavyMultiplier = 1f;

	public const float HeavySlowdownSeconds = 0.15f;

	public const float HeavySlowdownMultiplier = 0.5f;

	public const float HeavyFinishingMultiplier = 1.5f;

	public const float HeavyOpeningSeconds = 0.3f;

	public const float HeavyFinishingSeconds = 0.2f;

	public const float FirstOpeningSeconds = 0.1f;

	public const float ThirdOpeningSeconds = 0.05f;

	private static readonly FieldInfo AnimatorField = AccessTools.Field(typeof(ZSyncAnimation), "m_animator");

	private static readonly FieldInfo EventAnimatorField = AccessTools.Field(typeof(CharacterAnimEvent), "m_animator");

	private static readonly FieldInfo PauseTimerField = AccessTools.Field(typeof(CharacterAnimEvent), "m_pauseTimer");

	private static readonly FieldInfo PauseSpeedField = AccessTools.Field(typeof(CharacterAnimEvent), "m_pauseSpeed");

	private static Player Owner;

	private static Animator Animator;

	private static CharacterAnimEvent Events;

	private static OpeningEvents Receiver;

	private static bool Active;

	private static bool Entered;

	private static bool PhasedSwing;

	private static bool OpeningDone;

	private static bool HasEventStart;

	private static bool HeavySwing;

	private static bool FinishingDone;

	private static int PreviousStateHash;

	private static int EventStateHash;

	private static int DiagnosticCount;

	private static float PreviousNormalizedTime;

	private static float Multiplier = 1f;

	private static float AfterOpeningMultiplier = 1f;

	private static float BaseSpeed;

	private static float Started;

	private static float OpeningEndSeconds;

	private static AnimationClip EventClip;

	public static void Init()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("fai.swordmovesetoverhaul.animations").PatchAll(typeof(FirstSwing).Assembly);
	}

	public static void Remap(object instance, ref string name)
	{
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		ZSyncAnimation val = (ZSyncAnimation)((instance is ZSyncAnimation) ? instance : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		Player componentInParent = ((Component)val).GetComponentInParent<Player>();
		if (Object.op_Implicit((Object)(object)componentInParent) && (Object)(object)componentInParent == (Object)(object)Player.m_localPlayer)
		{
			End();
			if (name == "swing_longsword0" || name == "swing_longsword1" || name == "swing_longsword2" || name == "sword_secondary")
			{
				object? value = AnimatorField.GetValue(val);
				Animator val2 = (Animator)((value is Animator) ? value : null);
				if (Object.op_Implicit((Object)(object)val2))
				{
					Owner = componentInParent;
					Animator = val2;
					Events = ((Component)val2).GetComponent<CharacterAnimEvent>();
					Receiver = ((Component)val2).GetComponent<OpeningEvents>();
					if (!Object.op_Implicit((Object)(object)Receiver))
					{
						Receiver = ((Component)val2).gameObject.AddComponent<OpeningEvents>();
					}
					bool flag = Receiver.EnsureInstalled(val2);
					HeavySwing = name == "sword_secondary";
					PhasedSwing = name != "swing_longsword1" && flag;
					AfterOpeningMultiplier = ((name == "swing_longsword0") ? 1.4f : ((!(name == "swing_longsword2")) ? 1f : 0.95f));
					OpeningEndSeconds = (HeavySwing ? 0.3f : ((!(name == "swing_longsword0")) ? 0.05f : 0.1f));
					Multiplier = ((name == "swing_longsword1") ? 1.05f : ((!PhasedSwing) ? AfterOpeningMultiplier : (HeavySwing ? 1f : ((!(name == "swing_longsword0")) ? 0.5f : 3f))));
					AnimatorStateInfo currentAnimatorStateInfo = val2.GetCurrentAnimatorStateInfo(0);
					PreviousStateHash = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash;
					PreviousNormalizedTime = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime;
					BaseSpeed = val2.speed;
					Started = Time.unscaledTime;
					Entered = false;
					Active = true;
					OpeningDone = false;
					HasEventStart = false;
					FinishingDone = false;
					EventClip = null;
					val2.speed = BaseSpeed * Multiplier;
				}
			}
		}
		if (name == "swing_longsword0")
		{
			name = "swing_axe0";
		}
	}

	private static bool IsPaused()
	{
		return Object.op_Implicit((Object)(object)Events) && (float)PauseTimerField.GetValue(Events) > 0f;
	}

	private static bool IsOwnedEvent(OpeningEvents sender, AnimationEvent e)
	{
		//IL_0037: 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)
		int result;
		if (Active && PhasedSwing && (Object)(object)sender == (Object)(object)Receiver && e != null && e.isFiredByAnimator)
		{
			AnimatorClipInfo animatorClipInfo = e.animatorClipInfo;
			result = (sender.IsOwnedClip(((AnimatorClipInfo)(ref animatorClipInfo)).clip) ? 1 : 0);
		}
		else
		{
			result = 0;
		}
		return (byte)result != 0;
	}

	private static bool IsOurEvent(OpeningEvents sender, AnimationEvent e)
	{
		return !OpeningDone && IsOwnedEvent(sender, e);
	}

	public static void OpeningStart(OpeningEvents sender, AnimationEvent e)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		if (IsOurEvent(sender, e))
		{
			AnimatorStateInfo animatorStateInfo = e.animatorStateInfo;
			if (((AnimatorStateInfo)(ref animatorStateInfo)).fullPathHash != PreviousStateHash || !(((AnimatorStateInfo)(ref animatorStateInfo)).normalizedTime >= PreviousNormalizedTime) || !(PreviousNormalizedTime > 0.001f))
			{
				HasEventStart = true;
				EventStateHash = ((AnimatorStateInfo)(ref animatorStateInfo)).fullPathHash;
				AnimatorClipInfo animatorClipInfo = e.animatorClipInfo;
				EventClip = ((AnimatorClipInfo)(ref animatorClipInfo)).clip;
			}
		}
	}

	private static bool MatchesEventState(AnimationEvent e)
	{
		//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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		AnimatorStateInfo animatorStateInfo = e.animatorStateInfo;
		if (HasEventStart)
		{
			int result;
			if (((AnimatorStateInfo)(ref animatorStateInfo)).fullPathHash == EventStateHash)
			{
				AnimatorClipInfo animatorClipInfo = e.animatorClipInfo;
				result = (((Object)(object)((AnimatorClipInfo)(ref animatorClipInfo)).clip == (Object)(object)EventClip) ? 1 : 0);
			}
			else
			{
				result = 0;
			}
			return (byte)result != 0;
		}
		return ((AnimatorStateInfo)(ref animatorStateInfo)).fullPathHash != PreviousStateHash || ((AnimatorStateInfo)(ref animatorStateInfo)).normalizedTime < PreviousNormalizedTime - 0.0001f;
	}

	private static void ApplyMultiplier(float value)
	{
		Multiplier = value;
		if (IsPaused())
		{
			PauseSpeedField.SetValue(Events, BaseSpeed * Multiplier);
		}
		else if (Object.op_Implicit((Object)(object)Animator))
		{
			Animator.speed = BaseSpeed * Multiplier;
		}
	}

	private static void LogSwitch(string phase, AnimationEvent e)
	{
		if (DiagnosticCount++ < 6)
		{
			Debug.Log((object)("[SwordMovesetOverhaul 1.0.0] " + phase + " switched at animation event t=" + e.time + " to multiplier " + Multiplier));
		}
	}

	public static void OpeningEnd(OpeningEvents sender, AnimationEvent e)
	{
		if (IsOurEvent(sender, e) && !(Math.Abs(e.time - OpeningEndSeconds) > 1E-05f) && MatchesEventState(e))
		{
			OpeningDone = true;
			ApplyMultiplier(AfterOpeningMultiplier);
			LogSwitch("Opening", e);
		}
	}

	public static void HeavySlowdown(OpeningEvents sender, AnimationEvent e)
	{
		if (HeavySwing && IsOurEvent(sender, e) && MatchesEventState(e) && !(Math.Abs(e.time - 0.15f) > 1E-05f))
		{
			ApplyMultiplier(0.5f);
			LogSwitch("Heavy slowdown", e);
		}
	}

	public static float HeavyFinishingTime(AnimationClip clip)
	{
		return Math.Max(0.3f, clip.length - 0.2f);
	}

	public static void HeavyFinishing(OpeningEvents sender, AnimationEvent e)
	{
		//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)
		if (HeavySwing && !FinishingDone && IsOwnedEvent(sender, e) && MatchesEventState(e))
		{
			float time = e.time;
			AnimatorClipInfo animatorClipInfo = e.animatorClipInfo;
			if (!(Math.Abs(time - HeavyFinishingTime(((AnimatorClipInfo)(ref animatorClipInfo)).clip)) > 1E-05f))
			{
				OpeningDone = true;
				FinishingDone = true;
				ApplyMultiplier(1.5f);
				LogSwitch("Heavy finishing", e);
			}
		}
	}

	private static void End()
	{
		if (Active && Object.op_Implicit((Object)(object)Animator))
		{
			if (IsPaused())
			{
				PauseSpeedField.SetValue(Events, BaseSpeed);
			}
			else
			{
				Animator.speed = BaseSpeed;
			}
		}
		Active = false;
		Entered = false;
		PhasedSwing = false;
		OpeningDone = false;
		HasEventStart = false;
		HeavySwing = false;
		FinishingDone = false;
		Multiplier = 1f;
		AfterOpeningMultiplier = 1f;
		EventClip = null;
		Owner = null;
		Animator = null;
		Events = null;
	}

	public static void Tick()
	{
		if (!Active)
		{
			return;
		}
		if (!Object.op_Implicit((Object)(object)Owner) || !Object.op_Implicit((Object)(object)Animator) || (Object)(object)Owner != (Object)(object)Player.m_localPlayer)
		{
			End();
			return;
		}
		if (((Character)Owner).InAttack())
		{
			Entered = true;
		}
		else if (Entered || Time.unscaledTime - Started > 0.5f)
		{
			End();
			return;
		}
		if (Time.unscaledTime - Started > 4f)
		{
			End();
		}
		else if (!IsPaused())
		{
			Animator.speed = BaseSpeed * Multiplier;
		}
	}

	public static void Shutdown()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		End();
		if (Object.op_Implicit((Object)(object)Receiver))
		{
			Receiver.Release();
		}
		Receiver = null;
		new Harmony("fai.swordmovesetoverhaul.animations").UnpatchSelf();
	}

	private static bool Matches(CharacterAnimEvent e)
	{
		return Active && Object.op_Implicit((Object)(object)Animator) && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)Animator;
	}
}
public sealed class OpeningEvents : MonoBehaviour
{
	private Animator animator;

	private RuntimeAnimatorController original;

	private AnimatorOverrideController controller;

	private readonly HashSet<AnimationClip> clones = new HashSet<AnimationClip>();

	private static bool IsAttackClip(AnimationClip clip)
	{
		if (!Object.op_Implicit((Object)(object)clip) || clip.length <= 0.1f)
		{
			return false;
		}
		AnimationEvent[] events = clip.events;
		foreach (AnimationEvent val in events)
		{
			if (val.functionName == "Hit" || val.functionName == "OnAttackTrigger" || val.functionName == "Chain")
			{
				return true;
			}
		}
		return false;
	}

	public bool IsOwnedClip(AnimationClip clip)
	{
		return Object.op_Implicit((Object)(object)clip) && clones.Contains(clip);
	}

	public bool EnsureInstalled(Animator a)
	{
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Expected O, but got Unknown
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Expected O, but got Unknown
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Expected O, but got Unknown
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Expected O, but got Unknown
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Expected O, but got Unknown
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Expected O, but got Unknown
		if (Object.op_Implicit((Object)(object)controller) && (Object)(object)animator == (Object)(object)a && (Object)(object)a.runtimeAnimatorController == (Object)(object)controller)
		{
			return clones.Count > 0;
		}
		Release();
		animator = a;
		original = a.runtimeAnimatorController;
		if (!Object.op_Implicit((Object)(object)original))
		{
			Debug.LogWarning((object)"[SwordMovesetOverhaul 1.0.0] No animation controller; opening speed disabled.");
			return false;
		}
		try
		{
			RuntimeAnimatorController runtimeAnimatorController = original;
			while (runtimeAnimatorController is AnimatorOverrideController)
			{
				runtimeAnimatorController = ((AnimatorOverrideController)runtimeAnimatorController).runtimeAnimatorController;
			}
			controller = new AnimatorOverrideController(runtimeAnimatorController);
			List<KeyValuePair<AnimationClip, AnimationClip>> list = new List<KeyValuePair<AnimationClip, AnimationClip>>();
			controller.GetOverrides(list);
			RuntimeAnimatorController obj = original;
			AnimatorOverrideController val = (AnimatorOverrideController)(object)((obj is AnimatorOverrideController) ? obj : null);
			Dictionary<AnimationClip, AnimationClip> dictionary = new Dictionary<AnimationClip, AnimationClip>();
			if (Object.op_Implicit((Object)(object)val))
			{
				List<KeyValuePair<AnimationClip, AnimationClip>> list2 = new List<KeyValuePair<AnimationClip, AnimationClip>>();
				val.GetOverrides(list2);
				foreach (KeyValuePair<AnimationClip, AnimationClip> item in list2)
				{
					dictionary[item.Key] = item.Value;
				}
			}
			Dictionary<AnimationClip, AnimationClip> dictionary2 = new Dictionary<AnimationClip, AnimationClip>();
			for (int i = 0; i < list.Count; i++)
			{
				KeyValuePair<AnimationClip, AnimationClip> keyValuePair = list[i];
				if (!dictionary.TryGetValue(keyValuePair.Key, out var value) || !Object.op_Implicit((Object)(object)value))
				{
					value = ((!Object.op_Implicit((Object)(object)keyValuePair.Value)) ? keyValuePair.Key : keyValuePair.Value);
				}
				if (IsAttackClip(value))
				{
					if (!dictionary2.TryGetValue(value, out var value2))
					{
						value2 = Object.Instantiate<AnimationClip>(value);
						((Object)value2).name = ((Object)value).name + "_SwordMovesetOverhaulEvents";
						List<AnimationEvent> list3 = new List<AnimationEvent>(value2.events);
						AnimationEvent val2 = new AnimationEvent();
						val2.time = 0.0001f;
						val2.functionName = "SwordMovesetOverhaulOpeningStart";
						val2.messageOptions = (SendMessageOptions)1;
						list3.Add(val2);
						val2 = new AnimationEvent();
						val2.time = 0.05f;
						val2.functionName = "SwordMovesetOverhaulOpeningEnd";
						val2.messageOptions = (SendMessageOptions)1;
						list3.Add(val2);
						val2 = new AnimationEvent();
						val2.time = 0.1f;
						val2.functionName = "SwordMovesetOverhaulOpeningEnd";
						val2.messageOptions = (SendMessageOptions)1;
						list3.Add(val2);
						if (value2.length > 0.3f)
						{
							val2 = new AnimationEvent();
							val2.time = 0.15f;
							val2.functionName = "SwordMovesetOverhaulHeavySlowdown";
							val2.messageOptions = (SendMessageOptions)1;
							list3.Add(val2);
							val2 = new AnimationEvent();
							val2.time = 0.3f;
							val2.functionName = "SwordMovesetOverhaulOpeningEnd";
							val2.messageOptions = (SendMessageOptions)1;
							list3.Add(val2);
							val2 = new AnimationEvent();
							val2.time = FirstSwing.HeavyFinishingTime(value2);
							val2.functionName = "SwordMovesetOverhaulHeavyFinishing";
							val2.messageOptions = (SendMessageOptions)1;
							list3.Add(val2);
						}
						list3.Sort((AnimationEvent x, AnimationEvent y) => x.time.CompareTo(y.time));
						value2.events = list3.ToArray();
						clones.Add(value2);
						dictionary2[value] = value2;
					}
					value = value2;
				}
				list[i] = new KeyValuePair<AnimationClip, AnimationClip>(keyValuePair.Key, value);
			}
			if (clones.Count == 0)
			{
				Debug.LogWarning((object)"[SwordMovesetOverhaul 1.0.0] No attack clips found; opening speed disabled.");
				Release();
				return false;
			}
			controller.ApplyOverrides((IList<KeyValuePair<AnimationClip, AnimationClip>>)list);
			a.runtimeAnimatorController = (RuntimeAnimatorController)(object)controller;
			Debug.Log((object)("[SwordMovesetOverhaul 1.0.0] Installed light and heavy phase events on " + clones.Count + " attack clips."));
			return true;
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[SwordMovesetOverhaul 1.0.0] Opening-event setup failed: " + ex.Message));
			Release();
			return false;
		}
	}

	public void SwordMovesetOverhaulOpeningStart(AnimationEvent e)
	{
		FirstSwing.OpeningStart(this, e);
	}

	public void SwordMovesetOverhaulOpeningEnd(AnimationEvent e)
	{
		FirstSwing.OpeningEnd(this, e);
	}

	public void SwordMovesetOverhaulHeavySlowdown(AnimationEvent e)
	{
		FirstSwing.HeavySlowdown(this, e);
	}

	public void SwordMovesetOverhaulHeavyFinishing(AnimationEvent e)
	{
		FirstSwing.HeavyFinishing(this, e);
	}

	public void Release()
	{
		if (Object.op_Implicit((Object)(object)animator) && Object.op_Implicit((Object)(object)controller) && (Object)(object)animator.runtimeAnimatorController == (Object)(object)controller)
		{
			animator.runtimeAnimatorController = original;
		}
		foreach (AnimationClip clone in clones)
		{
			if (Object.op_Implicit((Object)(object)clone))
			{
				Object.Destroy((Object)(object)clone);
			}
		}
		clones.Clear();
		if (Object.op_Implicit((Object)(object)controller))
		{
			Object.Destroy((Object)(object)controller);
		}
		controller = null;
		original = null;
		animator = null;
	}

	private void OnDestroy()
	{
		Release();
	}
}

BepInEx/plugins/SwordMovesetOverhaul/SwordMovesetOverhaul.dll

Decompiled 5 days ago
using System.Reflection;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: AssemblyVersion("1.0.0.0")]
namespace SwordMovesetOverhaul;

[BepInPlugin("fai.swordmovesetoverhaul", "Sword Moveset Overhaul", "1.0.0")]
public class SwordMovesetOverhaulPlugin : BaseUnityPlugin
{
	private static float s_restoreAt;

	private static bool s_shieldHidden;

	private void Awake()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		FirstSwing.Init();
		new Harmony("fai.swordmovesetoverhaul").PatchAll();
	}

	private void Update()
	{
		if (s_shieldHidden && !(Time.unscaledTime < s_restoreAt))
		{
			RestoreShield();
		}
	}

	internal static void HideShield()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Invalid comparison between Unknown and I4
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		FieldInfo fieldInfo = AccessTools.Field(((object)Player.m_localPlayer).GetType(), "m_leftItem");
		if ((object)fieldInfo == null)
		{
			return;
		}
		ItemData val = (ItemData)fieldInfo.GetValue(Player.m_localPlayer);
		if ((int)val == 0)
		{
			return;
		}
		SharedData shared = val.m_shared;
		if (shared == null || (int)shared.m_itemType != 5)
		{
			return;
		}
		FieldInfo fieldInfo2 = AccessTools.Field(((object)Player.m_localPlayer).GetType(), "m_visEquipment");
		if ((object)fieldInfo2 == null)
		{
			return;
		}
		VisEquipment val2 = (VisEquipment)fieldInfo2.GetValue(Player.m_localPlayer);
		if (val2 == null)
		{
			return;
		}
		FieldInfo fieldInfo3 = AccessTools.Field(((object)val2).GetType(), "m_leftItemInstance");
		if ((object)fieldInfo3 != null)
		{
			GameObject val3 = (GameObject)fieldInfo3.GetValue(val2);
			if (val3 != null)
			{
				val3.SetActive(false);
				s_restoreAt = Time.unscaledTime + 1.65f;
				s_shieldHidden = true;
			}
		}
	}

	private static void RestoreShield()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		if (Player.m_localPlayer != null)
		{
			VisEquipment val = (VisEquipment)AccessTools.Field(((object)Player.m_localPlayer).GetType(), "m_visEquipment").GetValue(Player.m_localPlayer);
			if (val != null)
			{
				GameObject val2 = (GameObject)AccessTools.Field(((object)val).GetType(), "m_leftItemInstance").GetValue(val);
				if (val2 != null)
				{
					val2.SetActive(true);
				}
			}
		}
		s_shieldHidden = false;
	}

	private void LateUpdate()
	{
		FirstSwing.Tick();
	}

	private void OnDestroy()
	{
		FirstSwing.Shutdown();
	}
}
[HarmonyPatch(typeof(ZSyncAnimation), "SetTrigger")]
internal static class SwordAnimationPatch
{
	private static bool Prefix(object __instance, ref string __0)
	{
		FirstSwing.Remap(__instance, ref __0);
		if (__0 == "sword_secondary")
		{
			__0 = "greatsword2";
			object obj = ((__instance is Component) ? __instance : null);
			if (obj != null)
			{
				Component component = ((Component)obj).GetComponent(typeof(Player));
				Component obj2 = ((component is Player) ? component : null);
				if (obj2 != null && (object)obj2 == Player.m_localPlayer)
				{
					SwordMovesetOverhaulPlugin.HideShield();
				}
			}
		}
		else if (__0 == "swing_longsword2")
		{
			__0 = "dualaxes0";
		}
		return true;
	}
}
[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
internal static class DashPatch
{
	internal static Attack s_lastDashAttack;

	private static void Prefix(Attack __instance)
	{
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		if (__instance == null || !(__instance.m_attackAnimation == "sword_secondary") || Player.m_localPlayer == null)
		{
			return;
		}
		FieldInfo fieldInfo = AccessTools.Field(((object)Player.m_localPlayer).GetType(), "m_currentAttack");
		if ((object)fieldInfo == null)
		{
			return;
		}
		object? value = fieldInfo.GetValue(Player.m_localPlayer);
		object? obj = ((value is Attack) ? value : null);
		if (obj == null || obj != __instance)
		{
			return;
		}
		__instance.m_attackRange = 2.7f;
		__instance.m_attackAngle = 40f;
		__instance.m_attackRayWidth = 0.7f;
		__instance.m_multiHit = true;
		__instance.m_lowerDamagePerHit = true;
		if (s_lastDashAttack == __instance)
		{
			return;
		}
		s_lastDashAttack = __instance;
		if (!Physics.Raycast(((Component)Player.m_localPlayer).transform.position + Vector3.up * 0.8f, ((Component)Player.m_localPlayer).transform.forward, 0.3f, LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" })))
		{
			Component component = ((Component)Player.m_localPlayer).GetComponent(typeof(Rigidbody));
			Component obj2 = ((component is Rigidbody) ? component : null);
			if (obj2 != null)
			{
				((Rigidbody)obj2).position = ((Rigidbody)obj2).position + ((Component)Player.m_localPlayer).transform.forward * 0.3f;
			}
		}
	}
}