Decompiled source of GamblingMod v2.3.1

Mods/GamblingMod.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using GamblingMod;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppPhoton.Pun;
using Il2CppRUMBLE.Audio;
using Il2CppRUMBLE.Combat.ShiftStones;
using Il2CppRUMBLE.Economy.Interactables;
using Il2CppRUMBLE.Environment.Howard;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Pools;
using Il2CppRUMBLE.Poses;
using Il2CppRUMBLE.UI;
using Il2CppRUMBLE.Utilities;
using Il2CppSystem;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using RumbleModdingAPI.RMAPI;
using UIFramework;
using UIFramework.Models;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "GamblingMod", "2.3.1", "UlvakSkillz", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 195, 0, 255)]
[assembly: MelonAuthorColor(255, 195, 0, 255)]
[assembly: VerifyLoaderVersion(0, 6, 6, true)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("GamblingMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4ee95c6b09a2b4a3779a71e699293b3f7b9a04d7")]
[assembly: AssemblyProduct("GamblingMod")]
[assembly: AssemblyTitle("GamblingMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GamblingMod;

public class BlackJack : MonoBehaviour
{
	private int betAmount = 1;

	private int betHeldAmount = 0;

	private bool gameLoopRunning = false;

	private TextMeshPro betTextComponent = null;

	private GameObject storedBetsMenu = null;

	private GameObject storedOptionsMenu = null;

	private bool betAccepted = false;

	private bool userQuits = false;

	private List<int> deck;

	private List<int> dealerHand;

	private List<List<int>> hand;

	public object gameLoopCoroutine = null;

	private Transform storedGamePartsTransform = null;

	private Transform activeGamePartsTransform = null;

	private Table tableInstance;

	private GameObject cardSpots = null;

	private bool has21Immediately = false;

	private int coinsGained = 0;

	private bool continueShuffling = true;

	private bool pressedStay;

	private bool pressedHit;

	private bool pressedSplit;

	public BlackJack(Table tableInstance)
	{
		this.tableInstance = tableInstance;
	}

	public static void Log(string msg, bool sendMsg = true)
	{
		if (sendMsg)
		{
			Table.Log("BlackJack - " + msg, sendMsg);
		}
	}

	public static void Warn(string msg, bool sendMsg = true)
	{
		if (sendMsg)
		{
			Table.Warn("BlackJack - " + msg, sendMsg);
		}
	}

	public static void Error(string msg)
	{
		Table.Error("BlackJack - " + msg);
	}

	public void ShowSplash()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_0061: 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_0083: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		storedGamePartsTransform = ((Component)tableInstance).transform.GetChild(1);
		activeGamePartsTransform = ((Component)tableInstance).transform.GetChild(2);
		GameObject val = new GameObject("SplashScreen");
		val.transform.SetParent(activeGamePartsTransform);
		val.transform.localPosition = new Vector3(0f, 0.9454f, 0f);
		val.transform.localRotation = Quaternion.identity;
		val.transform.localScale = Vector3.one;
		GameObject val2 = tableInstance.SpawnText(val.transform, "BlackJack", new Vector3(0f, 0f, 0.4f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1.25f, 1.25f, 1.25f));
		TextMeshPro component = val2.GetComponent<TextMeshPro>();
		((TMP_Text)component).alignment = (TextAlignmentOptions)514;
		((TMP_Text)component).enableWordWrapping = false;
	}

	public IEnumerator Run()
	{
		Log("Run Running", Preferences.debugging.Value);
		SetupStart();
		gameLoopCoroutine = MelonCoroutines.Start(GameLoop());
		yield return gameLoopCoroutine;
		Log("Run Completed", Preferences.debugging.Value);
	}

	private void SetupStart()
	{
		Log("SetupStart Running", Preferences.debugging.Value);
		gameLoopRunning = false;
		RandomizeDeck();
		SetupBetMenu();
		SetupOptionsMenu();
		Log("SetupStart Completed", Preferences.debugging.Value);
	}

	private void SetupCardSpots()
	{
		//IL_0050: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		cardSpots = Object.Instantiate<GameObject>(((Component)storedGamePartsTransform.GetChild(1)).gameObject);
		((Object)cardSpots).name = "CardSpots";
		cardSpots.transform.SetParent(activeGamePartsTransform);
		cardSpots.transform.localPosition = Vector3.zero;
		cardSpots.transform.localRotation = Quaternion.identity;
		cardSpots.transform.localScale = Vector3.one;
	}

	private IEnumerator GameLoop()
	{
		Log("GameLoop Running", Preferences.debugging.Value);
		gameLoopRunning = true;
		while (gameLoopRunning)
		{
			if (deck.Count <= 26 * Preferences.deckCount.Value)
			{
				RandomizeDeck(continueShuffling: false);
				yield return (object)new WaitForSeconds(1f);
			}
			betAmount = 1;
			if (!tableInstance.freePlay && Main.GetPlayerCoinCount() < betAmount)
			{
				GameObject youBrokeAsFuck = tableInstance.SpawnText(((Component)activeGamePartsTransform).transform, "Too Few Coins. Try Free Play or" + Environment.NewLine + "Complete More Poses to Earn Coins", new Vector3(0f, tableInstance.TABLEHEIGHT - 0.025f, 0.65f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1f, 1f, 1f));
				((Object)youBrokeAsFuck).name = "You Broke As Fuck";
				TextMeshPro endGameTextTMP = youBrokeAsFuck.GetComponent<TextMeshPro>();
				((TMP_Text)endGameTextTMP).alignment = (TextAlignmentOptions)514;
				((TMP_Text)endGameTextTMP).enableWordWrapping = false;
				continueShuffling = false;
				Log("Not Enough Coins, Exiting BlackJack", Preferences.debugging.Value);
				yield return (object)new WaitForSeconds(1.5f);
				gameLoopRunning = false;
				break;
			}
			tableInstance.ClearActiveObjects();
			yield return MelonCoroutines.Start(RunBetMenu());
			tableInstance.ClearActiveObjects();
			yield return (object)new WaitForSeconds(1.5f);
			if (userQuits)
			{
				gameLoopRunning = false;
			}
			if (betAccepted)
			{
				Log("Player Bet Accepted: " + betAmount);
				Main.Payout(-betAmount, 1f, tableInstance);
				betHeldAmount = betAmount;
				coinsGained = 0;
				yield return MelonCoroutines.Start(PlayHands());
				yield return MelonCoroutines.Start(DealersTurn());
				List<int> playerHandTotals = GetPlayerHandTotal();
				int dealerHandTotal = GetDealerHandTotal();
				int i = playerHandTotals.Count - 1;
				while (i >= 0 && gameLoopRunning)
				{
					ClearVisualCardsFromAHand(isPlayer: true);
					ClearVisualCardsFromAHand(isPlayer: false);
					List<GameObject> handCards = SpawnHandCards(i);
					List<GameObject> dealerCards = SpawnDealerCards();
					yield return (object)new WaitForSeconds(0.25f);
					object endGameCoroutine1 = null;
					string cardString0 = "";
					foreach (int card in hand[i])
					{
						cardString0 = cardString0 + tableInstance.CardString[card] + " ";
					}
					string cardString1 = "";
					foreach (int card2 in dealerHand)
					{
						cardString1 = cardString1 + tableInstance.CardString[card2] + " ";
					}
					Log($"Checking Hand {i}: Player {playerHandTotals[i]} ( {cardString0}) vs Dealer {dealerHandTotal} ( {cardString1})");
					yield return (object)new WaitForSeconds(0.5f);
					object endGameCoroutine2;
					if (has21Immediately)
					{
						Log($"Player Got 21 Immediately! Gained {betAmount * 2} Coins");
						coinsGained += Main.Payout(betAmount, 2f, tableInstance);
						endGameCoroutine2 = MelonCoroutines.Start(PlayPlayerWin(handCards, dealerCards));
					}
					else if (playerHandTotals[i] > 21)
					{
						Log($"Player Bust, Lost {betAmount} Coins");
						betHeldAmount -= betAmount;
						coinsGained -= betAmount;
						endGameCoroutine2 = MelonCoroutines.Start(PlayPlayerBust(handCards));
					}
					else if (playerHandTotals[i] > dealerHandTotal || dealerHandTotal > 21)
					{
						Log($"Player Beat Dealer! Gained {(int)((float)betAmount * 1.5f)} Coins");
						coinsGained += Main.Payout(betAmount, 1.5f, tableInstance);
						endGameCoroutine2 = MelonCoroutines.Start(PlayPlayerWin(handCards, dealerCards));
					}
					else
					{
						Log($"Player Didn't Beat Dealer, Lost {betAmount} Coins");
						betHeldAmount -= betAmount;
						coinsGained -= betAmount;
						endGameCoroutine2 = MelonCoroutines.Start(PlayDealerWin(handCards, dealerCards));
					}
					if (dealerHandTotal > 21)
					{
						endGameCoroutine1 = MelonCoroutines.Start(PlayDealerBust(dealerCards));
					}
					yield return endGameCoroutine2;
					yield return endGameCoroutine1;
					yield return (object)new WaitForSeconds(0.25f);
					foreach (GameObject handCard in handCards)
					{
						Object.Destroy((Object)(object)handCard);
					}
					foreach (GameObject dealerCard in dealerCards)
					{
						Object.Destroy((Object)(object)dealerCard);
					}
					i--;
				}
				Main.Payout(betHeldAmount, 1f, tableInstance);
				bool continuePressed = false;
				string coinLine = ((coinsGained < 0) ? $"Coins Lost: {-coinsGained}" : $"Coins Gained: {coinsGained}");
				GameObject endGameText = tableInstance.SpawnText(((Component)activeGamePartsTransform).transform, coinLine, new Vector3(0f, tableInstance.TABLEHEIGHT - 0.025f, 0.5f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1f, 1f, 1f));
				((Object)endGameText).name = "End Game Text";
				TextMeshPro endGameTextTMP2 = endGameText.GetComponent<TextMeshPro>();
				((TMP_Text)endGameTextTMP2).alignment = (TextAlignmentOptions)514;
				((TMP_Text)endGameTextTMP2).enableWordWrapping = false;
				GameObject continueButton = tableInstance.LoadMenuButton("Continue", new Vector3(0f, tableInstance.TABLEHEIGHT - 0.025f, 0.96f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f), delegate
				{
					continuePressed = true;
				});
				((Object)continueButton).name = "Continue";
				while (!continuePressed && gameLoopRunning)
				{
					yield return (object)new WaitForFixedUpdate();
				}
			}
			tableInstance.ClearActiveObjects();
		}
		Log("GameLoop Completed", Preferences.debugging.Value);
	}

	private IEnumerator PlayPlayerWin(List<GameObject> handCards, List<GameObject> dealerCards)
	{
		Log("PlayPlayerWin Started", Preferences.debugging.Value);
		List<object> cardsReacting = new List<object>();
		for (int i = 0; i < handCards.Count; i++)
		{
			cardsReacting.Add(PlayCardReact(handCards[i], win: true, isPlayer: true));
		}
		for (int j = 0; j < dealerCards.Count; j++)
		{
			cardsReacting.Add(PlayCardReact(dealerCards[j], win: false, isPlayer: false));
		}
		foreach (object item in cardsReacting)
		{
			yield return item;
		}
		Log("PlayPlayerWin Completed", Preferences.debugging.Value);
	}

	private object PlayCardReact(GameObject card, bool win, bool isPlayer)
	{
		return MelonCoroutines.Start(PlayCardReactCoroutine(card, win, isPlayer));
	}

	private IEnumerator PlayCardReactCoroutine(GameObject card, bool win, bool isPlayer)
	{
		Vector3 startingPostion = card.transform.localPosition;
		Vector3 movePerTick = (isPlayer ? Vector3.back : Vector3.forward) / 50f * (win ? 0.5f : (-0.25f));
		for (int i = 0; i < 25; i++)
		{
			Transform transform = card.transform;
			transform.localPosition += movePerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		for (int j = 0; j < 25; j++)
		{
			Transform transform2 = card.transform;
			transform2.localPosition -= movePerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		card.transform.localPosition = startingPostion;
	}

	private IEnumerator PlayPlayerBust(List<GameObject> handCards)
	{
		Log("PlayPlayerBust Started", Preferences.debugging.Value);
		List<object> cardsReacting = new List<object>();
		for (int i = 0; i < handCards.Count; i++)
		{
			cardsReacting.Add(MelonCoroutines.Start(PlayCardBustCoroutine(handCards[i])));
		}
		foreach (object item in cardsReacting)
		{
			yield return item;
		}
		Log("PlayPlayerBust Completed", Preferences.debugging.Value);
	}

	private IEnumerator PlayDealerBust(List<GameObject> handCards)
	{
		Log("PlayDealerBust Started", Preferences.debugging.Value);
		List<object> cardsReacting = new List<object>();
		for (int i = 0; i < handCards.Count; i++)
		{
			cardsReacting.Add(MelonCoroutines.Start(PlayCardBustCoroutine(handCards[i])));
		}
		foreach (object item in cardsReacting)
		{
			yield return item;
		}
		Log("PlayDealerBust Completed", Preferences.debugging.Value);
	}

	private IEnumerator PlayCardBustCoroutine(GameObject card)
	{
		Log("PlayCardBustCoroutine Started", Preferences.debugging.Value);
		Vector3 startingScale = card.transform.localScale;
		Vector3 scalePerTick = startingScale / 50f;
		for (int i = 0; i < 50; i++)
		{
			Transform transform = card.transform;
			transform.localScale -= scalePerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		Log("PlayCardBustCoroutine Completed", Preferences.debugging.Value);
	}

	private IEnumerator PlayDealerWin(List<GameObject> handCards, List<GameObject> dealerCards)
	{
		Log("PlayDealerWin Started", Preferences.debugging.Value);
		List<object> cardsReacting = new List<object>();
		for (int i = 0; i < handCards.Count; i++)
		{
			cardsReacting.Add(PlayCardReact(handCards[i], win: false, isPlayer: true));
		}
		for (int j = 0; j < dealerCards.Count; j++)
		{
			cardsReacting.Add(PlayCardReact(dealerCards[j], win: true, isPlayer: false));
		}
		foreach (object item in cardsReacting)
		{
			yield return item;
		}
		Log("PlayDealerWin Completed", Preferences.debugging.Value);
	}

	private List<GameObject> SpawnHandCards(int thisHand)
	{
		//IL_006a: 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)
		List<GameObject> list = new List<GameObject>();
		for (int i = 0; i < hand[thisHand].Count; i++)
		{
			GameObject val = Object.Instantiate<GameObject>(((Component)tableInstance.storedDeckOfCards.transform.GetChild(hand[thisHand][i])).gameObject);
			val.transform.SetParent(cardSpots.transform.GetChild(0).GetChild(i));
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			list.Add(val);
		}
		return list;
	}

	private List<GameObject> SpawnDealerCards()
	{
		//IL_0061: 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)
		List<GameObject> list = new List<GameObject>();
		for (int i = 0; i < dealerHand.Count; i++)
		{
			GameObject val = Object.Instantiate<GameObject>(((Component)tableInstance.storedDeckOfCards.transform.GetChild(dealerHand[i])).gameObject);
			val.transform.SetParent(cardSpots.transform.GetChild(1).GetChild(i));
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			list.Add(val);
		}
		return list;
	}

	private IEnumerator RevealDealerCard()
	{
		Log("RevealDealerCard Started", Preferences.debugging.Value);
		float rotationPerTick = 7.2f;
		Transform dealerCard = cardSpots.transform.GetChild(1).GetChild(1).GetChild(0);
		GameObject newCard = Object.Instantiate<GameObject>(((Component)tableInstance.storedDeckOfCards.transform.GetChild(dealerHand[1])).gameObject);
		newCard.transform.SetParent(((Component)dealerCard).transform.parent);
		newCard.transform.position = ((Component)dealerCard).transform.position;
		newCard.transform.rotation = ((Component)dealerCard).transform.rotation;
		newCard.transform.localScale = ((Component)dealerCard).transform.localScale;
		Quaternion localRotation = newCard.transform.localRotation;
		float currentRotationX = ((Quaternion)(ref localRotation)).eulerAngles.x;
		localRotation = newCard.transform.localRotation;
		float currentRotationY = ((Quaternion)(ref localRotation)).eulerAngles.y;
		localRotation = newCard.transform.localRotation;
		float currentRotationZ = ((Quaternion)(ref localRotation)).eulerAngles.z;
		Object.Destroy((Object)(object)((Component)dealerCard).gameObject);
		for (int i = 0; i < 25; i++)
		{
			currentRotationX -= rotationPerTick;
			newCard.transform.localRotation = Quaternion.Euler(currentRotationX, currentRotationY, currentRotationZ);
			yield return (object)new WaitForFixedUpdate();
		}
		Log("Completed Rotation", Preferences.debugging.Value);
		Log("RevealDealerCard Completed", Preferences.debugging.Value);
	}

	private List<int> GetPlayerHandTotal()
	{
		Log("GetPlayerHandTotal Started", Preferences.debugging.Value);
		List<int> list = new List<int>();
		int num = 0;
		bool flag = false;
		foreach (List<int> item in hand)
		{
			foreach (int item2 in item)
			{
				int num2;
				for (num2 = item2; num2 >= 13; num2 -= 13)
				{
				}
				num2 = Math.Clamp(num2 + 1, 1, 10);
				if (num2 == 1)
				{
					flag = true;
				}
				num += num2;
			}
			if (flag && num <= 11)
			{
				num += 10;
			}
			list.Add(num);
			num = 0;
		}
		Log("GetPlayerHandTotal Completed", Preferences.debugging.Value);
		return list;
	}

	private int GetDealerHandTotal()
	{
		Log("GetDealerHandTotal Started", Preferences.debugging.Value);
		int num = 0;
		bool flag = false;
		foreach (int item in dealerHand)
		{
			int num2;
			for (num2 = item; num2 >= 13; num2 -= 13)
			{
			}
			num2 = Math.Clamp(num2 + 1, 1, 10);
			if (num2 == 1)
			{
				flag = true;
			}
			num += num2;
		}
		if (flag && num <= 11)
		{
			num += 10;
		}
		Log("GetDealerHandTotal Completed", Preferences.debugging.Value);
		return num;
	}

	private int GetCardsTotal(List<int> cards)
	{
		Log("GetCardsTotal Started", Preferences.debugging.Value);
		int num = 0;
		bool flag = false;
		foreach (int card in cards)
		{
			int num2;
			for (num2 = card; num2 >= 13; num2 -= 13)
			{
			}
			num2 = Math.Clamp(num2 + 1, 1, 10);
			if (num2 == 1)
			{
				flag = true;
			}
			num += num2;
			Log($"Card {tableInstance.CardString[card]}: {num2}", Preferences.debugging.Value);
		}
		if (flag && num <= 11)
		{
			num += 10;
			Log("Ace able to be 11", Preferences.debugging.Value);
		}
		Log("GetCardsTotal Completed: " + num, Preferences.debugging.Value);
		return num;
	}

	private IEnumerator PlayHands()
	{
		Log("PlayHands Running", Preferences.debugging.Value);
		hand = new List<List<int>>();
		dealerHand = new List<int>();
		has21Immediately = false;
		SetupCardSpots();
		int thisHand = hand.Count;
		hand.Add(new List<int>());
		hand[hand.Count - 1].Add(DrawCard());
		Log("Player Card 1: " + tableInstance.CardString[hand[hand.Count - 1][0]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(hand[hand.Count - 1][0], cardSpots.transform.GetChild(0).GetChild(0), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
		dealerHand.Add(DrawCard());
		Log("Dealer Card 1: " + tableInstance.CardString[dealerHand[0]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(dealerHand[0], cardSpots.transform.GetChild(1).GetChild(0), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
		hand[hand.Count - 1].Add(DrawCard());
		Log("Player Card 2: " + tableInstance.CardString[hand[hand.Count - 1][1]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(hand[hand.Count - 1][1], cardSpots.transform.GetChild(0).GetChild(1), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
		dealerHand.Add(DrawCard());
		Log("Dealer Card 2: -_-", Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(52, cardSpots.transform.GetChild(1).GetChild(1), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f), playRotate: false);
		if (GetCardsTotal(hand[thisHand]) == 21)
		{
			has21Immediately = true;
		}
		else
		{
			yield return MelonCoroutines.Start(RunOptionsMenu(thisHand));
		}
		Log("PlayHands Completed", Preferences.debugging.Value);
	}

	private object PlayDrawCardAnimation(int CardToDraw, Transform parent, Vector3 position, Quaternion localRotation, bool playRotate = true)
	{
		//IL_004a: 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)
		Log("PlayDrawCardAnimation Started", Preferences.debugging.Value);
		GameObject val = Object.Instantiate<GameObject>(((Component)tableInstance.storedDeckOfCards.transform.GetChild(CardToDraw)).gameObject);
		val.transform.SetParent(parent);
		val.transform.position = position;
		val.transform.localRotation = localRotation;
		Log("PlayDrawCardAnimation Completed", Preferences.debugging.Value);
		return MelonCoroutines.Start(PlayDrawAnimation(val, 25, playRotate));
	}

	private int DrawCard()
	{
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		if (deck.Count == 0)
		{
			RandomizeDeck();
		}
		int result = deck[0];
		deck.RemoveAt(0);
		tableInstance.dealerDeck.transform.localScale = new Vector3(1f, (float)deck.Count / 52f, 1f);
		return result;
	}

	private IEnumerator PlayDrawAnimation(GameObject card, int ticks = 25, bool playRotate = true)
	{
		Log("PlayDrawAnimation Started", Preferences.debugging.Value);
		Vector3 distancePerTick = card.transform.localPosition / (float)ticks;
		float rotationPerTick = 180f / (float)ticks;
		Quaternion localRotation = card.transform.localRotation;
		float currentRotationX = ((Quaternion)(ref localRotation)).eulerAngles.x;
		localRotation = card.transform.localRotation;
		float currentRotationY = ((Quaternion)(ref localRotation)).eulerAngles.y;
		localRotation = card.transform.localRotation;
		float currentRotationZ = ((Quaternion)(ref localRotation)).eulerAngles.z;
		for (int i = 0; i < 25; i++)
		{
			Transform transform = card.transform;
			transform.localPosition -= distancePerTick;
			if (playRotate)
			{
				currentRotationX -= rotationPerTick;
				card.transform.localRotation = Quaternion.Euler(currentRotationX, currentRotationY, currentRotationZ);
			}
			yield return (object)new WaitForFixedUpdate();
		}
		Log("PlayDrawAnimation Completed", Preferences.debugging.Value);
	}

	private IEnumerator RunBetMenu()
	{
		Log("RunBetMenu Started", Preferences.debugging.Value);
		betAmount = 1;
		SpawnBetsMenu();
		Log("Spawned Bets Menu, Waiting for Accepted Bet", Preferences.debugging.Value);
		while (!betAccepted && !userQuits)
		{
			yield return (object)new WaitForFixedUpdate();
		}
		if (betAccepted)
		{
			betHeldAmount = betAmount;
			Log("Bet Accepted, Bet: " + betAmount, Preferences.debugging.Value);
		}
		Log("RunBetMenu Completed", Preferences.debugging.Value);
	}

	private GameObject SpawnBetsMenu()
	{
		//IL_0055: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		Log("SpawnBetsMenu Started", Preferences.debugging.Value);
		GameObject val = Object.Instantiate<GameObject>(storedBetsMenu);
		val.transform.SetParent(activeGamePartsTransform);
		val.transform.localPosition = new Vector3(0f, tableInstance.TABLEHEIGHT - 0.052f, 0f);
		val.transform.localRotation = Quaternion.identity;
		val.transform.localScale = Vector3.one;
		betTextComponent = ((Component)val.transform.GetChild(1)).GetComponent<TextMeshPro>();
		UpdateBetAmountText();
		((Component)val.transform.GetChild(2).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Down Pressed", Preferences.debugging.Value);
			if (1 < betAmount)
			{
				betAmount--;
				Log("New Bet: " + betAmount, Preferences.debugging.Value);
				UpdateBetAmountText();
			}
		}));
		((Component)val.transform.GetChild(3).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Up Pressed", Preferences.debugging.Value);
			if (Main.GetPlayerCoinCount() >= betAmount + 1)
			{
				betAmount++;
				Log("New Bet: " + betAmount, Preferences.debugging.Value);
				UpdateBetAmountText();
			}
		}));
		((Component)val.transform.GetChild(4).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Down Pressed", Preferences.debugging.Value);
			if (10 < betAmount)
			{
				betAmount -= 10;
				Log("New Bet: " + betAmount, Preferences.debugging.Value);
				UpdateBetAmountText();
			}
		}));
		((Component)val.transform.GetChild(5).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Up Pressed", Preferences.debugging.Value);
			if (Main.GetPlayerCoinCount() >= betAmount + 10)
			{
				betAmount += 10;
				Log("New Bet: " + betAmount, Preferences.debugging.Value);
				UpdateBetAmountText();
			}
		}));
		((Component)val.transform.GetChild(6).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Accepted: " + betAmount, Preferences.debugging.Value);
			betAccepted = true;
			continueShuffling = false;
		}));
		((Component)val.transform.GetChild(7).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("User Quit During Betting", Preferences.debugging.Value);
			userQuits = true;
			continueShuffling = false;
		}));
		((Component)val.transform.GetChild(8).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Min Pressed", Preferences.debugging.Value);
			betAmount = 1;
			Log("New Bet: " + betAmount, Preferences.debugging.Value);
			UpdateBetAmountText();
		}));
		((Component)val.transform.GetChild(9).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Max Pressed", Preferences.debugging.Value);
			betAmount = Main.GetPlayerCoinCount();
			Log("New Bet: " + betAmount, Preferences.debugging.Value);
			UpdateBetAmountText();
		}));
		val.transform.GetChild(9).GetChild(1).localPosition = new Vector3(0f, 0f, -0.25f);
		betAccepted = false;
		userQuits = false;
		Log("SpawnBetsMenu Completed", Preferences.debugging.Value);
		return val;
	}

	private void RandomizeDeck(bool continueShuffling = true)
	{
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		Log("RandomizeDeck Running", Preferences.debugging.Value);
		object[] shufflings = tableInstance.ShuffleDealerDeck();
		if (continueShuffling)
		{
			ContinueShufflings(shufflings);
		}
		deck = new List<int>();
		List<int> list = new List<int>();
		int num = 0;
		for (int i = 0; i < 52 * Preferences.deckCount.Value; i++)
		{
			deck.Add(num);
			num++;
			if (num == 52)
			{
				num = 0;
			}
		}
		Log("Deck Setup Done", Preferences.debugging.Value);
		tableInstance.dealerDeck.transform.localScale = new Vector3(1f, (float)deck.Count / 52f, 1f);
		list.Clear();
		while (deck.Count > 0)
		{
			int index = tableInstance.random.Next(deck.Count);
			list.Add(deck[index]);
			deck.RemoveAt(index);
		}
		deck.AddRange(list);
		Log("RandomizeDeck Complete", Preferences.debugging.Value);
	}

	private void ContinueShufflings(object[] shufflings)
	{
		continueShuffling = true;
		Transform child = tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).GetChild(0);
		for (int i = 0; i < shufflings.Length; i++)
		{
			MelonCoroutines.Start(ShufflingCard(((Component)((Component)child).transform.GetChild(i)).gameObject, shufflings[i]));
		}
	}

	private IEnumerator ShufflingCard(GameObject card, object spinCoroutine)
	{
		tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).GetChild(0);
		yield return spinCoroutine;
		while (continueShuffling && (Object)(object)tableInstance.blackJackInstance != (Object)null)
		{
			spinCoroutine = MelonCoroutines.Start(tableInstance.SpinCard(card));
			yield return spinCoroutine;
			yield return (object)new WaitForFixedUpdate();
		}
	}

	private void SetupBetMenu()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_0068: 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_0094: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_0433: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_045b: Unknown result type (might be due to invalid IL or missing references)
		Log("SetupBetMenu Started", Preferences.debugging.Value);
		if ((Object)(object)storedBetsMenu != (Object)null)
		{
			Object.Destroy((Object)(object)storedBetsMenu);
		}
		storedBetsMenu = new GameObject("BetsMenu");
		storedBetsMenu.transform.SetParent(storedGamePartsTransform);
		storedBetsMenu.transform.localPosition = Vector3.zero;
		storedBetsMenu.transform.localRotation = Quaternion.identity;
		storedBetsMenu.transform.localScale = Vector3.one;
		GameObject val = tableInstance.SpawnText(storedBetsMenu.transform, "How Much To Bet?", new Vector3(0f, 0f, 0.35f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1.25f, 1.25f, 1.25f));
		TextMeshPro component = val.GetComponent<TextMeshPro>();
		((TMP_Text)component).alignment = (TextAlignmentOptions)514;
		((TMP_Text)component).enableWordWrapping = false;
		GameObject val2 = tableInstance.SpawnText(storedBetsMenu.transform, "BetText", new Vector3(0f, 0f, 0.5f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1f, 1f, 1f));
		TextMeshPro component2 = val2.GetComponent<TextMeshPro>();
		((TMP_Text)component2).alignment = (TextAlignmentOptions)514;
		((TMP_Text)component2).enableWordWrapping = false;
		betTextComponent = val2.GetComponent<TextMeshPro>();
		UpdateBetAmountText();
		GameObject val3 = tableInstance.SpawnButton(storedBetsMenu.transform, "-1", new Vector3(0.15f, 0f, 0.9f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val4 = tableInstance.SpawnButton(storedBetsMenu.transform, "+1", new Vector3(-0.15f, 0f, 0.9f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val5 = tableInstance.SpawnButton(storedBetsMenu.transform, "-10", new Vector3(0.325f, 0f, 0.85f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val6 = tableInstance.SpawnButton(storedBetsMenu.transform, "+10", new Vector3(-0.325f, 0f, 0.85f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val7 = tableInstance.SpawnButton(storedBetsMenu.transform, "Accept", new Vector3(0f, 0f, 0.75f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val8 = tableInstance.SpawnButton(storedBetsMenu.transform, "Exit", new Vector3(0.75f, 0f, 0.25f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val9 = tableInstance.SpawnButton(storedBetsMenu.transform, "Min", new Vector3(0.5f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val10 = tableInstance.SpawnButton(storedBetsMenu.transform, "Max", new Vector3(-0.5f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		Log("SetupBetMenu Completed", Preferences.debugging.Value);
	}

	private GameObject SpawnOptionsMenu(int thisHand)
	{
		//IL_006a: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		Log("SpawnOptionsMenu Started", Preferences.debugging.Value);
		pressedStay = false;
		pressedHit = false;
		pressedSplit = false;
		GameObject val = Object.Instantiate<GameObject>(storedOptionsMenu);
		val.transform.SetParent(activeGamePartsTransform);
		val.transform.localPosition = new Vector3(0f, tableInstance.TABLEHEIGHT - 0.052f, 0f);
		val.transform.localRotation = Quaternion.identity;
		val.transform.localScale = Vector3.one;
		((Component)val.transform.GetChild(0).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Stay Pressed", Preferences.debugging.Value);
			pressedStay = true;
		}));
		((Component)val.transform.GetChild(1).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Hit Pressed", Preferences.debugging.Value);
			pressedHit = true;
		}));
		val.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0f, 0f, -0.25f);
		if (SplitIsPossible(hand[thisHand]))
		{
			((Component)val.transform.GetChild(2).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
			{
				Log("Split Pressed", Preferences.debugging.Value);
				pressedSplit = true;
			}));
			val.transform.GetChild(2).GetChild(1).localPosition = new Vector3(0f, 0f, -0.25f);
			((Component)val.transform.GetChild(2)).gameObject.SetActive(true);
		}
		((TMP_Text)((Component)val.transform.GetChild(3)).GetComponent<TextMeshPro>()).text = GetPlayerHandTotal()[thisHand].ToString();
		val.transform.GetChild(3).localPosition = new Vector3(-0.15f, 0f, 0.6f);
		((Component)val.transform.GetChild(3)).gameObject.SetActive(Preferences.showHandCount.Value);
		int num;
		for (num = dealerHand[0]; num >= 13; num -= 13)
		{
		}
		string text = Math.Min(num + 1, 10).ToString();
		((TMP_Text)((Component)val.transform.GetChild(4)).GetComponent<TextMeshPro>()).text = text;
		((Component)val.transform.GetChild(4)).gameObject.SetActive(Preferences.showHandCount.Value);
		val.transform.GetChild(4).localPosition = new Vector3(-0.15f, 0f, 0.55f);
		((Component)val.transform.GetChild(4)).gameObject.SetActive(Preferences.showHandCount.Value);
		Log("SpawnOptionsMenu Completed", Preferences.debugging.Value);
		return val;
	}

	private IEnumerator RunOptionsMenu(int thisHand)
	{
		Log("RunOptionsMenu Started", Preferences.debugging.Value);
		GameObject optionsMenu = SpawnOptionsMenu(thisHand);
		Log("Spawned Options Menu, Waiting for Selection", Preferences.debugging.Value);
		while (!pressedStay && !pressedHit && !pressedSplit)
		{
			yield return (object)new WaitForFixedUpdate();
		}
		Object.Destroy((Object)(object)optionsMenu);
		if (pressedHit)
		{
			Log("Pressed Hit", Preferences.debugging.Value);
			hand[thisHand].Add(DrawCard());
			Log($"Player Card {hand[thisHand].Count}: {tableInstance.CardString[hand[thisHand][hand[thisHand].Count - 1]]}", Preferences.debugging.Value);
			yield return PlayDrawCardAnimation(hand[thisHand][hand[thisHand].Count - 1], cardSpots.transform.GetChild(0).GetChild(hand[thisHand].Count - 1), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
			if (GetCardsTotal(hand[thisHand]) < 21)
			{
				yield return MelonCoroutines.Start(RunOptionsMenu(thisHand));
			}
			else if (GetCardsTotal(hand[thisHand]) > 21)
			{
				Log("Player Bust, Total: " + GetCardsTotal(hand[thisHand]), Preferences.debugging.Value);
			}
			else
			{
				Log("Player Got 21, Stopping Hand", Preferences.debugging.Value);
			}
		}
		else if (pressedStay)
		{
			Log("Pressed Stay", Preferences.debugging.Value);
		}
		else if (pressedSplit)
		{
			Log("Pressed Split", Preferences.debugging.Value);
			Log("Player Split Bet Accepted: " + betAmount);
			Main.Payout(-betAmount, 1f, tableInstance);
			betHeldAmount += betAmount;
			List<int> secondHand = new List<int>
			{
				-1,
				hand[thisHand][1]
			};
			hand[thisHand][1] = -1;
			string cardsString = "";
			foreach (int i in hand[thisHand])
			{
				cardsString = ((i == -1) ? (cardsString + "-1") : (cardsString + tableInstance.CardString[i]));
				cardsString += " ";
			}
			Log($"Hand {thisHand}: {cardsString}", Preferences.debugging.Value);
			cardsString = "";
			foreach (int i2 in secondHand)
			{
				cardsString = ((i2 == -1) ? (cardsString + "-1") : (cardsString + tableInstance.CardString[i2]));
				cardsString += " ";
			}
			Log("Next Hand: " + cardsString, Preferences.debugging.Value);
			ClearVisualCardsFromAHand(isPlayer: true);
			Log("Playing First Hand", Preferences.debugging.Value);
			yield return MelonCoroutines.Start(DrawSplit(thisHand));
			if (GetCardsTotal(hand[thisHand]) < 21)
			{
				yield return MelonCoroutines.Start(RunOptionsMenu(thisHand));
			}
			else
			{
				yield return (object)new WaitForSeconds(1f);
			}
			Log("Setting Up For Next Hand", Preferences.debugging.Value);
			ClearVisualCardsFromAHand(isPlayer: true);
			hand.Add(secondHand);
			int secondHandSpot = hand.Count - 1;
			Log("Playing Next Hand", Preferences.debugging.Value);
			yield return MelonCoroutines.Start(DrawSplit(secondHandSpot, recreateOriginal: true));
			if (GetCardsTotal(hand[secondHandSpot]) <= 21)
			{
				yield return MelonCoroutines.Start(RunOptionsMenu(secondHandSpot));
			}
			yield return (object)new WaitForSeconds(1f);
		}
		Log("RunOptionsMenu Completed", Preferences.debugging.Value);
	}

	private void ClearVisualCardsFromAHand(bool isPlayer)
	{
		Log("Clearing " + (isPlayer ? "Player's" : "Dealer's") + " Cards", Preferences.debugging.Value);
		int num = ((!isPlayer) ? 1 : 0);
		for (int i = 0; i < cardSpots.transform.GetChild(num).GetChildCount(); i++)
		{
			for (int num2 = cardSpots.transform.GetChild(num).GetChild(i).childCount - 1; num2 >= 0; num2--)
			{
				Object.Destroy((Object)(object)((Component)cardSpots.transform.GetChild(num).GetChild(i).GetChild(num2)).gameObject);
			}
		}
	}

	private IEnumerator DrawSplit(int thisHand, bool recreateOriginal = false)
	{
		bool drawFirstSpot = false;
		if (hand[thisHand][0] == -1)
		{
			hand[thisHand][0] = DrawCard();
			drawFirstSpot = true;
		}
		else
		{
			PlayDrawCardAnimation(hand[thisHand][0], cardSpots.transform.GetChild(0).GetChild(0), cardSpots.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(0f, 0f, 0f), playRotate: false);
		}
		if (hand[thisHand][1] == -1)
		{
			hand[thisHand][1] = DrawCard();
			drawFirstSpot = false;
		}
		else
		{
			PlayDrawCardAnimation(hand[thisHand][1], cardSpots.transform.GetChild(0).GetChild(1), cardSpots.transform.GetChild(0).GetChild(1).position, Quaternion.Euler(0f, 0f, 0f), playRotate: false);
		}
		yield return PlayDrawCardAnimation(hand[thisHand][(!drawFirstSpot) ? 1 : 0], cardSpots.transform.GetChild(0).GetChild((!drawFirstSpot) ? 1 : 0), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
	}

	private IEnumerator DealersTurn()
	{
		Log("DealersTurn Started", Preferences.debugging.Value);
		yield return MelonCoroutines.Start(RevealDealerCard());
		bool hasAce = false;
		bool aceIs11 = false;
		int dealerTotal = GetDealerHandTotal();
		bool hasSoft17 = dealerTotal == 17 && hasAce && aceIs11;
		while (dealerTotal < 17 || hasSoft17)
		{
			yield return MelonCoroutines.Start(DealerDraw());
			dealerTotal = GetDealerHandTotal();
			hasSoft17 = dealerTotal == 17 && hasAce && aceIs11;
			yield return (object)new WaitForSeconds(0.25f);
		}
		Log("DealersTurn Completed", Preferences.debugging.Value);
	}

	private IEnumerator DealerDraw()
	{
		dealerHand.Add(DrawCard());
		Log($"Dealer Card {dealerHand.Count}: " + tableInstance.CardString[dealerHand[dealerHand.Count - 1]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(dealerHand[dealerHand.Count - 1], cardSpots.transform.GetChild(1).GetChild(dealerHand.Count - 1), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
	}

	private void SetupOptionsMenu()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_0068: 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_0094: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		Log("SetupOptionsMenu Started", Preferences.debugging.Value);
		if ((Object)(object)storedOptionsMenu != (Object)null)
		{
			Object.Destroy((Object)(object)storedOptionsMenu);
		}
		storedOptionsMenu = new GameObject("OptionsMenu");
		storedOptionsMenu.transform.SetParent(storedGamePartsTransform);
		storedOptionsMenu.transform.localPosition = Vector3.zero;
		storedOptionsMenu.transform.localRotation = Quaternion.identity;
		storedOptionsMenu.transform.localScale = Vector3.one;
		GameObject val = tableInstance.SpawnButton(storedOptionsMenu.transform, "Stay", new Vector3(0.25f, 0f, 0.9f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val2 = tableInstance.SpawnButton(storedOptionsMenu.transform, "Hit", new Vector3(-0.25f, 0f, 0.9f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val3 = tableInstance.SpawnButton(storedOptionsMenu.transform, "Split", new Vector3(0f, 0f, 0.95f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		val3.SetActive(false);
		GameObject val4 = tableInstance.SpawnText(storedOptionsMenu.transform, "Hand", new Vector3(-0.15f, 0f, 0.6f), Quaternion.Euler(90f, 180f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val5 = tableInstance.SpawnText(storedOptionsMenu.transform, "Hand", new Vector3(-0.15f, 0f, 0.5f), Quaternion.Euler(90f, 180f, 0f), new Vector3(0.5f, 0.5f, 0.55f));
		val5.SetActive(false);
		Log("SetupOptionsMenu Completed", Preferences.debugging.Value);
	}

	private bool SplitIsPossible(List<int> thisHand)
	{
		int num = thisHand[0];
		int num2 = thisHand[1];
		while (num >= 13)
		{
			num -= 13;
		}
		while (num2 >= 13)
		{
			num2 -= 13;
		}
		Log("Is Split Possible: " + (num == num2 && (tableInstance.freePlay || Main.GetPlayerCoinCount() >= betAmount + betHeldAmount)), Preferences.debugging.Value);
		return num == num2 && Main.GetPlayerCoinCount() >= betAmount + betHeldAmount;
	}

	private void UpdateBetAmountText()
	{
		((TMP_Text)betTextComponent).text = betAmount + " of " + Main.GetPlayerCoinCount();
	}
}
[RegisterTypeInIl2Cpp]
public class InteractionLever : MonoBehaviour
{
	private bool leftHandIn = false;

	private bool rightHandIn = false;

	private bool handleActive = false;

	public Action LeverPulled;

	public Action OnLeverReleased;

	public Action OnLeverReleasedComplete;

	public object leverReleaseCoroutine = null;

	public GameObject lastInteractedHand;

	public Player lastInteractedPlayer;

	private void OnTriggerEnter(Collider other)
	{
		if (!(((Object)((Component)other).gameObject).name != "Bone_HandAlpha_L") || !(((Object)((Component)other).gameObject).name != "Bone_HandAlpha_R"))
		{
			if (((Object)((Component)other).gameObject).name == "Bone_HandAlpha_L")
			{
				leftHandIn = true;
			}
			if (((Object)((Component)other).gameObject).name == "Bone_HandAlpha_R")
			{
				rightHandIn = true;
			}
		}
	}

	private void OnTriggerExit(Collider other)
	{
		if (!(((Object)((Component)other).gameObject).name != "Bone_HandAlpha_L") || !(((Object)((Component)other).gameObject).name != "Bone_HandAlpha_R"))
		{
			if (((Object)((Component)other).gameObject).name == "Bone_HandAlpha_L")
			{
				leftHandIn = false;
			}
			if (((Object)((Component)other).gameObject).name == "Bone_HandAlpha_R")
			{
				rightHandIn = false;
			}
		}
	}

	private void OnTriggerStay(Collider other)
	{
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		if (((Object)((Component)other).gameObject).name != "Bone_HandAlpha_L" && ((Object)((Component)other).gameObject).name != "Bone_HandAlpha_R")
		{
			return;
		}
		lastInteractedHand = ((Component)other).gameObject;
		lastInteractedPlayer = ((Component)lastInteractedHand.transform.parent.parent.parent.parent.parent.parent.parent.parent.parent).GetComponent<PlayerController>().AssignedPlayer;
		Quaternion rotation;
		if (leftHandIn)
		{
			if (!handleActive)
			{
				rotation = lastInteractedHand.transform.GetChild(3).GetChild(0).rotation;
				if (((Quaternion)(ref rotation)).eulerAngles.x >= 45f)
				{
					handleActive = true;
					MelonCoroutines.Start(PullLever());
				}
			}
		}
		else if (rightHandIn && !handleActive)
		{
			rotation = lastInteractedHand.transform.GetChild(3).GetChild(0).rotation;
			if (((Quaternion)(ref rotation)).eulerAngles.x >= 45f)
			{
				handleActive = true;
				MelonCoroutines.Start(PullLever());
			}
		}
	}

	private IEnumerator PullLever()
	{
		Quaternion localRotation = lastInteractedHand.transform.GetChild(3).GetChild(0).localRotation;
		float fingerRotation = ((Quaternion)(ref localRotation)).eulerAngles.x;
		while (leverReleaseCoroutine == null && fingerRotation >= 45f)
		{
			try
			{
				localRotation = lastInteractedHand.transform.GetChild(3).GetChild(0).localRotation;
				fingerRotation = ((Quaternion)(ref localRotation)).eulerAngles.x;
				RotateLever();
			}
			catch
			{
				break;
			}
			yield return (object)new WaitForFixedUpdate();
		}
		if (leverReleaseCoroutine == null)
		{
			leverReleaseCoroutine = MelonCoroutines.Start(ReleaseLever());
		}
	}

	private void RotateLever()
	{
		//IL_0019: 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)
		//IL_002b: 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)
		//IL_0042: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		Transform parent = ((Component)this).transform.parent;
		parent.LookAt(lastInteractedHand.transform.position);
		Quaternion localRotation = parent.localRotation;
		parent.localRotation = Quaternion.Euler(((Quaternion)(ref localRotation)).eulerAngles.x, 0f, 0f);
		localRotation = parent.localRotation;
		if (((Quaternion)(ref localRotation)).eulerAngles.x < 295f)
		{
			parent.localRotation = Quaternion.Euler(295f, 0f, 0f);
			return;
		}
		localRotation = parent.localRotation;
		if (!(((Quaternion)(ref localRotation)).eulerAngles.x >= 340f))
		{
			return;
		}
		parent.localRotation = Quaternion.Euler(340f, 0f, 0f);
		leverReleaseCoroutine = MelonCoroutines.Start(ReleaseLever());
		Delegate[] array = LeverPulled?.GetInvocationList();
		if (array == null)
		{
			return;
		}
		Delegate[] array2 = array;
		foreach (Delegate obj in array2)
		{
			try
			{
				obj.DynamicInvoke();
			}
			catch (Exception ex)
			{
				MelonLogger.Msg("RotateLever Error for LeverPulled: " + obj.Target);
				MelonLogger.Error((object)ex.InnerException);
			}
		}
	}

	private IEnumerator ReleaseLever()
	{
		Delegate[] listeners = OnLeverReleased?.GetInvocationList();
		if (listeners != null)
		{
			Delegate[] array = listeners;
			foreach (Delegate listener in array)
			{
				try
				{
					listener.DynamicInvoke();
				}
				catch (Exception ex)
				{
					MelonLogger.Msg("ReleaseLever Error for OnLeverReleased: " + listener.Target);
					MelonLogger.Error((object)ex.InnerException);
				}
			}
		}
		Transform parent = ((Component)this).transform.parent;
		Quaternion localRotation = ((Component)parent).transform.localRotation;
		int currentAngle = (int)((Quaternion)(ref localRotation)).eulerAngles.x;
		if (currentAngle < 295)
		{
			currentAngle += 360;
		}
		int rotationPerTick = 1;
		while (currentAngle != 295)
		{
			yield return (object)new WaitForFixedUpdate();
			currentAngle -= rotationPerTick;
			parent.localRotation = Quaternion.Euler((float)currentAngle, 0f, 0f);
		}
		handleActive = false;
		Delegate[] listeners2 = OnLeverReleasedComplete?.GetInvocationList();
		if (listeners2 != null)
		{
			Delegate[] array2 = listeners2;
			foreach (Delegate listener2 in array2)
			{
				try
				{
					listener2.DynamicInvoke();
				}
				catch (Exception ex2)
				{
					MelonLogger.Msg("ReleaseLever Error for OnLeverReleasedComplete: " + listener2.Target);
					MelonLogger.Error((object)ex2.InnerException);
				}
			}
		}
		leverReleaseCoroutine = null;
	}
}
public enum PayoutResult
{
	Nothing,
	JacksOrBetter,
	TwoPair,
	ThreeOfAKind,
	Straight,
	Flush,
	FullHouse,
	FourOfAKind,
	StraightFlush,
	RoyalFlush
}
public enum CardSuits
{
	Spades,
	Hearts,
	Diamonds,
	Clubs
}
public class JacksOrBetter : MonoBehaviour
{
	private string[] payoutsString = new string[10] { "Nothing", "Jacks or Better", "Two Pair", "Three of a Kind", "Straight", "Flush", "Full House", "Four of a Kind", "Straight Flush", "Royal Flush" };

	private float[] payoutsAmounts = new float[10] { 0f, 1f, 2f, 3f, 4f, 6f, 9f, 25f, 50f, 976f };

	private int betAmount = 1;

	private bool gameLoopRunning = false;

	private TextMeshPro betTextComponent = null;

	private GameObject storedBetsMenu = null;

	private GameObject storedOptionsMenu = null;

	private bool betAccepted = false;

	private bool userQuits = false;

	private List<int> deck;

	private List<int> hand;

	public object gameLoopCoroutine = null;

	private Transform storedGamePartsTransform = null;

	private Transform activeGamePartsTransform = null;

	private Table tableInstance;

	private GameObject cardSpots = null;

	private int coinsGained = 0;

	private PayoutResult thisHandsPayout = PayoutResult.Nothing;

	private bool continueShuffling = true;

	private bool pressedContinue;

	private bool removeCard1 = true;

	private bool removeCard2 = true;

	private bool removeCard3 = true;

	private bool removeCard4 = true;

	private bool removeCard5 = true;

	public JacksOrBetter(Table tableInstance)
	{
		this.tableInstance = tableInstance;
	}

	public static void Log(string msg, bool sendMsg = true)
	{
		if (sendMsg)
		{
			Table.Log("JacksOrBetter - " + msg, sendMsg);
		}
	}

	public static void Warn(string msg, bool sendMsg = true)
	{
		if (sendMsg)
		{
			Table.Warn("JacksOrBetter - " + msg, sendMsg);
		}
	}

	public static void Error(string msg)
	{
		Table.Error("JacksOrBetter - " + msg);
	}

	public void ShowSplash()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_0061: 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_0083: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		storedGamePartsTransform = ((Component)tableInstance).transform.GetChild(1);
		activeGamePartsTransform = ((Component)tableInstance).transform.GetChild(2);
		GameObject val = new GameObject("SplashScreen");
		val.transform.SetParent(activeGamePartsTransform);
		val.transform.localPosition = new Vector3(0f, 0.9454f, 0f);
		val.transform.localRotation = Quaternion.identity;
		val.transform.localScale = Vector3.one;
		GameObject val2 = tableInstance.SpawnText(val.transform, "Jacks or Better", new Vector3(0f, 0f, 0.4f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1.25f, 1.25f, 1.25f));
		TextMeshPro component = val2.GetComponent<TextMeshPro>();
		((TMP_Text)component).alignment = (TextAlignmentOptions)514;
		((TMP_Text)component).enableWordWrapping = false;
	}

	public IEnumerator Run()
	{
		Log("Run Running", Preferences.debugging.Value);
		SetupStart();
		gameLoopCoroutine = MelonCoroutines.Start(GameLoop());
		yield return gameLoopCoroutine;
		Log("Run Completed", Preferences.debugging.Value);
	}

	private void SetupStart()
	{
		Log("SetupStart Running", Preferences.debugging.Value);
		gameLoopRunning = false;
		RandomizeDeck();
		SetupBetMenu();
		SetupOptionsMenu();
		Log("SetupStart Completed", Preferences.debugging.Value);
	}

	private void SetupCardSpots()
	{
		//IL_0065: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		Log("SetupStart Started", Preferences.debugging.Value);
		cardSpots = Object.Instantiate<GameObject>(((Component)storedGamePartsTransform.GetChild(2)).gameObject);
		((Object)cardSpots).name = "CardSpots";
		cardSpots.transform.SetParent(activeGamePartsTransform);
		cardSpots.transform.localPosition = Vector3.zero;
		cardSpots.transform.localRotation = Quaternion.identity;
		cardSpots.transform.localScale = Vector3.one;
		Log("SetupStart Completed", Preferences.debugging.Value);
	}

	private IEnumerator GameLoop()
	{
		Log("GameLoop Running", Preferences.debugging.Value);
		gameLoopRunning = true;
		while (gameLoopRunning)
		{
			if (deck.Count <= 26 * Preferences.deckCount.Value)
			{
				RandomizeDeck(continueShuffling: false);
				yield return (object)new WaitForSeconds(1f);
			}
			betAmount = 1;
			if (!tableInstance.freePlay && Main.GetPlayerCoinCount() < betAmount)
			{
				GameObject youBrokeAsFuck = tableInstance.SpawnText(((Component)activeGamePartsTransform).transform, "Too Few Coins. Try Free Play or" + Environment.NewLine + "Complete More Poses to Earn Coins", new Vector3(0f, tableInstance.TABLEHEIGHT - 0.025f, 0.65f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1f, 1f, 1f));
				((Object)youBrokeAsFuck).name = "You Broke As Fuck";
				TextMeshPro endGameTextTMP = youBrokeAsFuck.GetComponent<TextMeshPro>();
				((TMP_Text)endGameTextTMP).alignment = (TextAlignmentOptions)514;
				((TMP_Text)endGameTextTMP).enableWordWrapping = false;
				continueShuffling = false;
				Log("Not Enough Coins, Exiting Jacks Or Better", Preferences.debugging.Value);
				yield return (object)new WaitForSeconds(1.5f);
				gameLoopRunning = false;
				break;
			}
			tableInstance.ClearActiveObjects();
			yield return MelonCoroutines.Start(RunBetMenu());
			tableInstance.ClearActiveObjects();
			yield return (object)new WaitForSeconds(1.5f);
			if (userQuits)
			{
				gameLoopRunning = false;
			}
			if (betAccepted)
			{
				Log("Player Bet Accepted: " + betAmount);
				Main.Payout(-betAmount, 1f, tableInstance);
				coinsGained = 0;
				yield return MelonCoroutines.Start(PlayHand());
				yield return (object)new WaitForSeconds(0.5f);
				yield return MelonCoroutines.Start(CheckPayout());
				ClearCardSpots();
				bool continuePressed = false;
				GameObject endGameText = tableInstance.SpawnText(((Component)activeGamePartsTransform).transform, "End Game Text", new Vector3(0f, tableInstance.TABLEHEIGHT - 0.025f, 0.5f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1f, 1f, 1f));
				((Object)endGameText).name = "End Game Text";
				TextMeshPro endGameTextTMP2 = endGameText.GetComponent<TextMeshPro>();
				((TMP_Text)endGameTextTMP2).alignment = (TextAlignmentOptions)514;
				((TMP_Text)endGameTextTMP2).enableWordWrapping = false;
				((TMP_Text)endGameTextTMP2).text = string.Concat(str3: (coinsGained == 0) ? $"Coins Lost: {-betAmount}" : $"Coins Gained: {coinsGained - betAmount}", str0: "Hand Contains: ", str1: payoutsString[(int)thisHandsPayout], str2: Environment.NewLine);
				GameObject continueButton = tableInstance.LoadMenuButton("Continue", new Vector3(0f, tableInstance.TABLEHEIGHT - 0.025f, 0.96f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f), delegate
				{
					continuePressed = true;
				});
				((Object)continueButton).name = "Continue";
				while (!continuePressed && gameLoopRunning)
				{
					yield return (object)new WaitForFixedUpdate();
				}
			}
			tableInstance.ClearActiveObjects();
		}
		Log("GameLoop Completed", Preferences.debugging.Value);
	}

	private IEnumerator CheckPayout()
	{
		Log("CheckPayout Started", Preferences.debugging.Value);
		thisHandsPayout = GetWinType();
		coinsGained = Main.Payout(betAmount, payoutsAmounts[(int)thisHandsPayout], tableInstance);
		Log($"Hand Contains: {payoutsString[(int)thisHandsPayout]}, Paying Out: {coinsGained}");
		yield return (thisHandsPayout != PayoutResult.Nothing) ? MelonCoroutines.Start(PlayPlayerWin()) : MelonCoroutines.Start(PlayPlayerLose());
		Log("CheckPayout Completed", Preferences.debugging.Value);
	}

	private IEnumerator PlayPlayerWin()
	{
		Log("PlayPlayerWin Started", Preferences.debugging.Value);
		List<object> coroutines = new List<object>();
		yield return (object)new WaitForSeconds(0.25f);
		for (int i = 0; i < 5; i++)
		{
			coroutines.Add(MelonCoroutines.Start(PlayCardWinCoroutine(((Component)cardSpots.transform.GetChild(i).GetChild(0)).gameObject, destroyAfter: true)));
			yield return (object)new WaitForSeconds(0.1f);
		}
		foreach (object item in coroutines)
		{
			yield return item;
		}
		yield return (object)new WaitForSeconds(0.25f);
		Log("PlayPlayerWin Completed", Preferences.debugging.Value);
	}

	private IEnumerator PlayPlayerLose()
	{
		Log("PlayPlayerLose Started", Preferences.debugging.Value);
		List<object> coroutines = new List<object>();
		yield return (object)new WaitForSeconds(0.25f);
		for (int i = 0; i < 5; i++)
		{
			coroutines.Add(MelonCoroutines.Start(PlayCardShrinkCoroutine(((Component)cardSpots.transform.GetChild(i).GetChild(0)).gameObject, destroyAfter: true)));
		}
		foreach (object item in coroutines)
		{
			yield return item;
		}
		yield return (object)new WaitForSeconds(0.25f);
		Log("PlayPlayerLose Completed", Preferences.debugging.Value);
	}

	private PayoutResult GetWinType()
	{
		if (HasRoyalFlush())
		{
			return PayoutResult.RoyalFlush;
		}
		if (HasStraightFlush())
		{
			return PayoutResult.StraightFlush;
		}
		if (HasFourOfAKind())
		{
			return PayoutResult.FourOfAKind;
		}
		if (HasFullHouse())
		{
			return PayoutResult.FullHouse;
		}
		if (HasFlush())
		{
			return PayoutResult.Flush;
		}
		if (HasStraight())
		{
			return PayoutResult.Straight;
		}
		if (HasThreeOfAKind())
		{
			return PayoutResult.ThreeOfAKind;
		}
		if (HasTwoPair())
		{
			return PayoutResult.TwoPair;
		}
		if (HasJacksOrBetter())
		{
			return PayoutResult.JacksOrBetter;
		}
		return PayoutResult.Nothing;
	}

	private bool HasJacksOrBetter()
	{
		List<int> list = new List<int>();
		foreach (int item in hand)
		{
			list.Add(getCardValue(item));
		}
		List<int> list2 = new List<int>();
		for (int i = 0; i < 13; i++)
		{
			list2.Add(0);
		}
		foreach (int item2 in list)
		{
			list2[item2 - 1]++;
		}
		return list2[0] >= 2 || list2[10] >= 2 || list2[11] >= 2 || list2[12] >= 2;
	}

	private bool HasTwoPair()
	{
		List<int> list = new List<int>();
		foreach (int item in hand)
		{
			list.Add(getCardValue(item));
		}
		List<int> list2 = new List<int>();
		for (int i = 0; i < 13; i++)
		{
			list2.Add(0);
		}
		foreach (int item2 in list)
		{
			list2[item2 - 1]++;
		}
		bool result = false;
		if (list2.Contains(2))
		{
			list2.Remove(2);
			if (list2.Contains(2))
			{
				result = true;
			}
		}
		return result;
	}

	private bool HasThreeOfAKind()
	{
		return HasXOfAKind(3);
	}

	private bool HasFourOfAKind()
	{
		return HasXOfAKind(4);
	}

	private bool HasFullHouse()
	{
		List<int> list = new List<int>();
		foreach (int item in hand)
		{
			list.Add(getCardValue(item));
		}
		List<int> list2 = new List<int>();
		for (int i = 0; i < 13; i++)
		{
			list2.Add(0);
		}
		foreach (int item2 in list)
		{
			list2[item2 - 1]++;
		}
		list2.Sort();
		return list2[12] == 3 && list2[11] == 2;
	}

	private bool HasStraightFlush()
	{
		return HasFlush() && HasStraight();
	}

	private bool HasRoyalFlush()
	{
		return HasFlush() && DoesHandContainCardValue(1) && DoesHandContainCardValue(10) && DoesHandContainCardValue(11) && DoesHandContainCardValue(12) && DoesHandContainCardValue(13);
	}

	private bool HasStraight()
	{
		List<int> list = new List<int>();
		foreach (int item in hand)
		{
			list.Add(getCardValue(item));
		}
		list.Sort();
		bool flag = false;
		bool flag2 = false;
		if (list[0] == 1)
		{
			flag = true;
			list.Add(list[0]);
		}
		bool result = true;
		for (int i = 0; i < list.Count - 1; i++)
		{
			if (list[i] + 1 != list[i + 1])
			{
				if (!flag || flag2)
				{
					result = false;
					break;
				}
				flag2 = true;
			}
		}
		return result;
	}

	private bool HasFlush()
	{
		CardSuits[] array = new CardSuits[5]
		{
			getCardSuit(hand[0]),
			getCardSuit(hand[1]),
			getCardSuit(hand[2]),
			getCardSuit(hand[3]),
			getCardSuit(hand[4])
		};
		return array[0] == array[1] && array[0] == array[2] && array[0] == array[3] && array[0] == array[4];
	}

	private bool DoesHandContainCardValue(int cardNumberToFind)
	{
		return getCardValue(hand[0]) == cardNumberToFind || getCardValue(hand[1]) == cardNumberToFind || getCardValue(hand[2]) == cardNumberToFind || getCardValue(hand[3]) == cardNumberToFind || getCardValue(hand[4]) == cardNumberToFind;
	}

	private bool HasXOfAKind(int x)
	{
		List<int> list = new List<int>();
		foreach (int item in hand)
		{
			list.Add(getCardValue(item));
		}
		List<int> list2 = new List<int>();
		for (int i = 0; i < 13; i++)
		{
			list2.Add(0);
		}
		foreach (int item2 in list)
		{
			list2[item2 - 1]++;
		}
		list2.Sort();
		return x <= list2[12];
	}

	private int getCardValue(int rawCard)
	{
		int num;
		for (num = rawCard; num >= 13; num -= 13)
		{
		}
		return num + 1;
	}

	private CardSuits getCardSuit(int rawCard)
	{
		int num = rawCard;
		CardSuits cardSuits = CardSuits.Spades;
		while (num >= 13)
		{
			num -= 13;
			cardSuits++;
		}
		return cardSuits;
	}

	private IEnumerator PlayCardShrinkCoroutine(GameObject card, bool destroyAfter = false)
	{
		Vector3 startingScale = card.transform.localScale;
		Vector3 scalePerTick = startingScale / 50f;
		for (int i = 0; i < 50; i++)
		{
			Transform transform = card.transform;
			transform.localScale -= scalePerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		if (destroyAfter)
		{
			Object.Destroy((Object)(object)card);
		}
	}

	private IEnumerator PlayCardWinCoroutine(GameObject card, bool destroyAfter = false)
	{
		_ = card.transform.localPosition;
		Vector3 positionPerTick = Vector3.up * 0.004f;
		for (int i = 0; i < 25; i++)
		{
			Transform transform = card.transform;
			transform.localPosition += positionPerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		for (int j = 0; j < 25; j++)
		{
			Transform transform2 = card.transform;
			transform2.localPosition -= positionPerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		for (int k = 0; k < 25; k++)
		{
			Transform transform3 = card.transform;
			transform3.localPosition += positionPerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		object winShrinkCoroutine = MelonCoroutines.Start(PlayCardShrinkCoroutine(card));
		for (int l = 0; l < 25; l++)
		{
			Transform transform4 = card.transform;
			transform4.localPosition -= positionPerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		for (int m = 0; m < 25; m++)
		{
			Transform transform5 = card.transform;
			transform5.localPosition += positionPerTick;
			yield return (object)new WaitForFixedUpdate();
		}
		yield return winShrinkCoroutine;
		if (destroyAfter)
		{
			Object.Destroy((Object)(object)card);
		}
	}

	private IEnumerator PlayHand()
	{
		Log("PlayHand Running", Preferences.debugging.Value);
		hand = new List<int>();
		SetupCardSpots();
		yield return MelonCoroutines.Start(DrawStartingHand());
		yield return MelonCoroutines.Start(RunOptionsMenu());
		yield return MelonCoroutines.Start(ReplaceMissingCardsInHand());
		Log("PlayHand Completed", Preferences.debugging.Value);
	}

	private IEnumerator DrawStartingHand()
	{
		Log("DrawStartingHand Started", Preferences.debugging.Value);
		hand.Add(DrawCard());
		Log("Player Card 1: " + tableInstance.CardString[hand[0]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(hand[0], cardSpots.transform.GetChild(0), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
		hand.Add(DrawCard());
		Log("Player Card 2: " + tableInstance.CardString[hand[1]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(hand[1], cardSpots.transform.GetChild(1), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
		hand.Add(DrawCard());
		Log("Player Card 3: " + tableInstance.CardString[hand[2]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(hand[2], cardSpots.transform.GetChild(2), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
		hand.Add(DrawCard());
		Log("Player Card 4: " + tableInstance.CardString[hand[3]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(hand[3], cardSpots.transform.GetChild(3), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
		hand.Add(DrawCard());
		Log("Player Card 5: " + tableInstance.CardString[hand[4]], Preferences.debugging.Value);
		yield return PlayDrawCardAnimation(hand[4], cardSpots.transform.GetChild(4), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
		Log("DrawStartingHand Completed", Preferences.debugging.Value);
	}

	private IEnumerator ReplaceMissingCardsInHand()
	{
		Log("ReplaceMissingCardsInHand Started", Preferences.debugging.Value);
		for (int i = 0; i < 5; i++)
		{
			if (hand[i] == -1)
			{
				hand[i] = DrawCard();
				yield return PlayDrawCardAnimation(hand[i], cardSpots.transform.GetChild(i), tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).position, Quaternion.Euler(-180f, 0f, 0f));
				yield return (object)new WaitForSeconds(0.25f);
			}
		}
		Log("ReplaceMissingCardsInHand Completed", Preferences.debugging.Value);
	}

	private object PlayDrawCardAnimation(int CardToDraw, Transform parent, Vector3 position, Quaternion localRotation, bool playRotate = true)
	{
		//IL_004a: 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)
		Log("PlayDrawCardAnimation Started", Preferences.debugging.Value);
		GameObject val = Object.Instantiate<GameObject>(((Component)tableInstance.storedDeckOfCards.transform.GetChild(CardToDraw)).gameObject);
		val.transform.SetParent(parent);
		val.transform.position = position;
		val.transform.localRotation = localRotation;
		Log("PlayDrawCardAnimation Completed", Preferences.debugging.Value);
		return MelonCoroutines.Start(PlayDrawAnimation(val, 25, playRotate));
	}

	private int DrawCard()
	{
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		if (deck.Count == 0)
		{
			RandomizeDeck();
		}
		int result = deck[0];
		deck.RemoveAt(0);
		tableInstance.dealerDeck.transform.localScale = new Vector3(1f, (float)deck.Count / 52f, 1f);
		return result;
	}

	private IEnumerator PlayDrawAnimation(GameObject card, int ticks = 25, bool playRotate = true)
	{
		Log("PlayDrawAnimation Started", Preferences.debugging.Value);
		Vector3 distancePerTick = card.transform.localPosition / (float)ticks;
		float rotationPerTick = 180f / (float)ticks;
		Quaternion localRotation = card.transform.localRotation;
		float currentRotationX = ((Quaternion)(ref localRotation)).eulerAngles.x;
		localRotation = card.transform.localRotation;
		float currentRotationY = ((Quaternion)(ref localRotation)).eulerAngles.y;
		localRotation = card.transform.localRotation;
		float currentRotationZ = ((Quaternion)(ref localRotation)).eulerAngles.z;
		for (int i = 0; i < 25; i++)
		{
			Transform transform = card.transform;
			transform.localPosition -= distancePerTick;
			if (playRotate)
			{
				currentRotationX -= rotationPerTick;
				card.transform.localRotation = Quaternion.Euler(currentRotationX, currentRotationY, currentRotationZ);
			}
			yield return (object)new WaitForFixedUpdate();
		}
		Log("PlayDrawAnimation Completed", Preferences.debugging.Value);
	}

	private IEnumerator RunBetMenu()
	{
		Log("RunBetMenu Started", Preferences.debugging.Value);
		betAmount = 1;
		SpawnBetsMenu();
		Log("Spawned Bets Menu, Waiting for Accepted Bet", Preferences.debugging.Value);
		while (!betAccepted && !userQuits)
		{
			yield return (object)new WaitForFixedUpdate();
		}
		Log("RunBetMenu Completed", Preferences.debugging.Value);
	}

	private GameObject SpawnBetsMenu()
	{
		//IL_0055: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		Log("SpawnBetsMenu Started", Preferences.debugging.Value);
		GameObject val = Object.Instantiate<GameObject>(storedBetsMenu);
		val.transform.SetParent(activeGamePartsTransform);
		val.transform.localPosition = new Vector3(0f, tableInstance.TABLEHEIGHT - 0.052f, 0f);
		val.transform.localRotation = Quaternion.identity;
		val.transform.localScale = Vector3.one;
		betTextComponent = ((Component)val.transform.GetChild(1)).GetComponent<TextMeshPro>();
		UpdateBetAmountText();
		((Component)val.transform.GetChild(2).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Down Pressed", Preferences.debugging.Value);
			if (1 < betAmount)
			{
				betAmount--;
				Log("New Bet: " + betAmount, Preferences.debugging.Value);
				UpdateBetAmountText();
			}
		}));
		((Component)val.transform.GetChild(3).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Up Pressed", Preferences.debugging.Value);
			if (Main.GetPlayerCoinCount() >= betAmount + 1)
			{
				betAmount++;
				Log("New Bet: " + betAmount, Preferences.debugging.Value);
				UpdateBetAmountText();
			}
		}));
		((Component)val.transform.GetChild(4).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Down Pressed", Preferences.debugging.Value);
			if (10 < betAmount)
			{
				betAmount -= 10;
				Log("New Bet: " + betAmount, Preferences.debugging.Value);
				UpdateBetAmountText();
			}
		}));
		((Component)val.transform.GetChild(5).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Up Pressed", Preferences.debugging.Value);
			if (Main.GetPlayerCoinCount() >= betAmount + 10)
			{
				betAmount += 10;
				Log("New Bet: " + betAmount, Preferences.debugging.Value);
				UpdateBetAmountText();
			}
		}));
		((Component)val.transform.GetChild(6).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Accepted: " + betAmount, Preferences.debugging.Value);
			betAccepted = true;
			continueShuffling = false;
		}));
		((Component)val.transform.GetChild(7).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("User Quit During Betting", Preferences.debugging.Value);
			userQuits = true;
			continueShuffling = false;
		}));
		((Component)val.transform.GetChild(8).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Min Pressed", Preferences.debugging.Value);
			betAmount = 1;
			Log("New Bet: " + betAmount, Preferences.debugging.Value);
			UpdateBetAmountText();
		}));
		((Component)val.transform.GetChild(9).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Bet Max Pressed", Preferences.debugging.Value);
			betAmount = Main.GetPlayerCoinCount();
			Log("New Bet: " + betAmount, Preferences.debugging.Value);
			UpdateBetAmountText();
		}));
		val.transform.GetChild(9).GetChild(1).localPosition = new Vector3(0f, 0f, -0.25f);
		betAccepted = false;
		userQuits = false;
		Log("SpawnBetsMenu Completed", Preferences.debugging.Value);
		return val;
	}

	private void RandomizeDeck(bool continueShuffling = true)
	{
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		Log("RandomizeDeck Running", Preferences.debugging.Value);
		object[] shufflings = tableInstance.ShuffleDealerDeck();
		if (continueShuffling)
		{
			ContinueShufflings(shufflings);
		}
		deck = new List<int>();
		List<int> list = new List<int>();
		int num = 0;
		for (int i = 0; i < 52 * Preferences.deckCount.Value; i++)
		{
			deck.Add(num);
			num++;
			if (num == 52)
			{
				num = 0;
			}
		}
		Log("Deck Setup Done", Preferences.debugging.Value);
		tableInstance.dealerDeck.transform.localScale = new Vector3(1f, (float)deck.Count / 52f, 1f);
		list.Clear();
		while (deck.Count > 0)
		{
			int index = tableInstance.random.Next(deck.Count);
			list.Add(deck[index]);
			deck.RemoveAt(index);
		}
		deck.AddRange(list);
		Log("RandomizeDeck Complete", Preferences.debugging.Value);
	}

	private void ContinueShufflings(object[] shufflings)
	{
		continueShuffling = true;
		Transform child = tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).GetChild(0);
		for (int i = 0; i < shufflings.Length; i++)
		{
			MelonCoroutines.Start(ShufflingCard(((Component)((Component)child).transform.GetChild(i)).gameObject, shufflings[i]));
		}
	}

	private IEnumerator ShufflingCard(GameObject card, object spinCoroutine)
	{
		tableInstance.dealerDeck.transform.GetChild(0).GetChild(0).GetChild(0);
		yield return spinCoroutine;
		while (continueShuffling && (Object)(object)tableInstance.jacksOrBetterInstance != (Object)null)
		{
			spinCoroutine = MelonCoroutines.Start(tableInstance.SpinCard(card));
			yield return spinCoroutine;
			yield return (object)new WaitForFixedUpdate();
		}
	}

	private void SetupBetMenu()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_0068: 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_0094: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_0433: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_045b: Unknown result type (might be due to invalid IL or missing references)
		Log("SetupBetMenu Started", Preferences.debugging.Value);
		if ((Object)(object)storedBetsMenu != (Object)null)
		{
			Object.Destroy((Object)(object)storedBetsMenu);
		}
		storedBetsMenu = new GameObject("BetsMenu");
		storedBetsMenu.transform.SetParent(storedGamePartsTransform);
		storedBetsMenu.transform.localPosition = Vector3.zero;
		storedBetsMenu.transform.localRotation = Quaternion.identity;
		storedBetsMenu.transform.localScale = Vector3.one;
		GameObject val = tableInstance.SpawnText(storedBetsMenu.transform, "How Much To Bet?", new Vector3(0f, 0f, 0.35f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1.25f, 1.25f, 1.25f));
		TextMeshPro component = val.GetComponent<TextMeshPro>();
		((TMP_Text)component).alignment = (TextAlignmentOptions)514;
		((TMP_Text)component).enableWordWrapping = false;
		GameObject val2 = tableInstance.SpawnText(storedBetsMenu.transform, "BetText", new Vector3(0f, 0f, 0.5f), Quaternion.Euler(90f, 180f, 0f), new Vector3(1f, 1f, 1f));
		TextMeshPro component2 = val2.GetComponent<TextMeshPro>();
		((TMP_Text)component2).alignment = (TextAlignmentOptions)514;
		((TMP_Text)component2).enableWordWrapping = false;
		betTextComponent = val2.GetComponent<TextMeshPro>();
		UpdateBetAmountText();
		GameObject val3 = tableInstance.SpawnButton(storedBetsMenu.transform, "-1", new Vector3(0.15f, 0f, 0.9f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val4 = tableInstance.SpawnButton(storedBetsMenu.transform, "+1", new Vector3(-0.15f, 0f, 0.9f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val5 = tableInstance.SpawnButton(storedBetsMenu.transform, "-10", new Vector3(0.325f, 0f, 0.85f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val6 = tableInstance.SpawnButton(storedBetsMenu.transform, "+10", new Vector3(-0.325f, 0f, 0.85f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val7 = tableInstance.SpawnButton(storedBetsMenu.transform, "Accept", new Vector3(0f, 0f, 0.75f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val8 = tableInstance.SpawnButton(storedBetsMenu.transform, "Exit", new Vector3(0.75f, 0f, 0.25f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val9 = tableInstance.SpawnButton(storedBetsMenu.transform, "Min", new Vector3(0.5f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		GameObject val10 = tableInstance.SpawnButton(storedBetsMenu.transform, "Max", new Vector3(-0.5f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		Log("SetupBetMenu Completed", Preferences.debugging.Value);
	}

	private GameObject SpawnOptionsMenu()
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		Log("SpawnOptionsMenu Started", Preferences.debugging.Value);
		pressedContinue = false;
		removeCard1 = true;
		removeCard2 = true;
		removeCard3 = true;
		removeCard4 = true;
		removeCard5 = true;
		GameObject spawnedOptionsMenu = Object.Instantiate<GameObject>(storedOptionsMenu);
		spawnedOptionsMenu.transform.SetParent(activeGamePartsTransform);
		spawnedOptionsMenu.transform.localPosition = new Vector3(0f, tableInstance.TABLEHEIGHT - 0.052f, 0f);
		spawnedOptionsMenu.transform.localRotation = Quaternion.identity;
		spawnedOptionsMenu.transform.localScale = Vector3.one;
		((Component)spawnedOptionsMenu.transform.GetChild(0).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Card 1 Pressed", Preferences.debugging.Value);
			removeCard1 = !removeCard1;
			((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(0).GetChild(1)).GetComponent<TextMeshPro>()).text = (removeCard1 ? "Remove" : "Keep");
		}));
		((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(0).GetChild(1)).GetComponent<TextMeshPro>()).text = "Remove";
		((Component)spawnedOptionsMenu.transform.GetChild(1).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Card 2 Pressed", Preferences.debugging.Value);
			removeCard2 = !removeCard2;
			((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(1).GetChild(1)).GetComponent<TextMeshPro>()).text = (removeCard2 ? "Remove" : "Keep");
		}));
		((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(1).GetChild(1)).GetComponent<TextMeshPro>()).text = "Remove";
		((Component)spawnedOptionsMenu.transform.GetChild(2).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Card 3 Pressed", Preferences.debugging.Value);
			removeCard3 = !removeCard3;
			((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(2).GetChild(1)).GetComponent<TextMeshPro>()).text = (removeCard3 ? "Remove" : "Keep");
		}));
		((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(2).GetChild(1)).GetComponent<TextMeshPro>()).text = "Remove";
		((Component)spawnedOptionsMenu.transform.GetChild(3).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Card 4 Pressed", Preferences.debugging.Value);
			removeCard4 = !removeCard4;
			((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(3).GetChild(1)).GetComponent<TextMeshPro>()).text = (removeCard4 ? "Remove" : "Keep");
		}));
		((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(3).GetChild(1)).GetComponent<TextMeshPro>()).text = "Remove";
		((Component)spawnedOptionsMenu.transform.GetChild(4).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Card 5 Pressed", Preferences.debugging.Value);
			removeCard5 = !removeCard5;
			((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(4).GetChild(1)).GetComponent<TextMeshPro>()).text = (removeCard5 ? "Remove" : "Keep");
		}));
		((TMP_Text)((Component)spawnedOptionsMenu.transform.GetChild(4).GetChild(1)).GetComponent<TextMeshPro>()).text = "Remove";
		((Component)spawnedOptionsMenu.transform.GetChild(5).GetChild(0)).GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
		{
			Log("Continue Pressed", Preferences.debugging.Value);
			pressedContinue = true;
		}));
		spawnedOptionsMenu.transform.GetChild(5).GetChild(1).localPosition = new Vector3(0f, 0f, -0.2f);
		Log("SpawnOptionsMenu Completed", Preferences.debugging.Value);
		return spawnedOptionsMenu;
	}

	private IEnumerator RunOptionsMenu()
	{
		Log("RunOptionsMenu Started", Preferences.debugging.Value);
		GameObject optionsMenu = SpawnOptionsMenu();
		Log("Spawned Options Menu, Waiting for Selection", Preferences.debugging.Value);
		while (!pressedContinue)
		{
			yield return (object)new WaitForFixedUpdate();
		}
		Object.Destroy((Object)(object)optionsMenu);
		Log($"Keep / Remove List: {removeCard1} {removeCard2} {removeCard3} {removeCard4} {removeCard5}", Preferences.debugging.Value);
		List<object> cardsRemoving = new List<object>();
		if (removeCard1)
		{
			Log("Removing Card 1", Preferences.debugging.Value);
			cardsRemoving.Add(MelonCoroutines.Start(PlayCardShrinkCoroutine(((Component)cardSpots.transform.GetChild(0).GetChild(0)).gameObject, destroyAfter: true)));
			hand[0] = -1;
		}
		if (removeCard2)
		{
			Log("Removing Card 2", Preferences.debugging.Value);
			cardsRemoving.Add(MelonCoroutines.Start(PlayCardShrinkCoroutine(((Component)cardSpots.transform.GetChild(1).GetChild(0)).gameObject, destroyAfter: true)));
			hand[1] = -1;
		}
		if (removeCard3)
		{
			Log("Removing Card 3", Preferences.debugging.Value);
			cardsRemoving.Add(MelonCoroutines.Start(PlayCardShrinkCoroutine(((Component)cardSpots.transform.GetChild(2).GetChild(0)).gameObject, destroyAfter: true)));
			hand[2] = -1;
		}
		if (removeCard4)
		{
			Log("Removing Card 4", Preferences.debugging.Value);
			cardsRemoving.Add(MelonCoroutines.Start(PlayCardShrinkCoroutine(((Component)cardSpots.transform.GetChild(3).GetChild(0)).gameObject, destroyAfter: true)));
			hand[3] = -1;
		}
		if (removeCard5)
		{
			Log("Removing Card 5", Preferences.debugging.Value);
			cardsRemoving.Add(MelonCoroutines.Start(PlayCardShrinkCoroutine(((Component)cardSpots.transform.GetChild(4).GetChild(0)).gameObject, destroyAfter: true)));
			hand[4] = -1;
		}
		foreach (object item in cardsRemoving)
		{
			yield return item;
		}
		Log("RunOptionsMenu Completed", Preferences.debugging.Value);
	}

	private void ClearCardSpots()
	{
		Log("Clearing Card Spots", Preferences.debugging.Value);
		for (int i = 0; i < cardSpots.transform.GetChildCount(); i++)
		{
			for (int num = cardSpots.transform.GetChild(i).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)cardSpots.transform.GetChild(i).GetChild(num)).gameObject);
			}
		}
	}

	private void SetupOptionsMenu()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0423: Unknown result type (might be due to invalid IL or missing references)
		//IL_0437: Unknown result type (might be due to invalid IL or missing references)
		Log("SetupOptionsMenu Started", Preferences.debugging.Value);
		if ((Object)(object)storedOptionsMenu != (Object)null)
		{
			Object.Destroy((Object)(object)storedOptionsMenu);
		}
		storedOptionsMenu = new GameObject("OptionsMenu");
		storedOptionsMenu.transform.SetParent(storedGamePartsTransform);
		storedOptionsMenu.transform.localPosition = Vector3.zero;
		storedOptionsMenu.transform.localRotation = Quaternion.identity;
		storedOptionsMenu.transform.localScale = Vector3.one;
		GameObject val = tableInstance.SpawnButton(storedOptionsMenu.transform, "Card1", new Vector3(0.2456f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		val.transform.GetChild(1).localPosition = new Vector3(0f, 0f, -0.2f);
		TextMeshPro component = ((Component)val.transform.GetChild(1)).GetComponent<TextMeshPro>();
		((TMP_Text)component).fontSize = 0.75f;
		((TMP_Text)component).text = "Remove";
		val = tableInstance.SpawnButton(storedOptionsMenu.transform, "Card2", new Vector3(0.1228f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		val.transform.GetChild(1).localPosition = new Vector3(0f, 0f, -0.2f);
		component = ((Component)val.transform.GetChild(1)).GetComponent<TextMeshPro>();
		((TMP_Text)component).fontSize = 0.75f;
		((TMP_Text)component).text = "Remove";
		val = tableInstance.SpawnButton(storedOptionsMenu.transform, "Card3", new Vector3(0f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		val.transform.GetChild(1).localPosition = new Vector3(0f, 0f, -0.2f);
		component = ((Component)val.transform.GetChild(1)).GetComponent<TextMeshPro>();
		((TMP_Text)component).fontSize = 0.75f;
		((TMP_Text)component).text = "Remove";
		val = tableInstance.SpawnButton(storedOptionsMenu.transform, "Card4", new Vector3(-0.1228f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		val.transform.GetChild(1).localPosition = new Vector3(0f, 0f, -0.2f);
		component = ((Component)val.transform.GetChild(1)).GetComponent<TextMeshPro>();
		((TMP_Text)component).fontSize = 0.75f;
		((TMP_Text)component).text = "Remove";
		val = tableInstance.SpawnButton(storedOptionsMenu.transform, "Card5", new Vector3(-0.2456f, 0f, 0.8f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		val.transform.GetChild(1).localPosition = new Vector3(0f, 0f, -0.2f);
		component = ((Component)val.transform.GetChild(1)).GetComponent<TextMeshPro>();
		((TMP_Text)component).fontSize = 0.75f;
		((TMP_Text)component).text = "Remove";
		tableInstance.SpawnButton(storedOptionsMenu.transform, "Continue", new Vector3(-0.43f, 0f, 0.86f), Quaternion.Euler(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f));
		Log("SetupOptionsMenu Completed", Preferences.debugging.Value);
	}

	private void UpdateBetAmountText()
	{
		((TMP_Text)betTextComponent).text = betAmount + " of " + Main.GetPlayerCoinCount();
	}
}
public static class BuildInfo
{
	public const string ModName = "GamblingMod";

	public const string ModVersion = "2.3.1";

	public const string Author = "UlvakSkillz";
}
[HarmonyPatch(typeof(PlayerPoseSystem), "OnPoseSetCompleted", new Type[] { typeof(PoseSet) })]
public static class PosePatch
{
	private static void Postfix(PoseSet set)
	{
		Main.posesCompleted++;
		if (Main.posesCompleted >= 100)
		{
			Main.posesCompleted -= 100;
			Main.Payout(1, 1f);
			Main.Log("Player Earned 1 Coin from Completing 100 Poses");
		}
	}
}
public class Main : MelonMod
{
	private static Instance logger;

	public static MelonMod melonMod;

	private static int playerCoins = -1;

	public static int posesCompleted = -1;

	private static bool flatLandFound = false;

	private static bool voidLandFound = false;

	public static List<Table> tableList = new List<Table>();

	public static List<SlotMachine> slotsList = new List<SlotMachine>();

	public GameObject rumbleTextObject;

	public static string currentScene = "Loader";

	private static GameObject storedTable;

	private static GameObject storedSlots;

	private bool finishedGymSetup;

	private Material spinnerMaterial;

	private static Shader URPLit;

	public static List<AudioCall> storedAudioCalls = new List<AudioCall>();

	public static void Log(string msg, bool sendMsg = true)
	{
		if (sendMsg)
		{
			logger.Msg(msg);
		}
	}

	public static void Warn(string msg, bool sendMsg = true)
	{
		if (sendMsg)
		{
			logger.Warning(msg);
		}
	}

	public static void Error(string msg)
	{
		logger.Error(msg);
	}

	public override void OnInitializeMelon()
	{
		Preferences.InitPrefs();
		((ModModelBase)UI.RegisterMelon((MelonBase)(object)this, (MelonPreferences_Category[])(object)new MelonPreferences_Category[1] { Preferences.GamblingModCategory })).OnModSaved += Save;
	}

	public override void OnLateInitializeMelon()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		URPLit = Shader.Find("Universal Render Pipeline/Lit");
		logger = ((MelonBase)this).LoggerInstance;
		melonMod = (MelonMod)(object)this;
		Lighting.UseBounceLighting(true);
		Lighting.SetHorizonLightColor((Color?)new Color(0.5f, 0.5f, 0.55f));
		Lighting.SetGroundLightColor((Color?)new Color(0.35f, 0.35f, 0.42f));
		Log("OnLateInitializeMelon Started", Preferences.debugging.Value);
		LoadSaveFile();
		LoadAssetBundle();
		MelonCoroutines.Start(GrabRumbleTextObject());
		Log("OnLateInitializeMelon Completed", Preferences.debugging.Value);
		Actions.onMapInitialized += MapLoaded;
	}

	private void LoadSaveFile()
	{
		Log("LoadSaveFile Started", Preferences.debugging.Value);
		if (!Directory.Exists("UserData\\GamblingMod"))
		{
			Directory.CreateDirectory("UserData\\GamblingMod");
		}
		if (!File.Exists("UserData\\GamblingMod\\Save.save"))
		{
			EncryptStringToFile("0|0", "UserData\\GamblingMod\\Save.save", "UlvakSkillz");
		}
		try
		{
			string text = DecryptStringFromFile("UserData\\GamblingMod\\Save.save", "UlvakSkillz");
			Log("Save.save File Text: " + text, Preferences.debugging.Value);
			string[] array = text.Split("|");
			playerCoins = int.Parse(array[0]);
			Log("Loaded Player Coins: " + playerCoins);
			posesCompleted = int.Parse(array[1]);
			Log("Loaded Poses Completed: " + posesCompleted);
		}
		catch (Exception ex)
		{
			Error("Error Loading Save File:");
			Error(ex.Message);
			if (playerCoins == -1)
			{
				Log("Failed to Load Player Coins, Setting to 0");
				playerCoins = 0;
			}
			if (posesCompleted == -1)
			{
				Log("Failed to Load Poses Completed Count, Setting to 0");
				posesCompleted = 0;
			}
		}
		Log("LoadSaveFile Completed", Preferences.debugging.Value);
	}

	private void LoadAssetBundle()
	{
		Log("LoadAssetBundle Started", Preferences.debugging.Value);
		GameObject val = Object.Instantiate<GameObject>(AssetBundles.LoadAssetFromStream<GameObject>((MelonMod)(object)this, "GamblingMod.gambling", "Spinner"));
		spinnerMaterial = ((Renderer)val.GetComponent<MeshRenderer>()).material;
		Object.DontDestroyOnLoad((Object)(object)val);
		((Object)val).name = "Gambling Mod Matierial Storage";
		val.SetActive(false);
		GameObject val2 = Object.Instantiate<GameObject>(AssetBundles.LoadAssetFromStream<GameObject>((MelonMod)(object)this, "GamblingMod.gambling", "Poker"));
		storedTable = ((Component)val2.transform.GetChild(0)).gameObject;
		storedSlots = ((Component)val2.transform.GetChild(1)).gameObject;
		((Object)storedTable).name = "PokerTable";
		((Object)storedSlots).name = "SlotMachine";
		storedTable.transform.SetParent((Transform)null);
		storedSlots.transform.SetParent((Transform)null);
		storedTable.SetActive(false);
		storedSlots.SetActive(false);
		Object.DontDestroyOnLoad((Object)(object)storedTable);
		Object.DontDestroyOnLoad((Object)(object)storedSlots);
		finishedGymSetup = false;