Decompiled source of CardBalance v0.3.0

CardBalance.dll

Decompiled 3 weeks 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnboundLib;
using UnboundLib.GameModes;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CardBalance")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+89d6c4ddfd7bd3c8db210139152f6f732fc138a2")]
[assembly: AssemblyProduct("CardBalance")]
[assembly: AssemblyTitle("CardBalance")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace CardBalance
{
	public static class ExtraPickBalancing
	{
		[CompilerGenerated]
		private sealed class <HandleExtraPicks>d__1 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private Dictionary<int, int> <teamSizes>5__2;

			private int <maxTeamSize>5__3;

			private List<Player>.Enumerator <>7__wrap3;

			private Player <player>5__5;

			private int <extraPicks>5__6;

			private int <i>5__7;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <HandleExtraPicks>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 1u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<teamSizes>5__2 = null;
				<>7__wrap3 = default(List<Player>.Enumerator);
				<player>5__5 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ae: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
					{
						<>1__state = -1;
						if (_running)
						{
							return false;
						}
						_running = true;
						List<Player> list = PlayerManager.instance.players.Where((Player p) => p.data.isPlaying).ToList();
						if (list.Count <= 1)
						{
							_running = false;
							return false;
						}
						<teamSizes>5__2 = (from p in list
							group p by p.teamID).ToDictionary((IGrouping<int, Player> g) => g.Key, (IGrouping<int, Player> g) => g.Count());
						<maxTeamSize>5__3 = <teamSizes>5__2.Values.Max();
						<>7__wrap3 = list.GetEnumerator();
						<>1__state = -3;
						goto IL_01e6;
					}
					case 1:
						<>1__state = -3;
						<>2__current = (object)new WaitForSecondsRealtime(0.1f);
						<>1__state = 2;
						return true;
					case 2:
						{
							<>1__state = -3;
							<i>5__7++;
							goto IL_01d1;
						}
						IL_01e6:
						do
						{
							if (<>7__wrap3.MoveNext())
							{
								<player>5__5 = <>7__wrap3.Current;
								<extraPicks>5__6 = <maxTeamSize>5__3 - <teamSizes>5__2[<player>5__5.teamID];
								continue;
							}
							<>m__Finally1();
							<>7__wrap3 = default(List<Player>.Enumerator);
							_running = false;
							return false;
						}
						while (<extraPicks>5__6 <= 0);
						<i>5__7 = 0;
						goto IL_01d1;
						IL_01d1:
						if (<i>5__7 < <extraPicks>5__6)
						{
							<>2__current = CardChoice.instance.DoPick(1, <player>5__5.playerID, (PickerType)1);
							<>1__state = 1;
							return true;
						}
						<player>5__5 = null;
						goto IL_01e6;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap3).Dispose();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static bool _running;

		[IteratorStateMachine(typeof(<HandleExtraPicks>d__1))]
		public static IEnumerator HandleExtraPicks(IGameModeHandler gm)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HandleExtraPicks>d__1(0);
		}
	}
	[HarmonyPatch(typeof(CardChoice), "Pick")]
	public static class CardChoicePatch
	{
		private static readonly Dictionary<int, int> _pendingExtraCards = new Dictionary<int, int>();

		public static void Postfix(CardChoice __instance)
		{
			int playerId = __instance.pickrID;
			if (playerId == -1)
			{
				return;
			}
			Player val = ((IEnumerable<Player>)PlayerManager.instance.players).FirstOrDefault((Func<Player, bool>)((Player p) => p.playerID == playerId));
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			List<Player> list = PlayerManager.instance.players.Where((Player p) => p.data.isPlaying).ToList();
			if (list.Count <= 1)
			{
				return;
			}
			int pickerTeamID = val.teamID;
			int num = 0;
			foreach (Player item in list)
			{
				if (item.teamID != pickerTeamID)
				{
					num++;
				}
			}
			if (num <= 1 || list.Count((Player p) => p.teamID == pickerTeamID) - 1 != 0)
			{
				return;
			}
			int num2 = num - 1;
			if (_pendingExtraCards.TryGetValue(playerId, out var value) && value > 0)
			{
				value--;
				if (value <= 0)
				{
					_pendingExtraCards.Remove(playerId);
				}
				else
				{
					_pendingExtraCards[playerId] = value;
				}
				return;
			}
			_pendingExtraCards[playerId] = num2;
			for (int i = 0; i < num2; i++)
			{
				ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)Unbound.Instance, 1, (Action)delegate
				{
					((MonoBehaviour)CardChoice.instance).StartCoroutine(CardChoice.instance.DoPick(1, playerId, (PickerType)1));
				});
			}
		}
	}
	[BepInPlugin("com.modpotato.rounds.cardbalance", "Card Balance", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string ModId = "com.modpotato.rounds.cardbalance";

		private const string ModName = "Card Balance";

		private const string Version = "0.3.0";

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.modpotato.rounds.cardbalance").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Card Balance v0.3.0 loaded successfully");
		}
	}
}