Decompiled source of BigWalkTexasHoldem v1.0.1

plugins/BigWalkTexasHoldem.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TexasHoldemMod
{
	internal static class HandEvaluator
	{
		internal enum Category
		{
			HighCard,
			OnePair,
			TwoPair,
			ThreeKind,
			Straight,
			Flush,
			FullHouse,
			FourKind,
			StraightFlush
		}

		internal struct Result
		{
			public Category category;

			public int[] kickers;

			public string nameZh;

			public string nameEn;

			public bool royal;
		}

		private static readonly string[] NamesZh = new string[9] { "高牌", "一对", "两对", "三条", "顺子", "同花", "葫芦", "四条", "同花顺" };

		private static readonly string[] NamesEn = new string[9] { "High Card", "One Pair", "Two Pair", "Three of a Kind", "Straight", "Flush", "Full House", "Four of a Kind", "Straight Flush" };

		private static int Rank(string card)
		{
			string text = card.Substring(0, card.Length - 1);
			switch (text)
			{
			case "J":
				return 11;
			case "Q":
				return 12;
			case "K":
				return 13;
			case "A":
				return 14;
			default:
			{
				if (!int.TryParse(text, out var result))
				{
					return 0;
				}
				return result;
			}
			}
		}

		private static string Suit(string card)
		{
			return card.Substring(card.Length - 1);
		}

		internal static int Compare(Result a, Result b)
		{
			if (a.category != b.category)
			{
				return a.category.CompareTo(b.category);
			}
			int num = Math.Min(a.kickers.Length, b.kickers.Length);
			for (int i = 0; i < num; i++)
			{
				if (a.kickers[i] != b.kickers[i])
				{
					return a.kickers[i].CompareTo(b.kickers[i]);
				}
			}
			return 0;
		}

		internal static Result Evaluate(List<string> cards)
		{
			Result result = new Result
			{
				category = Category.HighCard,
				kickers = new int[0]
			};
			if (cards == null || cards.Count < 5)
			{
				return result;
			}
			int count = cards.Count;
			for (int i = 0; i < count - 4; i++)
			{
				for (int j = i + 1; j < count - 3; j++)
				{
					for (int k = j + 1; k < count - 2; k++)
					{
						for (int l = k + 1; l < count - 1; l++)
						{
							for (int m = l + 1; m < count; m++)
							{
								Result result2 = Eval5(new List<string>
								{
									cards[i],
									cards[j],
									cards[k],
									cards[l],
									cards[m]
								});
								if (Compare(result2, result) > 0)
								{
									result = result2;
								}
							}
						}
					}
				}
			}
			result.nameZh = NamesZh[(int)result.category];
			result.nameEn = NamesEn[(int)result.category];
			if (result.category == Category.StraightFlush && result.kickers.Length != 0 && result.kickers[0] == 14)
			{
				result.royal = true;
				result.nameZh = "皇家同花顺";
				result.nameEn = "Royal Flush";
			}
			return result;
		}

		private static Result Eval5(List<string> five)
		{
			int[] array = new int[5];
			string[] array2 = new string[5];
			for (int i = 0; i < 5; i++)
			{
				array[i] = Rank(five[i]);
				array2[i] = Suit(five[i]);
			}
			Array.Sort(array);
			Array.Reverse(array);
			bool flag = true;
			for (int j = 1; j < 5; j++)
			{
				if (array2[j] != array2[0])
				{
					flag = false;
					break;
				}
			}
			bool flag2 = false;
			int num = 0;
			int[] array3 = UniqueDesc(array);
			if (array3.Length == 5)
			{
				if (array3[0] - array3[4] == 4)
				{
					flag2 = true;
					num = array3[0];
				}
				else if (array3[0] == 14 && array3[1] == 5 && array3[2] == 4 && array3[3] == 3 && array3[4] == 2)
				{
					flag2 = true;
					num = 5;
				}
			}
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			for (int k = 0; k < 5; k++)
			{
				int key = array[k];
				if (!dictionary.ContainsKey(key))
				{
					dictionary[key] = 0;
				}
				dictionary[key]++;
			}
			List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>(dictionary);
			list.Sort(delegate(KeyValuePair<int, int> x, KeyValuePair<int, int> y)
			{
				int num4 = y.Value.CompareTo(x.Value);
				return (num4 == 0) ? y.Key.CompareTo(x.Key) : num4;
			});
			Category category;
			int[] kickers;
			if (flag2 && flag)
			{
				category = Category.StraightFlush;
				kickers = new int[1] { num };
			}
			else if (list[0].Value == 4)
			{
				category = Category.FourKind;
				kickers = new int[2]
				{
					list[0].Key,
					list[1].Key
				};
			}
			else if (list[0].Value == 3 && list[1].Value == 2)
			{
				category = Category.FullHouse;
				kickers = new int[2]
				{
					list[0].Key,
					list[1].Key
				};
			}
			else if (flag)
			{
				category = Category.Flush;
				kickers = (int[])array.Clone();
			}
			else if (flag2)
			{
				category = Category.Straight;
				kickers = new int[1] { num };
			}
			else if (list[0].Value == 3)
			{
				category = Category.ThreeKind;
				kickers = new int[3]
				{
					list[0].Key,
					list[1].Key,
					list[2].Key
				};
			}
			else if (list[0].Value == 2 && list[1].Value == 2)
			{
				category = Category.TwoPair;
				int num2 = Math.Max(list[0].Key, list[1].Key);
				int num3 = Math.Min(list[0].Key, list[1].Key);
				int key2 = list[2].Key;
				kickers = new int[3] { num2, num3, key2 };
			}
			else if (list[0].Value == 2)
			{
				category = Category.OnePair;
				int key3 = list[0].Key;
				int[] array4 = new int[3]
				{
					list[1].Key,
					list[2].Key,
					list[3].Key
				};
				kickers = new int[4]
				{
					key3,
					array4[0],
					array4[1],
					array4[2]
				};
			}
			else
			{
				category = Category.HighCard;
				kickers = (int[])array.Clone();
			}
			return new Result
			{
				category = category,
				kickers = kickers
			};
		}

		private static int[] UniqueDesc(int[] arr)
		{
			List<int> list = new List<int>();
			for (int i = 0; i < arr.Length; i++)
			{
				if (!list.Contains(arr[i]))
				{
					list.Add(arr[i]);
				}
			}
			return list.ToArray();
		}
	}
	internal static class I18n
	{
		private static ConfigEntry<bool> _english;

		internal static bool IsEnglish
		{
			get
			{
				if (_english != null)
				{
					return _english.Value;
				}
				return false;
			}
		}

		internal static string ButtonLabel
		{
			get
			{
				if (!IsEnglish)
				{
					return "EN";
				}
				return "中文";
			}
		}

		internal static string CurrentLabel
		{
			get
			{
				if (!IsEnglish)
				{
					return "中文";
				}
				return "English";
			}
		}

		internal static void Init(ConfigFile config)
		{
			if (_english == null)
			{
				_english = config.Bind<bool>("界面/UI", "English", false, "界面语言:false=中文,true=English。也可用烟花菜单的「中/EN」按钮实时切换。");
			}
		}

		internal static string T(string zh, string en)
		{
			if (!IsEnglish)
			{
				return zh;
			}
			return en;
		}

		internal static bool Toggle()
		{
			if (_english == null)
			{
				return false;
			}
			_english.Value = !_english.Value;
			return _english.Value;
		}
	}
	[HarmonyPatch(typeof(TextChatSource), "AddMessage")]
	internal static class TexasChatPatch
	{
		private static string _last;

		private static float _lastAt;

		private static void Prefix(TextChatMessage message)
		{
			try
			{
				string text = null;
				PlayerCharacter val = null;
				try
				{
					text = message.message;
					val = message.sendingPlayer;
				}
				catch
				{
				}
				if (!string.IsNullOrEmpty(text))
				{
					string text2 = (((Object)(object)val != (Object)null) ? ((Object)val).GetInstanceID().ToString() : "0") + "|" + text;
					if (!(text2 == _last) || !(Time.unscaledTime - _lastAt < 0.3f))
					{
						_last = text2;
						_lastAt = Time.unscaledTime;
						TexasTool.OnChat(val, text);
					}
				}
			}
			catch
			{
			}
		}
	}
	[BepInPlugin("plx.bigwalk.texas", "BigWalkTexasHoldem", "1.0.0")]
	public sealed class TexasPlugin : BasePlugin
	{
		public sealed class TexasBehaviour : MonoBehaviour
		{
			public TexasBehaviour(IntPtr ptr)
				: base(ptr)
			{
			}

			public TexasBehaviour()
				: base(ClassInjector.DerivedConstructorPointer<TexasBehaviour>())
			{
				ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
			}

			private void Update()
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (Input.GetKeyDown(MenuKey.Value))
					{
						TexasUI.Toggle();
					}
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("Update异常:" + ex.GetBaseException().Message));
				}
			}

			private void OnGUI()
			{
				TexasUI.Draw();
			}
		}

		internal static ManualLogSource Log;

		internal static ConfigEntry<KeyCode> MenuKey;

		public override void Load()
		{
			//IL_0087: 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_0092: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BasePlugin)this).Log;
			Log.LogInfo((object)"德州扑克mod 加载中 v1.0.0(中英双语,照斗地主原理)");
			I18n.Init(((BasePlugin)this).Config);
			TexProbe.Create();
			MenuKey = ((BasePlugin)this).Config.Bind<KeyCode>("按键", "打开菜单", (KeyCode)286, "打开/关闭德州扑克菜单(默认 F5)");
			TexasTool.Install(Log, ((BasePlugin)this).Config, () => FindLocal());
			ClassInjector.RegisterTypeInIl2Cpp<TexasBehaviour>();
			GameObject val = new GameObject("BigWalkTexasHoldem");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<TexasBehaviour>();
			Log.LogInfo((object)("德州扑克mod 加载完成:" + ((object)MenuKey.Value/*cast due to .constrained prefix*/).ToString() + "=菜单"));
		}

		private static PlayerCharacter FindLocal()
		{
			try
			{
				List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
				if (allPlayerCharacters == null)
				{
					return null;
				}
				for (int i = 0; i < allPlayerCharacters.Count; i++)
				{
					PlayerCharacter val = allPlayerCharacters[i];
					if (!((Object)(object)val == (Object)null) && (Object)(object)val.playerNetworking != (Object)null && ((NetworkBehaviour)val.playerNetworking).isLocalPlayer)
					{
						return val;
					}
				}
			}
			catch
			{
			}
			return null;
		}
	}
	internal static class TexasTool
	{
		private enum Phase
		{
			Idle,
			Deal,
			Flop,
			Turn,
			River,
			Showdown,
			Over
		}

		private struct Seat
		{
			public Prop sign;

			public PlayerCharacter player;

			public string card1;

			public string card2;

			public int chips;

			public bool folded;

			public int contributed;

			public HandEvaluator.Result best;
		}

		private static readonly string[] Ranks = new string[13]
		{
			"2", "3", "4", "5", "6", "7", "8", "9", "10", "J",
			"Q", "K", "A"
		};

		private static readonly string[] Suits = new string[4] { "♠", "♥", "♦", "♣" };

		private static ManualLogSource Log;

		private static Func<PlayerCharacter> _local;

		private static ConfigFile _cfg;

		internal static ConfigEntry<int> PlayerCountEntry;

		internal static ConfigEntry<int> AnteEntry;

		internal static ConfigEntry<bool> HostModeEntry;

		private static readonly List<Seat> _seats = new List<Seat>();

		private static readonly List<string> _board = new List<string>();

		private static readonly List<string> _deck = new List<string>();

		private static Phase _phase = Phase.Idle;

		private static int _pot;

		private static int _dealer;

		private static bool _logicHost;

		internal static string Status = "";

		internal static bool IsRunning
		{
			get
			{
				if (_seats.Count > 0 && _phase != Phase.Idle)
				{
					return _phase != Phase.Over;
				}
				return false;
			}
		}

		internal static void Install(ManualLogSource log, ConfigFile cfg, Func<PlayerCharacter> local)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			Log = log;
			_cfg = cfg;
			_local = local;
			PlayerCountEntry = cfg.Bind<int>("德州扑克", "人数", 3, "2-8人");
			AnteEntry = cfg.Bind<int>("德州扑克", "底注", 10, "每人每轮底注");
			HostModeEntry = cfg.Bind<bool>("德州扑克", "房主模式", true, "开=写牌走服务器所有人可见;关=客户端改字");
			try
			{
				new Harmony("plx.bigwalk.texas.chat").PatchAll(typeof(TexasChatPatch));
				Log.LogInfo((object)"[德州扑克] 聊天补丁安装成功");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[德州扑克] 聊天补丁安装失败:" + ex.GetBaseException().Message));
			}
			Status = I18n.T("就绪:每人拿一块指示牌,房主点发牌", "Ready: each player holds a sign, host deals");
			Log.LogInfo((object)("[德州扑克] " + Status));
		}

		internal static void StartGame()
		{
			_logicHost = NetworkServer.active || HostModeEntry.Value;
			Status = I18n.T("发牌中…", "Dealing...");
			_seats.Clear();
			_board.Clear();
			List<Seat> list = FindSignHolders();
			int num = Mathf.Clamp(PlayerCountEntry.Value, 2, 8);
			if (list.Count < num)
			{
				Status = I18n.T("需要", "Need ") + num + I18n.T(" 人各拿一块指示牌(当前", " sign holders (now ") + list.Count + ")";
				Log.LogInfo((object)("[德州扑克] " + Status));
				return;
			}
			for (int i = 0; i < num; i++)
			{
				Seat item = list[i];
				item.card1 = "";
				item.card2 = "";
				item.chips = 100;
				item.folded = false;
				item.contributed = 0;
				item.best = default(HandEvaluator.Result);
				_seats.Add(item);
			}
			_deck.Clear();
			for (int j = 0; j < Ranks.Length; j++)
			{
				for (int k = 0; k < Suits.Length; k++)
				{
					_deck.Add(Ranks[j] + Suits[k]);
				}
			}
			Shuffle(_deck);
			int num2 = 0;
			for (int l = 0; l < _seats.Count; l++)
			{
				Seat value = _seats[l];
				value.card1 = _deck[num2++];
				value.card2 = _deck[num2++];
				value.chips -= AnteEntry.Value;
				value.contributed = AnteEntry.Value;
				_seats[l] = value;
			}
			_pot = AnteEntry.Value * _seats.Count;
			_dealer = 0;
			_phase = Phase.Flop;
			Status = I18n.T("发牌完成:2张底牌已发,聊天输入「要」跟注/「不要」弃牌,然后翻牌", "Dealt: 2 hole cards. Chat 要=call / 不要=fold, then Flop");
			RefreshSigns();
			Log.LogInfo((object)("[德州扑克] 发牌完成 " + _seats.Count + " 人,底池=" + _pot));
		}

		internal static void Flop()
		{
			if (IsRunning && _phase == Phase.Flop)
			{
				int num = _seats.Count * 2;
				for (int i = 0; i < 3; i++)
				{
					_board.Add(_deck[num++]);
				}
				_phase = Phase.Turn;
				Status = I18n.T("翻牌:", "Flop: ") + Join(_board) + I18n.T("|要=跟注 不要=弃牌", " | call/fold");
				RefreshSigns();
			}
		}

		internal static void Turn()
		{
			if (IsRunning && _phase == Phase.Turn)
			{
				int index = _seats.Count * 2 + 3;
				_board.Add(_deck[index]);
				_phase = Phase.River;
				Status = I18n.T("转牌:", "Turn: ") + Join(_board);
				RefreshSigns();
			}
		}

		internal static void River()
		{
			if (IsRunning && _phase == Phase.River)
			{
				int index = _seats.Count * 2 + 4;
				_board.Add(_deck[index]);
				_phase = Phase.Showdown;
				Showdown();
			}
		}

		private static void Showdown()
		{
			int num = -1;
			HandEvaluator.Result b = default(HandEvaluator.Result);
			List<string> collection = new List<string>(_board);
			for (int i = 0; i < _seats.Count; i++)
			{
				Seat value = _seats[i];
				if (!value.folded)
				{
					List<string> cards = new List<string>(collection) { value.card1, value.card2 };
					value.best = HandEvaluator.Evaluate(cards);
					_seats[i] = value;
					if (num < 0 || HandEvaluator.Compare(value.best, b) > 0)
					{
						num = i;
						b = value.best;
					}
				}
			}
			if (num >= 0)
			{
				Seat value2 = _seats[num];
				value2.chips += _pot;
				_seats[num] = value2;
				Status = SeatName(num) + I18n.T(" 获胜:", " wins: ") + b.nameZh + " (" + b.nameEn + ")";
			}
			else
			{
				Status = I18n.T("无人摊牌(都弃牌了)", "Showdown skipped (all folded)");
			}
			_phase = Phase.Over;
			RefreshSigns(showdown: true);
			Log.LogInfo((object)("[德州扑克] " + Status));
		}

		internal static void OnChat(PlayerCharacter sender, string text)
		{
			if (!IsRunning || string.IsNullOrEmpty(text))
			{
				return;
			}
			string text2 = text.Trim().ToLowerInvariant();
			int num = FindSeat(sender);
			if (num < 0)
			{
				return;
			}
			switch (text2)
			{
			default:
				return;
			case "要":
			case "call":
			case "yes":
			{
				Seat value3 = _seats[num];
				if (value3.folded)
				{
					return;
				}
				int num4 = Math.Max(AnteEntry.Value, 10);
				value3.chips -= num4;
				value3.contributed += num4;
				_pot += num4;
				_seats[num] = value3;
				Status = SeatName(num) + I18n.T(" 跟注 ", " calls ") + num4 + I18n.T(",底池=", ", pot=") + _pot;
				break;
			}
			case "不要":
			case "fold":
			case "no":
			{
				Seat value = _seats[num];
				value.folded = true;
				_seats[num] = value;
				Status = SeatName(num) + I18n.T(" 弃牌", " folds");
				int num2 = 0;
				int num3 = -1;
				for (int i = 0; i < _seats.Count; i++)
				{
					if (!_seats[i].folded)
					{
						num2++;
						num3 = i;
					}
				}
				if (num2 <= 1 && num3 >= 0)
				{
					Seat value2 = _seats[num3];
					value2.chips += _pot;
					_seats[num3] = value2;
					Status = SeatName(num3) + I18n.T(" 获胜(其他人弃牌),底池=", " wins (all folded), pot=") + _pot;
					_phase = Phase.Over;
				}
				break;
			}
			}
			RefreshSigns();
			Log.LogInfo((object)("[德州扑克] " + Status));
		}

		private static int FindSeat(PlayerCharacter pc)
		{
			if ((Object)(object)pc == (Object)null)
			{
				return -1;
			}
			for (int i = 0; i < _seats.Count; i++)
			{
				if ((Object)(object)_seats[i].player == (Object)(object)pc)
				{
					return i;
				}
			}
			return -1;
		}

		private static void RefreshSigns(bool showdown = false)
		{
			for (int i = 0; i < _seats.Count; i++)
			{
				Seat seat = _seats[i];
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine(I18n.T("德州扑克", "Texas Hold'em"));
				stringBuilder.AppendLine(I18n.T("底牌:", "Hole:") + " " + seat.card1 + " " + seat.card2);
				if (_board.Count > 0)
				{
					stringBuilder.AppendLine(I18n.T("公共:", "Board:") + " " + Join(_board));
				}
				stringBuilder.AppendLine(I18n.T("筹码:", "Chips:") + " " + seat.chips + "  " + I18n.T("本轮:", "Bet:") + seat.contributed);
				stringBuilder.AppendLine(I18n.T("底池:", "Pot:") + " " + _pot);
				if (seat.folded)
				{
					stringBuilder.AppendLine(I18n.T("已弃牌", "FOLDED"));
				}
				else if (showdown && seat.best.kickers != null)
				{
					stringBuilder.AppendLine(I18n.T("牌型:", "Hand:") + " " + seat.best.nameZh + "/" + seat.best.nameEn);
				}
				else
				{
					stringBuilder.AppendLine(I18n.T("要=跟注 不要=弃牌", "要=call 不要=fold"));
				}
				WriteSign(seat.sign, stringBuilder.ToString());
			}
		}

		private static string SeatName(int i)
		{
			if (i < 0 || i >= _seats.Count)
			{
				return "?";
			}
			try
			{
				PlayerCharacter player = _seats[i].player;
				if ((Object)(object)player != (Object)null && (Object)(object)player.playerNetworking != (Object)null)
				{
					string text = player.playerNetworking.username;
					if (string.IsNullOrEmpty(text))
					{
						text = player.playerNetworking.Networkusername;
					}
					if (!string.IsNullOrEmpty(text))
					{
						return text;
					}
				}
			}
			catch
			{
			}
			return I18n.T("玩家", "Player") + (i + 1);
		}

		private static List<Seat> FindSignHolders()
		{
			List<Seat> list = new List<Seat>();
			try
			{
				Il2CppArrayBase<Prop> val = Object.FindObjectsOfType<Prop>();
				if (val == null)
				{
					return list;
				}
				for (int i = 0; i < val.Length; i++)
				{
					Prop val2 = val[i];
					if ((Object)(object)val2 == (Object)null || (Object)(object)((Component)val2).gameObject == (Object)null)
					{
						continue;
					}
					string name = ((Object)((Component)val2).gameObject).name;
					if (string.IsNullOrEmpty(name))
					{
						continue;
					}
					string text = name.ToLowerInvariant();
					if (text.Contains("signprop") && !text.Contains("permo"))
					{
						PlayerCharacter val3 = null;
						try
						{
							val3 = val2.exclusiveHolder;
						}
						catch
						{
						}
						if ((Object)(object)val3 != (Object)null)
						{
							list.Add(new Seat
							{
								sign = val2,
								player = val3
							});
						}
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[德州扑克] 找指示牌异常:" + ex.GetBaseException().Message));
			}
			return list;
		}

		private static void WriteSign(Prop sign, string text)
		{
			if ((Object)(object)sign == (Object)null || (Object)(object)((Component)sign).gameObject == (Object)null)
			{
				return;
			}
			try
			{
				PeckEffectTextInput component = ((Component)sign).GetComponent<PeckEffectTextInput>();
				if ((Object)(object)component != (Object)null)
				{
					string text2 = text ?? "";
					if (NetworkServer.active || _logicHost)
					{
						component.ServerSetText(text2, "德州扑克");
					}
					else
					{
						component.CmdSendNewText(text2, (NetworkConnectionToClient)null);
					}
				}
				else
				{
					Log.LogInfo((object)("[德州扑克] 指示牌无PeckEffectTextInput:" + ((Object)((Component)sign).gameObject).name));
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[德州扑克] 写牌异常:" + ex.GetBaseException().Message));
			}
		}

		private static void Shuffle(List<string> d)
		{
			for (int num = d.Count - 1; num > 0; num--)
			{
				int index = Random.Range(0, num + 1);
				string value = d[num];
				d[num] = d[index];
				d[index] = value;
			}
		}

		private static string Join(List<string> cards)
		{
			return string.Join(" ", cards.ToArray());
		}

		internal static void EndGame()
		{
			_seats.Clear();
			_board.Clear();
			_phase = Phase.Idle;
			_pot = 0;
			Status = I18n.T("已结束", "Ended");
			Log.LogInfo((object)"[德州扑克] 已结束");
		}
	}
	internal static class TexasUI
	{
		internal static bool Open;

		private static Rect _rect = new Rect(0f, 0f, 560f, 440f);

		private static bool _inited;

		private static GUIStyle _title;

		private static GUIStyle _label;

		private static GUIStyle _dim;

		private static readonly Color PanelBg = new Color(0.07f, 0.125f, 0.255f, 0.97f);

		private static readonly Color PanelEdge = new Color(0.56f, 0.79f, 1f, 0.7f);

		private static readonly Color TextCol = new Color(0.855f, 0.914f, 1f);

		private static readonly Color BtnBlue = new Color(0.6f, 0.79f, 0.98f);

		private static void Init()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			if (!_inited)
			{
				_inited = true;
				((Rect)(ref _rect)).x = ((float)Screen.width - ((Rect)(ref _rect)).width) * 0.5f;
				((Rect)(ref _rect)).y = ((float)Screen.height - ((Rect)(ref _rect)).height) * 0.5f;
				_title = new GUIStyle(GUI.skin.label)
				{
					fontSize = 18,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				_label = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14
				};
				_dim = new GUIStyle(GUI.skin.label)
				{
					fontSize = 12
				};
			}
		}

		internal static void Toggle()
		{
			Open = !Open;
			if (Open)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			else
			{
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
			}
		}

		internal static void Draw()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			if (!Open)
			{
				return;
			}
			try
			{
				Init();
				TexProbe.DrawOnce();
				Color contentColor = GUI.contentColor;
				GUI.contentColor = TextCol;
				DrawGlass(_rect);
				float num = 16f;
				float num2 = ((Rect)(ref _rect)).x + num;
				float num3 = ((Rect)(ref _rect)).width - num * 2f;
				float num4 = ((Rect)(ref _rect)).y + 12f;
				GUI.Label(new Rect(num2, num4, num3 - 120f, 26f), I18n.T("德州扑克", "Texas Hold'em"), _title);
				if (Btn(new Rect(((Rect)(ref _rect)).xMax - 110f, ((Rect)(ref _rect)).y + 8f, 46f, 24f), I18n.ButtonLabel))
				{
					I18n.Toggle();
				}
				if (Btn(new Rect(((Rect)(ref _rect)).xMax - 58f, ((Rect)(ref _rect)).y + 8f, 34f, 24f), "×"))
				{
					Toggle();
					GUI.contentColor = contentColor;
					return;
				}
				num4 += 32f;
				GUI.Label(new Rect(num2, num4, num3, 40f), I18n.T("状态:", "Status: ") + TexasTool.Status, _label);
				num4 += 44f;
				if (Btn(new Rect(num2, num4, num3, 34f), I18n.T("发牌(每人2张底牌)", "Deal (2 hole cards each)")))
				{
					TexasTool.StartGame();
				}
				num4 += 40f;
				if (Btn(new Rect(num2, num4, num3 / 2f - 4f, 32f), I18n.T("翻牌(3张)", "Flop (3)")))
				{
					TexasTool.Flop();
				}
				if (Btn(new Rect(num2 + num3 / 2f + 4f, num4, num3 / 2f - 4f, 32f), I18n.T("转牌(1张)", "Turn (1)")))
				{
					TexasTool.Turn();
				}
				num4 += 38f;
				if (Btn(new Rect(num2, num4, num3 / 2f - 4f, 32f), I18n.T("河牌+摊牌", "River + Showdown")))
				{
					TexasTool.River();
				}
				if (Btn(new Rect(num2 + num3 / 2f + 4f, num4, num3 / 2f - 4f, 32f), I18n.T("结束", "End")))
				{
					TexasTool.EndGame();
				}
				num4 += 42f;
				GUI.Label(new Rect(num2, num4, num3, 20f), I18n.T("聊天输入:要=跟注 / 不要=弃牌", "Chat: 要=call / 不要=fold"), _dim);
				num4 += 20f;
				GUI.Label(new Rect(num2, num4, num3, 20f), I18n.T("每人一块指示牌显示底牌/公共牌/筹码", "Each sign shows hole/board/chips"), _dim);
				num4 += 20f;
				GUI.Label(new Rect(num2, num4, num3, 20f), I18n.T("热键:F5 菜单", "Key: F5 menu"), _dim);
				GUI.contentColor = contentColor;
			}
			catch (Exception ex)
			{
				if (TexasPlugin.Log != null)
				{
					TexasPlugin.Log.LogWarning((object)("菜单绘制异常:" + ex.GetBaseException().Message));
				}
			}
		}

		private static bool Btn(Rect r, string s)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = BtnBlue;
			bool result = GUI.Button(r, s);
			GUI.backgroundColor = backgroundColor;
			return result;
		}

		private static void DrawGlass(Rect r)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_00d5: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			TexProbe.Round(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 7f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), new Color(0f, 0f, 0f, 0.3f), 25);
			TexProbe.Round(new Rect(((Rect)(ref r)).x + 1f, ((Rect)(ref r)).y + 3f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), new Color(0f, 0f, 0f, 0.2f), 23);
			Rect r2 = default(Rect);
			((Rect)(ref r2))..ctor(((Rect)(ref r)).x + 1.5f, ((Rect)(ref r)).y + 1.5f, ((Rect)(ref r)).width - 3f, ((Rect)(ref r)).height - 3f);
			TexProbe.Round(r, PanelEdge, 22);
			TexProbe.Round(r2, PanelBg, 20);
			TexProbe.Fill(new Rect(((Rect)(ref r2)).x + 12f, ((Rect)(ref r2)).y + 2f, ((Rect)(ref r2)).width - 24f, 30f), new Color(0.86f, 0.95f, 1f, 0.05f));
		}
	}
	internal static class TexProbe
	{
		internal const int CornerSize = 22;

		private static Texture2D _tex;

		private static Texture2D[] _corner;

		private static int _state;

		private static int _rebuilt;

		internal static bool Usable => _state == 1;

		internal static bool Failed => _state == 2;

		internal static void Create()
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Texture2D val = new Texture2D(4, 4, (TextureFormat)4, false);
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(1f, 1f, 1f, 1f);
				for (int i = 0; i < 4; i++)
				{
					for (int j = 0; j < 4; j++)
					{
						val.SetPixel(j, i, val2);
					}
				}
				val.Apply(false, false);
				_tex = val;
				BuildCorners();
				TexasPlugin.Log.LogInfo((object)("[自检] Texture2D 创建成功(4x4 + 4 个圆角遮罩 " + 22 + "x" + 22 + "),准备试画一帧"));
			}
			catch (Exception ex)
			{
				_state = 2;
				TexasPlugin.Log.LogWarning((object)("[自检] Texture2D 创建失败:" + ex.GetBaseException().Message));
			}
		}

		private static void BuildCorners()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			int num = 22;
			_corner = (Texture2D[])(object)new Texture2D[4];
			Vector2[] array = (Vector2[])(object)new Vector2[4]
			{
				new Vector2((float)num, (float)num),
				new Vector2(0f, (float)num),
				new Vector2((float)num, 0f),
				new Vector2(0f, 0f)
			};
			for (int i = 0; i < 4; i++)
			{
				Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
				float x = array[i].x;
				float y = array[i].y;
				for (int j = 0; j < num; j++)
				{
					for (int k = 0; k < num; k++)
					{
						float num2 = (float)k + 0.5f - x;
						float num3 = (float)j + 0.5f - y;
						float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
						float num5 = Mathf.Clamp01((float)num - 0.5f - num4);
						val.SetPixel(k, num - 1 - j, new Color(1f, 1f, 1f, num5));
					}
				}
				val.Apply(false, false);
				_corner[i] = val;
			}
		}

		private static void EnsureAlive()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			if ((!((Object)_tex != (Object)null) || _corner == null) && _rebuilt <= 3)
			{
				_rebuilt++;
				TexasPlugin.Log.LogWarning((object)("[绘制] 白纹理/圆角遮罩已失效,重建第 " + _rebuilt + " 次"));
				Create();
			}
		}

		internal static void Fill(Rect r, Color c)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			EnsureAlive();
			if ((Object)_tex == (Object)null)
			{
				return;
			}
			Color color = GUI.color;
			try
			{
				GUI.color = new Color(c.r, c.g, c.b, Mathf.Clamp01(c.a));
				GUI.DrawTexture(r, (Texture)_tex);
			}
			catch
			{
			}
			finally
			{
				GUI.color = color;
			}
		}

		internal static void Round(Rect r, Color c, int rad)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			EnsureAlive();
			if ((Object)_tex == (Object)null)
			{
				return;
			}
			if (rad <= 1)
			{
				Fill(r, c);
				return;
			}
			int num = Mathf.FloorToInt(Mathf.Min(((Rect)(ref r)).width, ((Rect)(ref r)).height) * 0.5f);
			rad = Mathf.Clamp(rad, 1, Mathf.Max(1, num));
			if (rad <= 1)
			{
				Fill(r, c);
				return;
			}
			Fill(new Rect(((Rect)(ref r)).x + (float)rad, ((Rect)(ref r)).y, ((Rect)(ref r)).width - (float)rad * 2f, ((Rect)(ref r)).height), c);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + (float)rad, (float)rad, ((Rect)(ref r)).height - (float)rad * 2f), c);
			Fill(new Rect(((Rect)(ref r)).xMax - (float)rad, ((Rect)(ref r)).y + (float)rad, (float)rad, ((Rect)(ref r)).height - (float)rad * 2f), c);
			Corner(0, new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, (float)rad, (float)rad), c);
			Corner(1, new Rect(((Rect)(ref r)).xMax - (float)rad, ((Rect)(ref r)).y, (float)rad, (float)rad), c);
			Corner(2, new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - (float)rad, (float)rad, (float)rad), c);
			Corner(3, new Rect(((Rect)(ref r)).xMax - (float)rad, ((Rect)(ref r)).yMax - (float)rad, (float)rad, (float)rad), c);
		}

		private static void Corner(int k, Rect r, Color c)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			Texture2D val = ((_corner != null && k < _corner.Length) ? _corner[k] : null);
			if ((Object)val == (Object)null)
			{
				Fill(r, c);
				return;
			}
			Color color = GUI.color;
			try
			{
				GUI.color = new Color(c.r, c.g, c.b, Mathf.Clamp01(c.a));
				GUI.DrawTexture(r, (Texture)val, (ScaleMode)0, true);
			}
			catch
			{
			}
			finally
			{
				GUI.color = color;
			}
		}

		internal static void RoundStroke(Rect r, Color rim, Color fill, int rad, float thickness)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Round(r, rim, rad);
			float num = Mathf.Max(1f, thickness);
			Round(new Rect(((Rect)(ref r)).x + num, ((Rect)(ref r)).y + num, ((Rect)(ref r)).width - num * 2f, ((Rect)(ref r)).height - num * 2f), fill, Mathf.Max(1, rad - Mathf.RoundToInt(num)));
		}

		internal static void DrawOnce()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			if (_state != 0 || (Object)_tex == (Object)null)
			{
				return;
			}
			try
			{
				GUI.DrawTexture(new Rect(0f, 0f, 4f, 4f), (Texture)_tex);
				_state = 1;
				TexasPlugin.Log.LogInfo((object)"[自检] GUI.DrawTexture 正常返回 —— 面板底色/圆角可以画了");
			}
			catch (Exception ex)
			{
				_state = 2;
				TexasPlugin.Log.LogWarning((object)("[自检] GUI.DrawTexture 失败:" + ex.GetBaseException().Message));
			}
		}
	}
}