Decompiled source of Start N Cards v0.0.2

StartNCards.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using DrawNCards;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using PickNCards;
using TMPro;
using UnboundLib;
using UnboundLib.GameModes;
using UnboundLib.Networking;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[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]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace StartNCards
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("darthbinks.rounds.plugins.startncards", "Start N Cards", "0.0.2")]
	[BepInProcess("Rounds.exe")]
	public class StartNCards : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c : Object
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__17_0;

			internal void <Start>b__17_0()
			{
			}
		}

		private const string ModId = "darthbinks.rounds.plugins.startncards";

		private const string ModName = "Start N Cards";

		private const string CompatibilityModName = "StartNCards";

		private const int maxPicks = 10;

		private const string loggingPrefix = "[StartNCards]: ";

		internal static StartNCards instance;

		public static ConfigEntry<int> PicksConfig;

		public static ConfigEntry<float> DelayConfig;

		internal static int picks;

		internal static float delay = 0.1f;

		internal static bool lockPickQueue = false;

		internal static List<int> playerIDsToPick = new List<int>();

		internal static bool extraPicksInProgress = false;

		internal static bool transmittedStartingPicks = false;

		internal static bool transmittedPickNCardsPicks = false;

		internal static int pickNCardsStoredPicks = 0;

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			PicksConfig = ((BaseUnityPlugin)this).Config.Bind<int>("StartNCards", "Picks", 1, "Total number of card picks per player at the beginning of the match");
			new Harmony("darthbinks.rounds.plugins.startncards").PatchAll();
		}

		private void Start()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			picks = PicksConfig.Value;
			Unbound.RegisterCredits("Start N Cards", (string[])(object)new String[1] { "Darth Binks" }, (string[])(object)new String[1] { "GitHub" }, (string[])(object)new String[1] { "https://github.com/mclaager/StartNCards" });
			object obj = <>c.<>9__17_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
				};
				<>c.<>9__17_0 = val;
				obj = (object)val;
			}
			Unbound.RegisterMenu("Start N Cards", (UnityAction)obj, (Action<GameObject>)NewGUI, (GameObject)null, false);
			Unbound.RegisterHandshake("darthbinks.rounds.plugins.startncards", new Action(OnHandShakeCompleted));
			GameModeManager.AddHook("PickStart", (Func<IGameModeHandler, IEnumerator>)PickStart, 800);
			GameModeManager.AddHook("GameStart", (Func<IGameModeHandler, IEnumerator>)GameStart, 800);
		}

		private void OnHandShakeCompleted()
		{
			if (PhotonNetwork.IsMasterClient)
			{
				NetworkingManager.RPC_Others(typeof(StartNCards), "SyncSettings", (object[])(object)new Object[1] { (object)picks });
			}
		}

		[UnboundRPC]
		private static void SyncSettings(int host_picks)
		{
			picks = host_picks;
		}

		private void NewGUI(GameObject menu)
		{
			//IL_000d: 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_0018: 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_0032: 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_003d: 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_0078: 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_0083: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val2 = default(TextMeshProUGUI);
			MenuHandler.CreateText("Start N Cards Options", menu, ref val2, 60, true, default(Nullable<Color>), (TMP_FontAsset)null, (Material)null, default(Nullable<TextAlignmentOptions>));
			MenuHandler.CreateText(" ", menu, ref val2, 30, true, default(Nullable<Color>), (TMP_FontAsset)null, (Material)null, default(Nullable<TextAlignmentOptions>));
			Slider val3 = default(Slider);
			MenuHandler.CreateSlider("Number of cards to start the game with", menu, 30, 0f, 10f, (float)PicksConfig.Value, (UnityAction<float>)PicksChanged, ref val3, true, default(Nullable<Color>), (Direction)0, true, default(Nullable<Color>), (TMP_FontAsset)null, (Material)null, default(Nullable<TextAlignmentOptions>));
			MenuHandler.CreateText(" ", menu, ref val2, 30, true, default(Nullable<Color>), (TMP_FontAsset)null, (Material)null, default(Nullable<TextAlignmentOptions>));
			[CompilerGenerated]
			void PicksChanged(float val)
			{
				PicksConfig.Value = Mathf.RoundToInt(Mathf.Clamp(val, 0f, 10f));
				picks = PicksConfig.Value;
				OnHandShakeCompleted();
			}
		}

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

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

		[IteratorStateMachine(/*Could not decode attribute arguments.*/)]
		private IEnumerator WaitForSyncUp()
		{
			if (!PhotonNetwork.OfflineMode)
			{
				yield return MonoBehaviourExtensions.SyncMethod((MonoBehaviour)(object)this, "RPC_RequestSync", (int[])null, (object[])(object)new Object[1] { (object)PhotonNetwork.LocalPlayer.ActorNumber });
			}
		}

		[IteratorStateMachine(/*Could not decode attribute arguments.*/)]
		internal static IEnumerator ResetPickQueue()
		{
			if (!extraPicksInProgress)
			{
				playerIDsToPick = new List<int>();
				lockPickQueue = false;
			}
			yield break;
		}

		[IteratorStateMachine(/*Could not decode attribute arguments.*/)]
		internal static IEnumerator PickStart(IGameModeHandler handler)
		{
			yield return AlterPickNCardsForCompatibilty();
			yield return ResetPickQueue();
		}

		[IteratorStateMachine(/*Could not decode attribute arguments.*/)]
		internal static IEnumerator GameStart(IGameModeHandler gm)
		{
			transmittedStartingPicks = false;
			transmittedPickNCardsPicks = false;
			yield break;
		}

		[IteratorStateMachine(/*Could not decode attribute arguments.*/)]
		internal static IEnumerator AlterPickNCardsForCompatibilty()
		{
			if (!extraPicksInProgress && (PhotonNetwork.IsMasterClient || PhotonNetwork.OfflineMode))
			{
				if (!transmittedStartingPicks)
				{
					pickNCardsStoredPicks = PickNCards.PicksConfig.Value;
					int value = DrawNCards.NumDrawsConfig.Value;
					NetworkingManager.RPC(typeof(PickNCards), "SyncSettings", (object[])(object)new Object[2]
					{
						(object)picks,
						(object)value
					});
					yield return new WaitForSecondsRealtime(0.1f);
					transmittedStartingPicks = true;
				}
				else if (!transmittedPickNCardsPicks)
				{
					int value2 = DrawNCards.NumDrawsConfig.Value;
					NetworkingManager.RPC(typeof(PickNCards), "SyncSettings", (object[])(object)new Object[2]
					{
						(object)pickNCardsStoredPicks,
						(object)value2
					});
					yield return new WaitForSecondsRealtime(0.1f);
					transmittedPickNCardsPicks = true;
				}
			}
		}
	}
}