Decompiled source of CardLimit v1.0.0

CardLimit.dll

Decompiled a year 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 BepInEx.Configuration;
using HarmonyLib;
using ModdingUtils.Utils;
using ModsPlus;
using On;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnboundLib;
using UnboundLib.Extensions;
using UnboundLib.GameModes;
using UnboundLib.Networking;
using UnboundLib.Utils;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CardLimit")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CardLimit")]
[assembly: AssemblyTitle("CardLimit")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CompetitiveRounds;

[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("dev.scyye.rounds.competitiverounds.limit", "Card Limit", "1.0.0")]
[BepInProcess("Rounds.exe")]
public class Main : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static UnityAction <>9__7_0;

		public static Func<IGameModeHandler, IEnumerator> <>9__7_1;

		public static Func<IGameModeHandler, IEnumerator> <>9__7_2;

		public static hook_Awake <>9__7_3;

		internal void <Start>b__7_0()
		{
		}

		internal IEnumerator <Start>b__7_1(IGameModeHandler gm)
		{
			return MaxCardsHandler.DiscardPhase(gm, endpick: false);
		}

		internal IEnumerator <Start>b__7_2(IGameModeHandler gm)
		{
			return MaxCardsHandler.DiscardPhase(gm, endpick: true);
		}

		internal void <Start>b__7_3(orig_Awake orig, MainMenuHandler self)
		{
			if ((Object)(object)MaxCardsHandler.textCanvas != (Object)null)
			{
				MaxCardsHandler.textCanvas.SetActive(false);
			}
			if ((Object)(object)MaxCardsHandler.passCanvas != (Object)null)
			{
				MaxCardsHandler.passCanvas.SetActive(false);
			}
			ToggleCardsMenuHandler.Close();
			orig.Invoke(self);
		}
	}

	private const string ModId = "dev.scyye.rounds.competitiverounds.limit";

	private const string ModName = "Card Limit";

	private const string Version = "1.0.0";

	public static ConfigEntry<int> MaxCardsConfig;

	public static int MaxCards;

	public static Main Instance;

	private void Awake()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		Instance = this;
		MaxCardsConfig = ((BaseUnityPlugin)this).Config.Bind<int>("CardLimit", "MaxCards", 0, "Maximum number of cards a player can have");
		Harmony val = new Harmony("dev.scyye.rounds.competitiverounds.limit");
		val.PatchAll();
	}

	private void Start()
	{
		//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_0071: Expected O, but got Unknown
		//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_013d: Expected O, but got Unknown
		MaxCards = MaxCardsConfig.Value;
		Unbound.RegisterCredits("Card Limit", new string[2] { "Scyye (Modernization & Improvements)", "Pykess (Code Originally)" }, new string[1] { "github" }, new string[1] { "https://github.com/pdcook/CompetitiveRounds" });
		object obj = <>c.<>9__7_0;
		if (obj == null)
		{
			UnityAction val = delegate
			{
			};
			<>c.<>9__7_0 = val;
			obj = (object)val;
		}
		Unbound.RegisterMenu("Card Limit", (UnityAction)obj, (Action<GameObject>)NewGUI, (GameObject)null, false);
		GameModeManager.AddHook("PickStart", (Func<IGameModeHandler, IEnumerator>)((IGameModeHandler gm) => MaxCardsHandler.DiscardPhase(gm, endpick: false)));
		GameModeManager.AddHook("PickEnd", (Func<IGameModeHandler, IEnumerator>)((IGameModeHandler gm) => MaxCardsHandler.DiscardPhase(gm, endpick: true)));
		GameModeManager.AddHook("GameStart", (Func<IGameModeHandler, IEnumerator>)ResetPlayerHasPicked);
		GameModeManager.AddHook("PickEnd", (Func<IGameModeHandler, IEnumerator>)ResetPlayerHasPicked);
		Unbound.RegisterHandshake("dev.scyye.rounds.competitiverounds.limit", (Action)Sync);
		object obj2 = <>c.<>9__7_3;
		if (obj2 == null)
		{
			hook_Awake val2 = delegate(orig_Awake orig, MainMenuHandler self)
			{
				if ((Object)(object)MaxCardsHandler.textCanvas != (Object)null)
				{
					MaxCardsHandler.textCanvas.SetActive(false);
				}
				if ((Object)(object)MaxCardsHandler.passCanvas != (Object)null)
				{
					MaxCardsHandler.passCanvas.SetActive(false);
				}
				ToggleCardsMenuHandler.Close();
				orig.Invoke(self);
			};
			<>c.<>9__7_3 = val2;
			obj2 = (object)val2;
		}
		MainMenuHandler.Awake += (hook_Awake)obj2;
	}

	private void Sync()
	{
		if (PhotonNetwork.IsMasterClient)
		{
			NetworkingManager.RPC_Others(typeof(Main), "SyncMaxCards", new object[1] { MaxCards });
		}
	}

	private static IEnumerator ResetPlayerHasPicked(IGameModeHandler ignored)
	{
		foreach (Player player in PlayerManager.instance.players)
		{
			CardChoiceDoPickPatch.playerHasPicked[player] = false;
			CardChoiceVisualsShowPatch.playerHasPicked[player] = false;
		}
		yield break;
	}

	[UnboundRPC]
	private static void SyncMaxCards(int maxCards)
	{
		MaxCards = maxCards;
	}

	private void NewGUI(GameObject menu)
	{
		Slider val2 = null;
		TextMeshProUGUI val3 = default(TextMeshProUGUI);
		MenuHandler.CreateText("Competitive Rounds Options", menu, ref val3, 45, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		TextMeshProUGUI maxCardsWarning = default(TextMeshProUGUI);
		MenuHandler.CreateText(" ", menu, ref maxCardsWarning, 15, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateSlider("Maximum Number of Cards One Can Have", menu, 30, 0f, 50f, (float)MaxCardsConfig.Value, (UnityAction<float>)MaxChanged, ref val2, true, (Color?)null, (Direction)0, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		void MaxChanged(float val)
		{
			MaxCardsConfig.Value = Mathf.RoundToInt(val);
			MaxCards = MaxCardsConfig.Value;
			if (val == 0f)
			{
				((TMP_Text)maxCardsWarning).text = " ";
			}
		}
	}
}
internal class Selectable : MonoBehaviour, IPointerUpHandler, IEventSystemHandler, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler
{
	internal Player player;

	private int idx;

	private bool hover = false;

	private bool down = false;

	private Color orig;

	private Vector3 origScale;

	private void Start()
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: 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)
		orig = GetCardSquareColor();
		origScale = ((Component)this).transform.localScale;
		idx = ((Component)this).transform.GetSiblingIndex();
	}

	private Color GetCardSquareColor()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: 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)
		return CardBarUtils.instance.GetCardSquareColor(((Component)((Component)this).transform.GetChild(0)).gameObject);
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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)
		down = true;
		((Component)this).transform.localScale = Vector3.one;
		float num = default(float);
		float num2 = default(float);
		float num3 = default(float);
		Color.RGBToHSV(GetCardSquareColor(), ref num, ref num2, ref num3);
		Color val = Color.HSVToRGB(num, num2 - 0.1f, num3 - 0.1f);
		val.a = orig.a;
		CardBarUtils.instance.ChangeCardSquareColor(((Component)((Component)this).transform.GetChild(0)).gameObject, val);
	}

	public void OnPointerUp(PointerEventData eventData)
	{
		//IL_001d: 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_0044: Unknown result type (might be due to invalid IL or missing references)
		if (!down)
		{
			return;
		}
		down = false;
		((Component)this).transform.localScale = origScale;
		CardBarUtils.instance.ChangeCardSquareColor(((Component)((Component)this).transform.GetChild(0)).gameObject, orig);
		if (hover)
		{
			if (!PhotonNetwork.OfflineMode)
			{
				NetworkingManager.RPC(typeof(Selectable), "RPCA_RemoveCardOnClick", new object[2]
				{
					player.playerID,
					idx - 1
				});
			}
			else
			{
				Cards.instance.RemoveCardFromPlayer(player, idx - 1);
			}
		}
	}

	public void OnPointerEnter(PointerEventData eventData)
	{
		hover = true;
	}

	public void OnPointerExit(PointerEventData eventData)
	{
		hover = false;
	}

	private void OnDestroy()
	{
		//IL_0008: 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_002f: Unknown result type (might be due to invalid IL or missing references)
		((Component)this).transform.localScale = origScale;
		CardBarUtils.instance.ChangeCardSquareColor(((Component)((Component)this).transform.GetChild(0)).gameObject, orig);
	}

	[UnboundRPC]
	private static void RPCA_RemoveCardOnClick(int playerID, int idx)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		Cards.instance.RemoveCardFromPlayer((Player)ExtensionMethods.InvokeMethod((object)PlayerManager.instance, "GetPlayerWithID", new object[1] { playerID }), idx);
	}
}
internal static class MaxCardsHandler
{
	internal static GameObject textCanvas;

	internal static GameObject passCanvas;

	internal static GameObject passButton;

	private static TextMeshProUGUI text;

	internal static bool active = false;

	internal static bool forceRemove = false;

	internal static Dictionary<Player, bool> pass = new Dictionary<Player, bool>();

	private static Random rng = new Random();

	internal static IEnumerator DiscardPhase(IGameModeHandler gm, bool endpick)
	{
		if ((Object)(object)PlayerManager.instance.GetLastPlayerAlive() == (Object)null)
		{
			yield break;
		}
		int winningTeamID = PlayerManager.instance.GetLastPlayerAlive().teamID;
		if ((Object)(object)textCanvas == (Object)null)
		{
			CreateText();
		}
		if ((Object)(object)passCanvas == (Object)null)
		{
			CreatePassButton();
		}
		pass = new Dictionary<Player, bool>();
		foreach (Player player3 in PlayerManager.instance.players)
		{
			pass[player3] = false;
		}
		yield return (object)new WaitForSecondsRealtime(0.1f);
		if (!endpick)
		{
			foreach (Player player4 in PlayerManager.instance.players.Where((Player player) => player.teamID != winningTeamID))
			{
				if (Main.MaxCards > 0 && CardBarUtils.instance.GetCardBarSquares(player4.teamID).Length - 1 >= Main.MaxCards)
				{
					yield return Discard(player4, endpick);
				}
			}
			yield break;
		}
		foreach (Player player2 in PlayerManager.instance.players)
		{
			if (Main.MaxCards > 0 && CardBarUtils.instance.GetCardBarSquares(player2.teamID).Length - 1 > Main.MaxCards)
			{
				yield return Discard(player2, endpick);
			}
		}
	}

	private static IEnumerator Discard(Player player, bool endpick)
	{
		active = true;
		forceRemove = false;
		pass = new Dictionary<Player, bool>();
		foreach (Player p in PlayerManager.instance.players)
		{
			pass[p] = false;
		}
		int teamID = player.teamID;
		if (Main.MaxCards > 0 && CardBarUtils.instance.GetCardBarSquares(teamID).Length - 1 >= (endpick ? (Main.MaxCards + 1) : Main.MaxCards))
		{
			textCanvas.SetActive(true);
			if (!endpick && player.data.view.IsMine)
			{
				passCanvas.SetActive(true);
				ExtensionMethods.GetOrAddComponent<PassButtonSelectable>(passButton, false).player = player;
			}
			_ = Color.clear;
			Color orig;
			try
			{
				orig = CardBarUtils.instance.GetPlayersBarColor(teamID);
			}
			catch
			{
				yield break;
			}
			Transform transform = ((Component)CardBarUtils.instance.PlayersCardBar(teamID)).gameObject.transform;
			transform.localPosition += CardBarUtils.localShift;
			float h = default(float);
			float s = default(float);
			float v = default(float);
			while (Main.MaxCards > 0 && CardBarUtils.instance.GetCardBarSquares(teamID).Length - 1 >= (endpick ? (Main.MaxCards + 1) : Main.MaxCards))
			{
				((Component)CardBarUtils.instance.PlayersCardBar(teamID)).gameObject.transform.localScale = Vector3.one * CardBarUtils.barlocalScaleMult;
				CardBarUtils.instance.ChangePlayersLineColor(teamID, Color.white);
				Color.RGBToHSV(CardBarUtils.instance.GetPlayersBarColor(teamID), ref h, ref s, ref v);
				CardBarUtils.instance.ChangePlayersBarColor(teamID, Color.HSVToRGB(h, s + 0.1f, v + 0.1f));
				while (Main.MaxCards > 0 && CardBarUtils.instance.GetCardBarSquares(teamID).Length - 1 >= (endpick ? (Main.MaxCards + 1) : Main.MaxCards))
				{
					if (player.data.view.IsMine)
					{
						((TMP_Text)text).text = "DISCARD " + (CardBarUtils.instance.GetCardBarSquares(teamID).Length - (endpick ? (Main.MaxCards + 1) : Main.MaxCards)) + " CARD" + ((CardBarUtils.instance.GetCardBarSquares(teamID).Length - (endpick ? (Main.MaxCards + 1) : Main.MaxCards) != 1) ? "S" : "");
						GameObject[] cardBarSquares = CardBarUtils.instance.GetCardBarSquares(teamID);
						foreach (GameObject cardBarButton2 in cardBarSquares)
						{
							Selectable selectable = ExtensionMethods.GetOrAddComponent<Selectable>(cardBarButton2, false);
							selectable.player = player;
						}
					}
					else
					{
						((TMP_Text)text).text = "WAITING FOR " + ExtraPlayerSkins.GetTeamColorName(PlayerExtensions.GetAdditionalData(player).colorID).ToUpper();
					}
					yield return null;
					if (forceRemove)
					{
						Cards.instance.RemoveCardFromPlayer(player, rng.Next(0, player.data.currentCards.Count));
						yield return (object)new WaitForSecondsRealtime(0.11f);
					}
					else if (pass[player] && !endpick)
					{
						break;
					}
				}
				if (pass[player] && !forceRemove && !endpick)
				{
					break;
				}
				yield return (object)new WaitForSecondsRealtime(0.11f);
			}
			yield return (object)new WaitForSecondsRealtime(0.1f);
			if (player.data.view.IsMine)
			{
				GameObject[] cardBarSquares2 = CardBarUtils.instance.GetCardBarSquares(teamID);
				foreach (GameObject cardBarButton in cardBarSquares2)
				{
					if ((Object)(object)cardBarButton.GetComponent<Selectable>() != (Object)null)
					{
						Object.Destroy((Object)(object)cardBarButton.GetComponent<Selectable>());
					}
				}
			}
			try
			{
				((Component)CardBarUtils.instance.PlayersCardBar(teamID)).gameObject.transform.localScale = Vector3.one * 1f;
				Transform transform2 = ((Component)CardBarUtils.instance.PlayersCardBar(teamID)).gameObject.transform;
				transform2.localPosition -= CardBarUtils.localShift;
				CardBarUtils.instance.ResetPlayersLineColor(teamID);
				CardBarUtils.instance.ChangePlayersBarColor(teamID, orig);
			}
			catch
			{
			}
		}
		textCanvas.SetActive(false);
		passCanvas.SetActive(false);
		active = false;
	}

	private static void CreateText()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Expected O, but got Unknown
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		textCanvas = new GameObject("TextCanvas", new Type[1] { typeof(Canvas) });
		textCanvas.transform.SetParent(((Component)Unbound.Instance.canvas).transform);
		GameObject val = new GameObject("TextBackground", new Type[1] { typeof(Image) });
		val.transform.SetParent(textCanvas.transform);
		((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.85f);
		((Graphic)val.GetComponent<Image>()).rectTransform.anchorMin = new Vector2(-2f, 0.25f);
		((Graphic)val.GetComponent<Image>()).rectTransform.anchorMax = new Vector2(3f, 0.75f);
		GameObject val2 = new GameObject("Timer", new Type[1] { typeof(TextMeshProUGUI) });
		val2.transform.SetParent(val.transform);
		text = val2.GetComponent<TextMeshProUGUI>();
		((TMP_Text)text).text = "";
		((TMP_Text)text).fontSize = 45f;
		textCanvas.transform.position = Vector2.op_Implicit(new Vector2((float)Screen.width / 2f, (float)Screen.height - 150f));
		((TMP_Text)text).enableWordWrapping = false;
		((TMP_Text)text).overflowMode = (TextOverflowModes)0;
		((TMP_Text)text).alignment = (TextAlignmentOptions)514;
		textCanvas.SetActive(false);
	}

	private static void CreatePassButton()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Expected O, but got Unknown
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Expected O, but got Unknown
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		passCanvas = new GameObject("PassCanvas", new Type[2]
		{
			typeof(Canvas),
			typeof(GraphicRaycaster)
		});
		passCanvas.transform.SetParent(((Component)Unbound.Instance.canvas).transform);
		passButton = new GameObject("PassBackground", new Type[2]
		{
			typeof(Image),
			typeof(PassButtonSelectable)
		});
		passButton.transform.SetParent(passCanvas.transform);
		((Graphic)passButton.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.85f);
		((Graphic)passButton.GetComponent<Image>()).rectTransform.anchorMin = new Vector2(0f, 0f);
		((Graphic)passButton.GetComponent<Image>()).rectTransform.anchorMax = new Vector2(1f, 1f);
		GameObject val = new GameObject("Pass", new Type[1] { typeof(TextMeshProUGUI) });
		val.transform.SetParent(passButton.transform);
		TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
		((TMP_Text)component).text = "Pass";
		((TMP_Text)component).fontSize = 45f;
		passCanvas.transform.position = Vector2.op_Implicit(new Vector2(5f * (float)Screen.width / 6f, 150f));
		((TMP_Text)component).enableWordWrapping = false;
		((TMP_Text)component).overflowMode = (TextOverflowModes)0;
		((TMP_Text)component).alignment = (TextAlignmentOptions)514;
		passCanvas.SetActive(false);
	}
}
internal class PassButtonSelectable : MonoBehaviour, IPointerUpHandler, IEventSystemHandler, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler
{
	internal Player player;

	private bool hover = false;

	private bool down = false;

	private Color orig;

	private Vector3 origScale;

	private void Start()
	{
		//IL_0008: 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_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)
		orig = ((Graphic)((Component)this).GetComponentInChildren<Image>()).color;
		origScale = ((Component)this).transform.localScale;
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		//IL_000f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		down = true;
		((Component)this).transform.localScale = origScale * 0.9f;
		float num = default(float);
		float num2 = default(float);
		float num3 = default(float);
		Color.RGBToHSV(orig, ref num, ref num2, ref num3);
		Color color = Color.HSVToRGB(num, num2 - 0.1f, num3 - 0.1f);
		color.a = orig.a;
		((Graphic)((Component)this).GetComponentInChildren<Image>()).color = color;
	}

	public void OnPointerUp(PointerEventData eventData)
	{
		//IL_001a: 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)
		if (down)
		{
			down = false;
			((Component)this).transform.localScale = origScale;
			((Graphic)((Component)this).GetComponentInChildren<Image>()).color = orig;
			if (hover)
			{
				PassOnClick();
			}
		}
	}

	public void OnPointerEnter(PointerEventData eventData)
	{
		hover = true;
	}

	public void OnPointerExit(PointerEventData eventData)
	{
		hover = false;
	}

	private void OnDestroy()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		((Component)this).transform.localScale = origScale;
		((Graphic)((Component)this).GetComponentInChildren<Image>()).color = orig;
	}

	private void PassOnClick()
	{
		if (!PhotonNetwork.OfflineMode)
		{
			NetworkingManager.RPC(typeof(PassButtonSelectable), "RPCA_PassOnClick", new object[1] { player.playerID });
		}
		else
		{
			MaxCardsHandler.pass[player] = true;
		}
	}

	[UnboundRPC]
	private static void RPCA_PassOnClick(int playerID)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		Player key = (Player)ExtensionMethods.InvokeMethod((object)PlayerManager.instance, "GetPlayerWithID", new object[1] { playerID });
		MaxCardsHandler.pass[key] = true;
	}
}
[HarmonyPatch(typeof(CardChoice), "DoPick")]
internal class CardChoiceDoPickPatch
{
	internal static Dictionary<Player, bool> playerHasPicked = new Dictionary<Player, bool>();

	private static bool Prefix(CardChoice __instance, int picketIDToSet)
	{
		Player playerWithID = ExtensionMethods.GetPlayerWithID(PlayerManager.instance, picketIDToSet);
		playerHasPicked[playerWithID] = Main.MaxCards <= 0 || CardBarUtils.instance.GetCardBarSquares(playerWithID.teamID).Length <= Main.MaxCards;
		if (!playerHasPicked[playerWithID])
		{
			__instance.IsPicking = false;
		}
		return playerHasPicked[playerWithID];
	}
}
[HarmonyPatch(typeof(CardChoiceVisuals), "Show")]
internal class CardChoiceVisualsShowPatch
{
	internal static Dictionary<Player, bool> playerHasPicked = new Dictionary<Player, bool>();

	private static bool Prefix(CardChoiceVisuals __instance, int pickerID)
	{
		Player playerWithID = ExtensionMethods.GetPlayerWithID(PlayerManager.instance, pickerID);
		playerHasPicked[playerWithID] = Main.MaxCards <= 0 || CardBarUtils.instance.GetCardBarSquares(playerWithID.teamID).Length <= Main.MaxCards;
		return playerHasPicked[playerWithID];
	}
}
public static class SyncMethodStatic
{
	private static readonly ConditionalWeakTable<Type, HashSet<Tuple<int, string>>> pendingRequests = new ConditionalWeakTable<Type, HashSet<Tuple<int, string>>>();

	public static Coroutine SyncMethod(Type staticType, string methodName, int[] actors, params object[] data)
	{
		return ((MonoBehaviour)Main.Instance).StartCoroutine(SyncMethodCoroutine(staticType, methodName, actors, data));
	}

	public static Coroutine SyncMethod(Type staticType, string methodName, int actor, params object[] data)
	{
		return SyncMethod(staticType, methodName, new int[1] { actor }, data);
	}

	private static IEnumerator SyncMethodCoroutine(Type staticType, string methodName, int[] actors, params object[] data)
	{
		if (PhotonNetwork.OfflineMode || PhotonNetwork.CurrentRoom == null)
		{
			NetworkingManager.RPC(staticType, methodName, data);
			yield break;
		}
		if (actors == null)
		{
			actors = (from p in PhotonNetwork.CurrentRoom.Players.Values.ToList()
				select p.ActorNumber).ToArray();
		}
		int[] array = actors;
		foreach (int actor in array)
		{
			GetPendingRequests(staticType).Add(new Tuple<int, string>(actor, methodName));
		}
		NetworkingManager.RPC(staticType, methodName, data);
		while ((from r in GetPendingRequests(staticType)
			where r.Item2 == methodName
			select r).Any((Tuple<int, string> r) => actors.Contains(r.Item1)))
		{
			yield return null;
		}
	}

	[UnboundRPC]
	public static void RPC_RequestSync(int requestingPlayer)
	{
		NetworkingManager.RPC(typeof(SyncMethodStatic), "RPC_SyncResponse", new object[2]
		{
			requestingPlayer,
			PhotonNetwork.LocalPlayer.ActorNumber
		});
	}

	[UnboundRPC]
	public static void RPC_SyncResponse(int requestingPlayer, int readyPlayer)
	{
		if (PhotonNetwork.LocalPlayer.ActorNumber == requestingPlayer)
		{
			RemovePendingRequest(typeof(SyncMethodStatic), readyPlayer, "RPC_RequestSync");
		}
	}

	public static IEnumerator WaitForSyncUp()
	{
		if (!PhotonNetwork.OfflineMode)
		{
			yield return SyncMethod(typeof(SyncMethodStatic), "RPC_RequestSync", null, PhotonNetwork.LocalPlayer.ActorNumber);
		}
	}

	public static HashSet<Tuple<int, string>> GetPendingRequests(Type staticType)
	{
		return pendingRequests.GetOrCreateValue(staticType);
	}

	public static void ClearPendingRequests(Type staticType, int actor)
	{
		HashSet<Tuple<int, string>> orCreateValue = pendingRequests.GetOrCreateValue(staticType);
		foreach (Tuple<int, string> item in from t in orCreateValue.ToList()
			where t.Item1 == actor
			select t)
		{
			orCreateValue.Remove(new Tuple<int, string>(actor, item.Item2));
		}
	}

	public static void RemovePendingRequest(Type staticType, int actor, string methodName)
	{
		HashSet<Tuple<int, string>> orCreateValue = pendingRequests.GetOrCreateValue(staticType);
		orCreateValue.Remove(new Tuple<int, string>(actor, methodName));
	}
}