Decompiled source of CatsCards v1.0.4

CatsCards.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using CatsCards.Lightsaber;
using CatsCards.Lightsaber.Extensions;
using HarmonyLib;
using InControl;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using ModdingUtils.Utils;
using RarityLib.Utils;
using UnboundLib;
using UnboundLib.Cards;
using UnboundLib.Extensions;
using UnboundLib.GameModes;
using UnboundLib.Networking;
using UnboundLib.Utils;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CatsCards
{
	public class CardHolder : MonoBehaviour
	{
		public List<GameObject> Cards;

		public List<GameObject> HiddenCards;

		internal void RegisterCards()
		{
			foreach (GameObject Card in Cards)
			{
				RarityAdder rarityAdder = Card.GetComponent<RarityAdder>();
				if (rarityAdder != null)
				{
					ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)CatsCards.instance, 5, (Action)delegate
					{
						//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)
						Card.GetComponent<CardInfo>().rarity = RarityUtils.GetRarity($"{rarityAdder.rarity}");
					});
				}
				CustomCard.RegisterUnityCard(Card, CatsCards.modInitials, Card.GetComponent<CardInfo>().cardName, true, (Action<CardInfo>)null);
			}
			foreach (GameObject Card2 in HiddenCards)
			{
				RarityAdder rarityAdder2 = Card2.GetComponent<RarityAdder>();
				if (rarityAdder2 != null)
				{
					ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)CatsCards.instance, 5, (Action)delegate
					{
						//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)
						Card2.GetComponent<CardInfo>().rarity = RarityUtils.GetRarity($"{rarityAdder2.rarity}");
					});
				}
				CustomCard.RegisterUnityCard(Card2, CatsCards.modInitials, Card2.GetComponent<CardInfo>().cardName, false, (Action<CardInfo>)null);
				Cards.instance.AddHiddenCard(Card2.GetComponent<CardInfo>());
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.CatsCards.Cats", "Cats Cards", "1.0.4")]
	[BepInProcess("Rounds.exe")]
	public class CatsCards : BaseUnityPlugin
	{
		internal static AssetBundle assets;

		internal static CatsCards instance;

		internal static readonly string modInitials = "Cats";

		private const string ModId = "com.CatsCards.Cats";

		private const string ModName = "Cats Cards";

		public const string Version = "1.0.4";

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.CatsCards.Cats").PatchAll();
			instance = this;
			GameModeManager.AddHook("BattleStart", (Func<IGameModeHandler, IEnumerator>)ObjectSlash.Enable);
			GameModeManager.AddHook("PointEnd", (Func<IGameModeHandler, IEnumerator>)ObjectSlash.Disable);
			assets = AssetUtils.LoadAssetBundleFromResources("assetbundle", typeof(CatsCards).Assembly);
			assets.LoadAsset<GameObject>("ModCards").GetComponent<CardHolder>().RegisterCards();
		}

		public void OnDestroy()
		{
			GameModeManager.RemoveHook("PointEnd", (Func<IGameModeHandler, IEnumerator>)ObjectSlash.Disable);
			GameModeManager.RemoveHook("PointStart", (Func<IGameModeHandler, IEnumerator>)ObjectSlash.Enable);
		}
	}
	public static class Constants
	{
		public const string PlayerObjectCollider = "PlayerObjectCollider";

		public const string Lightsaber = "Lightsaber";

		public const string Damagable = "Damagable";

		public const string ModCards = "ModCards";

		public const string Spring = "Spring";

		public const string CardBase = "CardBase(Clone)";

		public const string AssetBundle = "assetbundle";

		public const string AmmoCanvas = "Ammo/Canvas";

		public const string ProcessName = "Rounds.exe";

		public const string CardChoiceSpawnUniqueCardPatch = "pykess.rounds.plugins.cardchoicespawnuniquecardpatch";

		public const string RarityBundle = "com.CrazyCoders.Rounds.RarityBundle";

		public const string ModdingUtils = "pykess.rounds.plugins.moddingutils";

		public const string ActionHelper = "com.rounds.willuwontu.ActionHelper";

		public const string UnboundLib = "com.willis.rounds.unbound";

		public const string CardThemeLib = "root.cardtheme.lib";

		public const string RarityLib = "root.rarity.lib";
	}
	public class LoadAsset : MonoBehaviour
	{
		public GameObject Object;

		public GameObject InstantiateObject(Transform transform)
		{
			Object = Instantiate(((Object)Object).name, transform);
			return Object;
		}

		private static GameObject Instantiate(string ObjectName, Transform transform)
		{
			GameObject obj = Object.Instantiate<GameObject>(CatsCards.assets.LoadAsset<GameObject>(ObjectName), transform);
			((Object)obj).name = ObjectName;
			return obj;
		}
	}
	internal class RarityAdder : MonoBehaviour
	{
		public Rarity rarity = Rarity.Common;
	}
	public enum Rarity
	{
		Trinket,
		Common,
		Scarce,
		Uncommon,
		Exotic,
		Rare,
		Epic,
		Legendary,
		Mythical,
		Divine
	}
}
namespace CatsCards.MonoBehaviors.SquishPlayer
{
	[Serializable]
	[HarmonyPatch(typeof(Player), "FullReset")]
	internal class PlayerFullResetPatch
	{
		private static void Prefix(Player __instance)
		{
			Object.Destroy((Object)(object)((Component)__instance).GetComponentInChildren<A_HoldableObject>());
		}
	}
}
namespace CatsCards.Lightsaber
{
	public class A_HoldableHandler : MonoBehaviour
	{
		internal Player Player;

		internal ObjectSlash ObjectSlash;

		internal ObjectMirror ObjectMirror;

		internal ObjectCollider ObjectCollider;

		internal BladeColor BladeColor;

		internal GameObject Collider;

		internal GameObject Weapon;

		internal GameObject Blade;

		public A_HoldableHandler Initialize(A_HoldableObject HoldableObject, Player player, string WeaponName = "BackupInit")
		{
			if (HoldableObject.Weapon == null || (Object)(object)HoldableObject.Weapon == (Object)null)
			{
				HoldableObject.Weapon = Object.Instantiate<GameObject>(CatsCards.assets.LoadAsset<GameObject>(WeaponName), player.GetSpring().transform);
				((Object)HoldableObject.Weapon.gameObject).name = WeaponName;
			}
			Player = player;
			Weapon = HoldableObject.Weapon;
			Blade = ((Component)Weapon.transform.Find("Blade")).gameObject;
			Collider = ((Component)Blade.transform.Find("Collider")).gameObject;
			ObjectMirror = ExtensionMethods.GetOrAddComponent<ObjectMirror>(Weapon, false);
			ObjectSlash = ExtensionMethods.GetOrAddComponent<ObjectSlash>(Weapon, false).Initialize(Player);
			ObjectCollider = ExtensionMethods.GetOrAddComponent<ObjectCollider>(Collider.gameObject, false).IgnoreCollisions(ObjectSlash);
			ObjectSlash.Collider = ObjectCollider;
			ObjectSlash.Mirror = ObjectMirror;
			BladeColor = ExtensionMethods.GetOrAddComponent<BladeColor>(Blade.gameObject, false).Initialize(player.playerID);
			ObjectSlash.holdableObject = HoldableObject;
			ObjectMirror.holdableObject = HoldableObject;
			ObjectCollider.holdableObject = HoldableObject;
			BladeColor.holdableObject = HoldableObject;
			return this;
		}

		public void OnDestroy()
		{
			Object.Destroy((Object)(object)ObjectSlash);
			Object.Destroy((Object)(object)ObjectMirror);
			Object.Destroy((Object)(object)ObjectCollider);
			Object.Destroy((Object)(object)BladeColor);
			Object.Destroy((Object)(object)Collider);
			Object.Destroy((Object)(object)Weapon);
			Object.Destroy((Object)(object)Blade);
		}
	}
	public class A_HoldableObject : MonoBehaviour
	{
		public UnityEvent TriggerSFX;

		public LoadAsset asset;

		internal A_HoldableHandler Handler;

		internal GameObject Weapon;

		private Player Player;

		private const float Volume = 1f;

		internal const float SwitchDelay = 0.25f;

		internal const float ResetSwitchTimer = 0f;

		private float StabTimer;

		private bool wasOut;

		internal float SwitchTimer { get; private set; }

		internal bool IsOut { get; private set; }

		private void Start()
		{
			IsOut = false;
			StabTimer = 0f;
			SwitchTimer = 0f;
			Player = ((Component)this).GetComponentInParent<Player>();
			Weapon = asset.InstantiateObject(Player.GetSpring().transform);
			Handler = ExtensionMethods.GetOrAddComponent<A_HoldableHandler>(((Component)this).gameObject, false).Initialize(this, Player, "Lightsaber");
			Player.data.stats.objectsAddedToPlayer.Add(Weapon);
			NetworkingManager.RPC(typeof(A_HoldableObject), "RPCA_Switch_To_Holdable", new object[3] { Player.playerID, true, false });
			NetworkingManager.RPC(typeof(A_HoldableObject), "RPCA_Switch_To_Holdable", new object[3] { Player.playerID, false, false });
		}

		private void OnDisable()
		{
			if (Player != null && Player.data.view.IsMine && IsOut && !wasOut)
			{
				IsOut = false;
				wasOut = true;
				NetworkingManager.RPC(typeof(A_HoldableObject), "RPCA_Switch_To_Holdable", new object[3] { Player.playerID, false, false });
			}
		}

		private void OnEnable()
		{
			if (Player != null && Player.data.view.IsMine && !Player.data.dead && !IsOut && wasOut)
			{
				IsOut = true;
				wasOut = false;
				NetworkingManager.RPC(typeof(A_HoldableObject), "RPCA_Switch_To_Holdable", new object[3] { Player.playerID, true, false });
			}
		}

		private void Update()
		{
			if (Player != null && Player.data.view.IsMine && !Player.data.dead)
			{
				StabTimer -= TimeHandler.deltaTime;
				SwitchTimer -= TimeHandler.deltaTime;
				if (!(SwitchTimer > 0f) && ((OneAxisInputControl)Player.data.playerActions.GetAdditionalData().SwitchHoldable).WasPressed)
				{
					SwitchTimer = (IsOut ? 0f : 0.25f);
					IsOut = !IsOut;
					NetworkingManager.RPC(typeof(A_HoldableObject), "RPCA_Switch_To_Holdable", new object[3] { Player.playerID, IsOut, IsOut });
				}
			}
		}

		[UnboundRPC]
		internal static void RPCA_Switch_To_Holdable(int stabbingPlayerID, bool holdableObj, bool playSFX)
		{
			MakeGunHoldable(stabbingPlayerID, holdableObj, playSFX);
		}

		private static void MoveToHide(Transform transform, bool hide)
		{
			//IL_0002: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, hide ? (-10000f) : 0f);
		}

		internal static void MakeGunHoldable(int playerID, bool holdableObj, bool playSFX = false)
		{
			Player playerWithID = PlayerManager.instance.GetPlayerWithID(playerID);
			if (playerWithID != null)
			{
				A_HoldableObject componentInChildren = ((Component)playerWithID).GetComponentInChildren<A_HoldableObject>();
				if (playSFX)
				{
					componentInChildren.TriggerSFX.Invoke();
				}
				((Component)componentInChildren).gameObject.GetComponent<A_HoldableHandler>().Weapon.SetActive(holdableObj);
				GameObject spring = playerWithID.GetSpring();
				MoveToHide(spring.transform.Find("Ammo/Canvas"), holdableObj);
				MoveToHide(spring.transform.GetChild(2), holdableObj);
				MoveToHide(spring.transform.GetChild(3), holdableObj);
				((Behaviour)((Component)spring.transform.GetChild(2)).GetComponent<RightLeftMirrorSpring>()).enabled = !holdableObj;
				((Behaviour)((Component)spring.transform.GetChild(3)).GetComponent<RightLeftMirrorSpring>()).enabled = !holdableObj;
				playerWithID.GetGun().GetData().disabled = holdableObj;
			}
		}

		private void OnDestroy()
		{
			if (Player != null)
			{
				NetworkingManager.RPC(typeof(A_HoldableObject), "RPCA_Switch_To_Holdable", new object[3] { Player.playerID, false, false });
				Object.Destroy((Object)(object)Handler);
			}
		}
	}
	internal class BladeColor : MonoBehaviour
	{
		internal A_HoldableObject holdableObject;

		private static SpriteRenderer render;

		private static PlayerSkin skin;

		private static Player player;

		private static Color color;

		internal BladeColor Initialize(int playerID)
		{
			//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)
			player = PlayerManager.instance.GetPlayerWithID(playerID);
			skin = ExtraPlayerSkins.GetPlayerSkinColors(PlayerExtensions.colorID(player));
			color = skin.color;
			render = ((Component)this).gameObject.GetComponent<SpriteRenderer>();
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)Unbound.Instance, 10, (Action)UpdateBladeColor);
			return this;
		}

		public static void UpdateBladeColor()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			RPCA_UpdateBladeColor(color);
		}

		[UnboundRPC]
		private static void RPCA_UpdateBladeColor(Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			render.color = color;
		}
	}
	public class ObjectCollider : MonoBehaviour
	{
		internal A_HoldableObject holdableObject;

		internal ObjectSlash ObjectSlash;

		internal Collider2D collider;

		internal ObjectCollider IgnoreCollisions(ObjectSlash objectSlash)
		{
			((Component)this).gameObject.layer = LayerMask.NameToLayer("PlayerObjectCollider");
			collider = ((Component)this).GetComponent<Collider2D>();
			collider.attachedRigidbody.mass = 500f;
			collider.isTrigger = false;
			ObjectSlash = objectSlash;
			Collider2D[] componentsInChildren = ((Component)ObjectSlash.Player).GetComponentsInChildren<Collider2D>();
			foreach (Collider2D val in componentsInChildren)
			{
				Physics2D.IgnoreCollision(collider, val);
			}
			IgnoreLayerCollision();
			return this;
		}

		public static void IgnoreLayerCollision()
		{
			Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("PlayerObjectCollider"), LayerMask.NameToLayer("Player"));
		}

		private void OnCollider(Collider2D collider2D)
		{
			ObjectSlash?.TrySlash(collider2D);
		}

		private void OnCollision(Collision2D collision2D)
		{
			ObjectSlash?.TrySlash(collision2D);
		}

		private void OnTriggerEnter2D(Collider2D collider2D)
		{
			OnCollider(collider2D);
		}

		private void OnTriggerStay2D(Collider2D collider2D)
		{
			OnCollider(collider2D);
		}

		private void OnCollisionEnter2D(Collision2D collision)
		{
			OnCollision(collision);
		}

		private void OnCollisionStay2D(Collision2D collision)
		{
			OnCollision(collision);
		}
	}
	public class ObjectMirror : MonoBehaviour
	{
		internal A_HoldableObject holdableObject;

		private Holdable holdable;

		private static readonly Vector3 LeftPos = new Vector3(0.1f, 1.95f, 0f);

		private static readonly Vector3 RightPos = new Vector3(0.4f, 1.95f, 0f);

		private static readonly Vector3 LeftScale = new Vector3(-1f, 1f, 1f);

		private static readonly Vector3 RightScale = new Vector3(-1f, -1f, 1f);

		internal Vector3 positionMod = Vector3.zero;

		private const float LeftRot = 300f;

		private const float RightRot = 225f;

		internal float rotMod;

		private void Start()
		{
			holdable = ((Component)((Component)this).transform.root).GetComponent<Holdable>();
		}

		private void Update()
		{
			//IL_0022: 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_005f: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			if (holdable != null && holdable.holder != null)
			{
				bool flag = ((Component)this).transform.root.position.x - 0.1f < ((Component)holdable.holder).transform.position.x;
				((Component)this).transform.localScale = (flag ? LeftScale : RightScale);
				float num = (flag ? 300f : 225f) + rotMod * (flag ? (-1f) : 1f);
				((Component)this).transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, num));
				Vector3 localPosition = (flag ? LeftPos : RightPos) + new Vector3(positionMod.x * (flag ? (-1f) : 1f), positionMod.y, positionMod.z);
				((Component)this).transform.localPosition = localPosition;
			}
		}
	}
	public class ObjectSlash : MonoBehaviour
	{
		public static bool CanAttack = false;

		internal A_HoldableObject holdableObject;

		internal GameObject OnHitEffect;

		private const float slashAnimationDuration = 0.25f;

		private const float slashCooldown = 0.3f;

		private float sinceSlash = 0.3f;

		private bool canDoDamage;

		private bool isSlashing;

		private Holdable Holdable;

		internal Player Player;

		internal ObjectCollider Collider;

		internal ObjectMirror Mirror;

		private GeneralInput Input;

		private static readonly AnimationCurve[] SlashCurves = (AnimationCurve[])(object)new AnimationCurve[3]
		{
			new AnimationCurve((Keyframe[])(object)new Keyframe[7]
			{
				new Keyframe(0f, 0f, 1f, 1f, 1f, 1f),
				new Keyframe(0.0625f, 0.1f, 1f, 1f, 1f, 1f),
				new Keyframe(0.25f, 0.35f, 2f, 2f, 1f, 1f),
				new Keyframe(2f / 3f, 0f, 1f, 1f, 1f, 1f),
				new Keyframe(5f / 6f, -0.2f, 1f, 1f, 1f, 1f),
				new Keyframe(0.875f, -0.1f, 1f, 1f, 1f, 1f),
				new Keyframe(1f, 0f, 1f, 1f, 1f, 1f)
			}),
			new AnimationCurve((Keyframe[])(object)new Keyframe[7]
			{
				new Keyframe(0f, 0f, 1f, 1f, 1f, 1f),
				new Keyframe(0.0625f, -0.15f, 1f, 1f, 1f, 1f),
				new Keyframe(0.25f, 0.2f, 1f, 1f, 1f, 1f),
				new Keyframe(2f / 3f, 0.4f, 1f, 1f, 1f, 1f),
				new Keyframe(5f / 6f, 0.25f, 1f, 1f, 1f, 1f),
				new Keyframe(0.875f, -0.05f, 1f, 1f, 1f, 1f),
				new Keyframe(1f, 0f, 1f, 1f, 1f, 1f)
			}),
			new AnimationCurve((Keyframe[])(object)new Keyframe[7]
			{
				new Keyframe(0f, 0f, 1f, 1f, 1f, 1f),
				new Keyframe(0.0625f, 5f, 1f, 1f, 1f, 1f),
				new Keyframe(0.25f, 40f, 1f, 1f, 1f, 1f),
				new Keyframe(2f / 3f, 0f, 1f, 1f, 1f, 1f),
				new Keyframe(5f / 6f, -20f, 1f, 1f, 1f, 1f),
				new Keyframe(0.875f, -10f, 1f, 1f, 1f, 1f),
				new Keyframe(1f, 0f, 1f, 1f, 1f, 1f)
			})
		};

		private List<Collider2D> HitColliders = new List<Collider2D>();

		private List<Player> HitPlayers = new List<Player>();

		private const float slashForceMultiplier = 1500f;

		private const float nonSlashForceMultiplier = 500f;

		internal ObjectSlash Initialize(Player player, GameObject OnHitEffect = null)
		{
			Holdable = ((Component)((Component)this).transform.root).GetComponent<Holdable>();
			Player = player;
			Input = Player.data.input;
			isSlashing = false;
			this.OnHitEffect = OnHitEffect;
			return this;
		}

		private void DoSlash()
		{
			if (holdableObject.IsOut)
			{
				sinceSlash = 0f;
				canDoDamage = true;
				DoSlashAnimation();
				if (Player.data.view.IsMine)
				{
					NetworkingManager.RPC_Others(typeof(ObjectSlash), "RPCA_DoSlashAnimation", new object[1] { Player.playerID });
				}
			}
		}

		[UnboundRPC]
		private static void RPCA_DoSlashAnimation(int playerID)
		{
			Player playerWithID = PlayerManager.instance.GetPlayerWithID(playerID);
			if (playerWithID != null)
			{
				((Component)((Component)playerWithID.GetGun()).transform.GetChild(1).Find("Lightsaber")).GetComponent<ObjectSlash>().DoSlashAnimation();
			}
		}

		internal void DoSlashAnimation()
		{
			((MonoBehaviour)this).StartCoroutine(IDoSlashAnimation());
		}

		private IEnumerator IDoSlashAnimation()
		{
			isSlashing = true;
			HitPlayers = new List<Player>();
			if ((Object)(object)Holdable == (Object)null)
			{
				Holdable = ((Component)((Component)this).transform.root).GetComponent<Holdable>();
			}
			float deltaTime = 0f;
			float num = Mathf.Clamp(deltaTime / 0.25f, 0f, 1f);
			Mirror.rotMod = SlashCurves[2].Evaluate(num);
			Vector3 val = default(Vector3);
			while (deltaTime < 0.25f)
			{
				yield return null;
				deltaTime += TimeHandler.deltaTime;
				num = Mathf.Clamp(deltaTime / 0.25f, 0f, 1f);
				bool flag = ((Component)this).transform.root.position.x - 0.1f < ((Component)Holdable.holder).transform.position.x;
				((Component)this).transform.root.position = Player.data.hand.position;
				((Vector3)(ref val))..ctor(SlashCurves[1].Evaluate(num), SlashCurves[0].Evaluate(num) * (flag ? (-1f) : 1f), 0f);
				Vector2 val2 = Vector2.op_Implicit(((Vector3)(ref Player.data.aimDirection)).normalized);
				Vector2 val3 = Vector2.op_Implicit(((Vector3)(ref val)).normalized);
				Transform root = ((Component)this).transform.root;
				root.position += Quaternion.Euler(0f, 0f, Vector2.Angle(val2, val3)) * val;
				Mirror.rotMod = SlashCurves[2].Evaluate(num);
			}
			Mirror.rotMod = 0f;
			isSlashing = false;
		}

		private void Update()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			sinceSlash += TimeHandler.deltaTime;
			if (Player.data.view.IsMine)
			{
				if (!isSlashing)
				{
					((Component)this).transform.root.position = Player.data.hand.position;
				}
				if (holdableObject.IsOut && Input.shootWasPressed && !(holdableObject.SwitchTimer > 0f) && !(sinceSlash < 0.3f))
				{
					DoSlash();
				}
			}
		}

		internal void TrySlash(Collider2D collider2D)
		{
			if (Player.data.view.IsMine && canDoDamage && !((Object)(object)collider2D == (Object)null))
			{
				Player component = ((Component)collider2D).GetComponent<Player>();
				if (!((Object)(object)component == (Object)null) && !component.data.dead && component.playerID != Player.playerID)
				{
					canDoDamage = false;
					NetworkingManager.RPC(typeof(ObjectSlash), "RPCA_SlashPlayer", new object[2]
					{
						Player.playerID,
						((Component)collider2D).GetComponent<Player>().playerID
					});
				}
			}
		}

		internal void TrySlash(Collision2D collision)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			Collider2D collider2D = collision.collider;
			if (!Player.data.view.IsMine || (Object)(object)collider2D == (Object)null || collision.contactCount <= 0 || HitColliders.Contains(collider2D))
			{
				return;
			}
			HitColliders.Add(collider2D);
			ExtensionMethods.ExecuteAfterSeconds((MonoBehaviour)(object)CatsCards.instance, 0.25f, (Action)delegate
			{
				HitColliders.Remove(collider2D);
			});
			Vector3 position = ((Component)this).gameObject.transform.position;
			if (Object.op_Implicit((Object)(object)((Component)collider2D).GetComponentInParent<Player>()))
			{
				if (((Component)collider2D).GetComponentInParent<Player>().playerID != Player.playerID)
				{
					Player componentInParent = ((Component)collider2D).GetComponentInParent<Player>();
					if (!HitPlayers.Contains(componentInParent))
					{
						HitPlayers.Add(componentInParent);
						HandlePlayer(componentInParent, collision);
					}
				}
			}
			else if (Object.op_Implicit((Object)(object)((Component)collider2D).GetComponentInParent<ProjectileHit>()))
			{
				HandleBullet(((Component)collider2D).GetComponentInParent<ProjectileHit>(), collision);
			}
			else if ((Object)(object)collider2D.attachedRigidbody != (Object)null)
			{
				HandleBox(collider2D.attachedRigidbody, collision);
			}
			else if (isSlashing && Object.op_Implicit((Object)(object)((Component)((Component)collider2D).transform.root).GetComponentInChildren<Damagable>()))
			{
				((Component)((Component)collider2D).transform.root).GetComponentInChildren<Damagable>().CallTakeDamage(Vector2.up * 55f, Vector2.op_Implicit(position), (GameObject)null, Player, true);
			}
		}

		internal void HandlePlayer(Player target, Collision2D collision)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (isSlashing && CanAttack)
			{
				NetworkingManager.RPC(typeof(ObjectSlash), "RPCA_SlashPlayer", new object[2] { Player.playerID, target.playerID });
				Gun gun = Player.data.weaponHandler.gun;
				float num = (float)ExtensionMethods.GetFieldValue((object)target.data.playerVel, "mass") / 100f;
				float num2 = Mathf.Pow(gun.damage, 2f) * gun.knockback * Mathf.Clamp(num, 0f, 1f);
				target.data.healthHandler.CallTakeForce(num2 * ((ContactPoint2D)(ref collision.contacts[0])).point, (ForceMode2D)1, false, false, 0f);
			}
		}

		internal void HandleBox(Rigidbody2D box, Collision2D collision)
		{
			//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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)((Component)box).GetComponent<Damagable>()) && isSlashing)
			{
				Gun gun = Player.data.weaponHandler.gun;
				Damagable component = ((Component)box).GetComponent<Damagable>();
				Vector2 point = ((ContactPoint2D)(ref collision.contacts[0])).point;
				Vector3 position = ((Component)this).transform.position;
				Vector2 val = Vector2.op_Implicit(((Vector3)(ref position)).normalized);
				component.CallTakeDamage(55f * gun.damage * gun.bulletDamageMultiplier * (point - val), point, (GameObject)null, (Player)null, true);
			}
			ContactPoint2D[] array = (ContactPoint2D[])(object)new ContactPoint2D[collision.contactCount];
			int contacts = collision.GetContacts(array);
			for (int i = 0; i < contacts; i++)
			{
				box.AddForceAtPosition(Player.data.weaponHandler.gun.knockback * box.mass * -1f * ((ContactPoint2D)(ref array[i])).normal * (isSlashing ? 1500f : 500f) / (float)contacts, ((ContactPoint2D)(ref array[i])).point);
			}
		}

		internal void HandleBullet(ProjectileHit bullet, Collision2D collision)
		{
			//IL_0021: 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)
			Player.data.block.blocked(((Component)bullet).gameObject, ((Component)bullet).gameObject.transform.forward, collision.transform.position);
		}

		[UnboundRPC]
		private static void RPCA_SlashPlayer(int slashingPlayerID, int slashedPlayerID)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (slashedPlayerID == -1)
			{
				return;
			}
			Player playerWithID = PlayerManager.instance.GetPlayerWithID(slashingPlayerID);
			Player playerWithID2 = PlayerManager.instance.GetPlayerWithID(slashedPlayerID);
			if ((Object)(object)playerWithID2 == (Object)null || (Object)(object)playerWithID == (Object)null)
			{
				return;
			}
			Gun gun = playerWithID.GetGun();
			float damage = gun.damage;
			float bulletDamageMultiplier = gun.bulletDamageMultiplier;
			HealthHandler healthHandler = playerWithID2.data.healthHandler;
			Vector2 val = Vector2.op_Implicit(damage * bulletDamageMultiplier * 55f * gun.shootPosition.forward);
			Vector2 val2 = Vector2.op_Implicit(((Component)playerWithID2).transform.position);
			Color white = Color.white;
			Transform transform = ((Component)gun).transform;
			object obj;
			if (transform == null)
			{
				obj = null;
			}
			else
			{
				Transform child = transform.GetChild(1);
				if (child == null)
				{
					obj = null;
				}
				else
				{
					Transform obj2 = child.Find("Lightsaber");
					obj = ((obj2 != null) ? ((Component)obj2).gameObject : null);
				}
			}
			healthHandler.DoDamage(val, val2, white, (GameObject)obj, playerWithID, false, true, true);
		}

		public static IEnumerator Enable(IGameModeHandler gm)
		{
			CanAttack = true;
			yield break;
		}

		public static IEnumerator Disable(IGameModeHandler gm)
		{
			CanAttack = false;
			yield break;
		}
	}
}
namespace CatsCards.Lightsaber.Patches
{
	[HarmonyPatch(typeof(Gun))]
	internal class AttackPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Attack")]
		private static bool ToggleGun(Gun __instance)
		{
			return !__instance.GetData().disabled;
		}
	}
	[HarmonyPatch(typeof(PlayerActions))]
	public static class PlayerActionsPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static void CreatePlayerAction(PlayerActions __instance)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			__instance.GetAdditionalData().SwitchHoldable = (PlayerAction)typeof(PlayerActions).InvokeMember("CreatePlayerAction", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, __instance, new object[1] { "SwitchHoldable" });
		}

		[HarmonyPostfix]
		[HarmonyPatch("CreateWithKeyboardBindings")]
		private static void CreateWithKeyboardBindings(ref PlayerActions __result)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			__result.GetAdditionalData().SwitchHoldable.AddDefaultBinding((BindingSource)new KeyBindingSource((Key[])(object)new Key[1] { (Key)5 }));
		}

		[HarmonyPostfix]
		[HarmonyPatch("CreateWithControllerBindings")]
		private static void CreateWithControllerBindings(ref PlayerActions __result)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			__result.GetAdditionalData().SwitchHoldable.AddDefaultBinding((BindingSource)new DeviceBindingSource((InputControlType)12));
		}
	}
}
namespace CatsCards.Lightsaber.Extensions
{
	public static class GameObjectExtensions
	{
		public static T GetOrAddComponentInChildren<T>(this GameObject go) where T : Component
		{
			T val = go.GetComponentInChildren<T>();
			if ((Object)(object)val == (Object)null)
			{
				val = go.AddComponent<T>();
			}
			return val;
		}

		public static RightLeftMirrorSpring GetSpringMirror(this GameObject spring)
		{
			return ((Component)spring.transform.GetChild(2)).GetComponent<RightLeftMirrorSpring>();
		}
	}
	public class GunAdditionalData
	{
		public bool disabled;
	}
	public static class GunExtensions
	{
		private static readonly ConditionalWeakTable<Gun, GunAdditionalData> additionalData = new ConditionalWeakTable<Gun, GunAdditionalData>();

		public static GunAdditionalData GetData(this Gun instance)
		{
			return additionalData.GetOrCreateValue(instance);
		}

		public static void DisableGun(this Gun instance)
		{
			instance.GetData().disabled = true;
		}

		public static void EnableGun(this Gun instance)
		{
			instance.GetData().disabled = false;
		}

		public static GameObject GetSpring(this Gun gun)
		{
			return ((Component)((Component)gun).transform.Find("Spring")).gameObject;
		}

		public static RightLeftMirrorSpring GetSpringMirror(this Gun gun)
		{
			return gun.GetSpring().GetSpringMirror();
		}
	}
	[Serializable]
	public class PlayerActionsAdditionalData
	{
		public PlayerAction SwitchHoldable;

		public PlayerActionsAdditionalData()
		{
			SwitchHoldable = null;
		}
	}
	public static class PlayerActionsExtension
	{
		public static readonly ConditionalWeakTable<PlayerActions, PlayerActionsAdditionalData> data = new ConditionalWeakTable<PlayerActions, PlayerActionsAdditionalData>();

		public static PlayerActionsAdditionalData GetAdditionalData(this PlayerActions playerActions)
		{
			return data.GetOrCreateValue(playerActions);
		}

		public static void AddData(this PlayerActions playerActions, PlayerActionsAdditionalData value)
		{
			try
			{
				data.Add(playerActions, value);
			}
			catch (Exception)
			{
			}
		}
	}
	public static class PlayerExtensions
	{
		public static Gun GetGun(this Player player)
		{
			if (player == null)
			{
				return null;
			}
			return ((Component)((Component)player).GetComponent<Holding>().holdable).GetComponent<Gun>();
		}

		public static GameObject GetSpring(this Player player)
		{
			return player.GetGun().GetSpring();
		}
	}
	public static class PlayerManagerExtensions
	{
		public static Player GetPlayerWithID(this PlayerManager instance, int playerID)
		{
			return ((IEnumerable<Player>)instance.players).FirstOrDefault((Func<Player, bool>)((Player p) => p.playerID == playerID));
		}

		public static void ForEachPlayer(this PlayerManager instance, Action<Player> action)
		{
			foreach (Player player in instance.players)
			{
				action(player);
			}
		}

		public static RightLeftMirrorSpring GetSpringMirror(this Player player)
		{
			return player.GetGun().GetSpringMirror();
		}
	}
}