Decompiled source of Better Chess v0.6.0

plugins/com.github.Kirshoo.BetterChess.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.Kirshoo.BetterChess")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: AssemblyInformationalVersion("0.6.0+d4b373497cc566a1dd76ecfb5a1af32a04734d3c")]
[assembly: AssemblyProduct("com.github.Kirshoo.BetterChess")]
[assembly: AssemblyTitle("BetterChess")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BetterChess
{
	internal class ChessLogic
	{
		private static ChessManager manager = ChessManager.Instance;

		private const string DefaultFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";

		private static void PlacePiece(PieceType type, bool isWhite, BoardPosition position)
		{
			string text = (isWhite ? "White" : "Black");
			manager.CreatePieceOnBoard(type, isWhite, position);
		}

		private static void PlacePawn(bool isWhite, BoardPosition position)
		{
			PlacePiece(PieceType.Pawn, isWhite, position);
		}

		private static void PlaceRook(bool isWhite, BoardPosition position)
		{
			PlacePiece(PieceType.Rook, isWhite, position);
		}

		private static void PlaceKnight(bool isWhite, BoardPosition position)
		{
			PlacePiece(PieceType.Knight, isWhite, position);
		}

		private static void PlaceBishop(bool isWhite, BoardPosition position)
		{
			PlacePiece(PieceType.Bishop, isWhite, position);
		}

		private static void PlaceQueen(bool isWhite, BoardPosition position)
		{
			PlacePiece(PieceType.Queen, isWhite, position);
		}

		private static void PlaceKing(bool isWhite, BoardPosition position)
		{
			PlacePiece(PieceType.King, isWhite, position);
		}

		private static void PlaceFENPiece(char c, BoardPosition position)
		{
			switch (c)
			{
			case 'P':
			case 'p':
				PlacePawn(c == 'P', position);
				break;
			case 'R':
			case 'r':
				PlaceRook(c == 'R', position);
				break;
			case 'N':
			case 'n':
				PlaceKnight(c == 'N', position);
				break;
			case 'B':
			case 'b':
				PlaceBishop(c == 'B', position);
				break;
			case 'K':
			case 'k':
				PlaceKing(c == 'K', position);
				break;
			case 'Q':
			case 'q':
				PlaceQueen(c == 'Q', position);
				break;
			}
		}

		public static void SetBoardStateToFEN(string fen)
		{
			string text = fen.Split(' ', 2)[0];
			string[] array = text.Split("/", 8);
			if (array.Length != 8)
			{
				Plugin.Log.LogError((object)$"[ChessLogic] Unable to load state from FEN: amount of ranks doesnt match (have {array.Length} want {8})");
				return;
			}
			int num = 0;
			foreach (string item in array.Reverse())
			{
				int num2 = 0;
				string text2 = item;
				foreach (char c in text2)
				{
					if (c >= '1' && c <= '8')
					{
						num2 += c - 49 + 1;
						continue;
					}
					PlaceFENPiece(c, new BoardPosition(num, num2));
					num2++;
				}
				num++;
			}
		}

		public static void ResetBoardPosition(string FEN)
		{
			if (string.IsNullOrEmpty(FEN))
			{
				Plugin.Log.LogWarning((object)"Attempting to use an empty FEN. Fallback to default...");
				FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
			}
			manager.RemoveAllPieces();
			SetBoardStateToFEN(FEN);
		}
	}
	public class ChessManager
	{
		private readonly HashSet<ChessPiece> pieces = new HashSet<ChessPiece>();

		private static ChessManager? _instance;

		private bool boardLoaded;

		private Vector3 boardPosition = Vector3.zero;

		private Quaternion boardRotation = Quaternion.identity;

		private Vector3 boardScale = Vector3.zero;

		private Vector3 boardOriginOffset = new Vector3(BoardPosition.HalfSize, 0f, BoardPosition.HalfSize);

		private Quaternion boardRotationCorrection = Quaternion.Euler(270f, 90f, 0f);

		public static ChessManager Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new ChessManager();
				}
				return _instance;
			}
		}

		public void Init()
		{
			MovableChessboardWrapper.Init();
			if (!MovableChessboardWrapper.enabled || !MovableChessboardWrapper.IsAvailable)
			{
				Plugin.Log.LogInfo((object)"[ChessManager] MovableChessboard mod not loaded, continue running in standalone mode");
				return;
			}
			Plugin.Log.LogInfo((object)"[ChessManager] Found MoveableChessboard! Subscribing to the events.");
			MovableChessboardWrapper.SubscirbeToBoardLoaded(OnBoardLoaded);
			MovableChessboardWrapper.SubscirbeToPositionChanged(OnBoardMoved);
			MovableChessboardWrapper.SubscirbeToRotationChanged(OnBoardRotated);
			MovableChessboardWrapper.SubscirbeToScaleChanged(OnBoardScaled);
		}

		private void OnBoardLoaded()
		{
			//IL_0001: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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)
			boardPosition = MovableChessboardWrapper.GetBoardPosition();
			boardRotation = MovableChessboardWrapper.GetBoardRotation();
			boardScale = MovableChessboardWrapper.GetBoardScale();
			Plugin.Log.LogDebug((object)$"[ChessManager] Loaded position: {boardPosition}; rotation: {boardRotation}; scale: {boardScale}");
			LoadChessSetPieces();
		}

		private void OnBoardMoved(Vector3 newPosition)
		{
			//IL_0024: 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_0030: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log.LogDebug((object)$"[ChessManager] Updating position of {pieces.Count} pieces.");
			Vector3 deltaMovement = newPosition - boardPosition;
			List<ChessPiece> list = new List<ChessPiece>();
			foreach (ChessPiece piece in pieces)
			{
				if ((Object)(object)piece.ObjectReference == (Object)null)
				{
					list.Add(piece);
					continue;
				}
				Util.ApplyBoardMovement(piece.ObjectReference.transform, deltaMovement);
				piece.ViewReference.RPC("SetKinematicRPC", (RpcTarget)3, new object[3]
				{
					true,
					piece.ObjectReference.transform.position,
					piece.ObjectReference.transform.rotation
				});
			}
			foreach (ChessPiece item in list)
			{
				pieces.Remove(item);
			}
			boardPosition = newPosition;
		}

		private void OnBoardRotated(Quaternion newRotation)
		{
			//IL_0024: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log.LogDebug((object)$"[ChessManager] Updating rotation of {pieces.Count} pieces.");
			Quaternion rotation = newRotation * Quaternion.Inverse(boardRotation);
			List<ChessPiece> list = new List<ChessPiece>();
			foreach (ChessPiece piece in pieces)
			{
				if ((Object)(object)piece.ObjectReference == (Object)null)
				{
					list.Add(piece);
					continue;
				}
				Util.RotateAroundPivot(piece.ObjectReference.transform, boardPosition, rotation);
				piece.ViewReference.RPC("SetKinematicRPC", (RpcTarget)3, new object[3]
				{
					true,
					piece.ObjectReference.transform.position,
					piece.ObjectReference.transform.rotation
				});
			}
			foreach (ChessPiece item in list)
			{
				pieces.Remove(item);
			}
			boardRotation = newRotation;
		}

		private void OnBoardScaled(Vector3 newScale)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log.LogDebug((object)$"[ChessManager] Updating scale of {pieces.Count} pieces.");
			List<ChessPiece> list = new List<ChessPiece>();
			foreach (ChessPiece piece in pieces)
			{
				if ((Object)(object)piece.ObjectReference == (Object)null)
				{
					list.Add(piece);
					continue;
				}
				Util.ApplyBoardScale(piece.ObjectReference.transform, boardPosition, boardScale, newScale);
				piece.ViewReference.RPC("SetKinematicRPC", (RpcTarget)3, new object[3]
				{
					true,
					piece.ObjectReference.transform.position,
					piece.ObjectReference.transform.rotation
				});
			}
			foreach (ChessPiece item in list)
			{
				pieces.Remove(item);
			}
			boardScale = newScale;
		}

		private void LoadBoardPosition()
		{
			//IL_0050: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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)
			GameObject val = GameObject.Find("Chess");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"[ChessManager] Unable to initialize board position: cannot find ChessSet object.");
				return;
			}
			Transform val2 = val.transform.Find("Plane");
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogError((object)"[ChessManager] Unable to initialize board position: cannot find chessboard object.");
				return;
			}
			boardPosition = val2.position;
			boardRotation = val2.rotation;
			boardScale = val2.localScale;
			Plugin.Log.LogDebug((object)$"[ChessManager] Found chessboard at {boardPosition} with rotation of {boardRotation} and scale of {boardScale}");
		}

		private void LoadChessSetPieces()
		{
			GameObject val = GameObject.Find("Chess");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"[ChessManager] Unable to initialize board position: cannot find ChessSet object.");
				return;
			}
			ChessStabilizer[] componentsInChildren = val.GetComponentsInChildren<ChessStabilizer>();
			ChessStabilizer[] array = componentsInChildren;
			foreach (ChessStabilizer val2 in array)
			{
				RegisterPiece(((Component)val2).gameObject);
			}
			Plugin.Log.LogDebug((object)$"[ChessManager] Added a total of {componentsInChildren.Length} chess pieces!");
			Plugin.Log.LogDebug((object)$"[ChessManager] Tracking {pieces.Count} pieces!");
		}

		public Vector3 GetChessBoardPosition()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!MovableChessboardWrapper.enabled && !IsLoaded())
			{
				boardLoaded = true;
				LoadBoardPosition();
				LoadChessSetPieces();
			}
			return boardPosition;
		}

		public Vector3 GetChessBoardOrigin()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return GetChessBoardPosition() - boardOriginOffset;
		}

		public Quaternion GetChessBoardRotation()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			if (!MovableChessboardWrapper.enabled && !IsLoaded())
			{
				LoadBoardPosition();
				LoadChessSetPieces();
				boardLoaded = true;
			}
			return boardRotation * Quaternion.Inverse(boardRotationCorrection);
		}

		public Vector3 GetChessBoardScale()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!MovableChessboardWrapper.enabled && !IsLoaded())
			{
				LoadBoardPosition();
				LoadChessSetPieces();
				boardLoaded = true;
			}
			return boardScale;
		}

		public static string GetPiecePrefab(PieceType type, bool isWhite)
		{
			StringBuilder stringBuilder = new StringBuilder();
			switch (type)
			{
			case PieceType.Pawn:
				stringBuilder.Append("C_Pawn");
				break;
			case PieceType.Knight:
				stringBuilder.Append("C_Knight");
				break;
			case PieceType.Bishop:
				stringBuilder.Append("C_Bishop");
				break;
			case PieceType.Rook:
				stringBuilder.Append("C_Rook");
				break;
			case PieceType.Queen:
				stringBuilder.Append("C_Queen");
				break;
			case PieceType.King:
				stringBuilder.Append("C_King");
				break;
			default:
				Plugin.Log.LogError((object)"[ChessManager] Unable to deduce prefab name: PieceType is None");
				return "";
			}
			stringBuilder.Append(" " + (isWhite ? "W" : "B"));
			return stringBuilder.ToString();
		}

		public static bool TryGetPiecePrefab(PieceType type, bool isWhite, out string prefabName)
		{
			prefabName = GetPiecePrefab(type, isWhite);
			if (string.IsNullOrEmpty(prefabName))
			{
				return false;
			}
			return true;
		}

		public void CreatePiece(PieceType type, bool isWhite, Vector3 position, Quaternion rotation)
		{
			//IL_0048: 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)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient)
			{
				Plugin.Log.LogError((object)$"[ChessManager] Unable to create '{type}' piece: host privileges required.");
				return;
			}
			if (!TryGetPiecePrefab(type, isWhite, out string prefabName))
			{
				Plugin.Log.LogError((object)$"[ChessManager] Unable to create '{type}' piece: unable to deduce prefab name.");
				return;
			}
			position += new Vector3(0f, 2f, 0f);
			PhotonView component = PhotonNetwork.InstantiateItemRoom(prefabName, position, rotation).GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null)
			{
				Plugin.Log.LogWarning((object)("[ChessManager] Created '" + prefabName + "', but unable to get photon view component."));
				return;
			}
			pieces.Add(new ChessPiece(((Component)component).gameObject));
			component.RPC("SetKinematicRPC", (RpcTarget)3, new object[3]
			{
				false,
				((Component)component).transform.position,
				((Component)component).transform.rotation
			});
			Plugin.Log.LogDebug((object)$"[ChessManager] Successfully created '{prefabName}' at {position}");
		}

		public void CreatePieceOnBoard(PieceType type, bool isWhite, BoardPosition position)
		{
			//IL_0030: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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)
			float num = 2.8f;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor((float)position.File * 0.8f - num, 0f, (float)position.Rank * 0.8f - num);
			Vector3 position2 = Util.CalculatePositionAfterPivotRotation(val + GetChessBoardPosition(), GetChessBoardPosition(), GetChessBoardRotation());
			Quaternion val2 = Quaternion.Euler(0f, isWhite ? 0f : 180f, 0f);
			val2 *= GetChessBoardRotation();
			CreatePiece(type, isWhite, position2, val2);
		}

		private void RemoveDeletedPieces()
		{
			int num = pieces.RemoveWhere((ChessPiece piece) => (Object)(object)piece.ObjectReference == (Object)null);
			if (num > 0)
			{
				Plugin.Log.LogDebug((object)$"[ChessManager] Removed {num} pieces that had no ObjectReference");
			}
		}

		public void RemoveAllPieces()
		{
			if (!PhotonNetwork.IsMasterClient)
			{
				Plugin.Log.LogError((object)"[ChessManager] Unable to remove pieces: host privileges required.");
				return;
			}
			RemoveDeletedPieces();
			int count = pieces.Count;
			foreach (ChessPiece piece in pieces)
			{
				PhotonNetwork.Destroy(piece.ObjectReference);
			}
			pieces.Clear();
			Plugin.Log.LogDebug((object)$"[ChessManager] Destroyed a total of {count} pieces!");
		}

		internal void RegisterPiece(GameObject piece)
		{
			pieces.Add(new ChessPiece(piece));
		}

		internal ChessPiece GetChessPiece(GameObject _object)
		{
			GameObject _object2 = _object;
			return pieces.Where((ChessPiece piece) => (Object)(object)piece.ObjectReference == (Object)(object)_object2).FirstOrDefault();
		}

		internal bool TryGetChessPiece(GameObject _object, out ChessPiece piece)
		{
			piece = GetChessPiece(_object);
			return piece != null;
		}

		public bool IsLoaded()
		{
			return boardLoaded;
		}
	}
	public class BoardPosition
	{
		public const int BoardSize = 8;

		public const float GridSize = 0.8f;

		public int Rank;

		public int File;

		public static float HalfSize => 2.8f;

		public BoardPosition(Vector3 position, Vector3 origin)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			Vector3 val = position - origin;
			File = Mathf.RoundToInt(val.x / 0.8f);
			Rank = Mathf.RoundToInt(val.z / 0.8f);
		}

		public BoardPosition(int rank, int file)
		{
			Rank = rank;
			File = file;
		}

		private bool WithinBounds(int x, int y)
		{
			if (x >= 0 && x < 8 && y >= 0)
			{
				return y < 8;
			}
			return false;
		}

		public override string ToString()
		{
			if (!WithinBounds(File, Rank))
			{
				return "??";
			}
			return $"{(char)(97 + File)}{(char)(49 + Rank)}";
		}
	}
	public class ChessPiece
	{
		public GameObject ObjectReference;

		public PhotonView ViewReference;

		public Vector3 Position;

		public PieceType Type;

		public bool IsWhite;

		public BoardPosition PositionOnBoard;

		private ChessManager manager;

		public ChessPiece(GameObject gameObject, Vector3 position, PieceType type, bool isWhite)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			ObjectReference = gameObject;
			ViewReference = gameObject.GetComponent<PhotonView>();
			Position = position;
			Type = type;
			IsWhite = isWhite;
			manager = ChessManager.Instance;
			PositionOnBoard = new BoardPosition(Position, manager.GetChessBoardPosition());
		}

		public ChessPiece(GameObject chessPiece)
			: this(chessPiece, chessPiece.transform.position, NameToType(((Object)chessPiece).name), NameToColor(((Object)chessPiece).name))
		{
		}//IL_0008: Unknown result type (might be due to invalid IL or missing references)


		public void UpdatePosition(Vector3 newPosition)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Position = newPosition;
			PositionOnBoard = new BoardPosition(Position, manager.GetChessBoardPosition());
		}

		public static PieceType NameToType(string name)
		{
			name = name.ToLowerInvariant();
			string text = name;
			if (name.Contains("pawn"))
			{
				return PieceType.Pawn;
			}
			if (name.Contains("knight"))
			{
				return PieceType.Knight;
			}
			if (name.Contains("bishop"))
			{
				return PieceType.Bishop;
			}
			if (name.Contains("rook"))
			{
				return PieceType.Rook;
			}
			if (name.Contains("queen"))
			{
				return PieceType.Queen;
			}
			if (name.Contains("king"))
			{
				return PieceType.King;
			}
			return PieceType.None;
		}

		public static bool NameToColor(string name)
		{
			string[] array = name.Split(' ', 2);
			if (array.Length < 2)
			{
				return true;
			}
			if (!array[1].Contains('B'))
			{
				return true;
			}
			return false;
		}

		public override int GetHashCode()
		{
			return (Type.GetHashCode() + IsWhite.GetHashCode() + PositionOnBoard.GetHashCode()) % int.MaxValue;
		}
	}
	public enum PieceType
	{
		None,
		Pawn,
		Knight,
		Bishop,
		Rook,
		Queen,
		King
	}
	internal class DebugSnapPlane : MonoBehaviour
	{
		private GameObject? debugPlane;

		private bool isVisible;

		private List<GameObject> dots = new List<GameObject>();

		private List<Vector3> dotOffsets = new List<Vector3>();

		private Quaternion _lastRotation = Quaternion.identity;

		private Vector3 _lastPosition = Vector3.zero;

		private Vector3 _lastScale = Vector3.one;

		private static readonly Vector3 heightOffset = new Vector3(0f, 0.005f, 0f);

		public void CreatePlane(Vector3 boardOrigin)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0042: 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)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_00c0: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("DebugSnapPlane");
			debugPlane = new GameObject("DebugPlane");
			debugPlane.transform.SetParent(val.transform, false);
			debugPlane.transform.position = ChessManager.Instance.GetChessBoardPosition();
			Transform transform = debugPlane.transform;
			transform.rotation *= Quaternion.Euler(180f, 0f, 0f);
			debugPlane.SetActive(isVisible);
			MeshRenderer val2 = debugPlane.AddComponent<MeshRenderer>();
			MeshFilter val3 = debugPlane.AddComponent<MeshFilter>();
			val3.mesh = MakeMesh();
			Material val4 = new Material(Shader.Find("Unlit/Color"));
			val4.color = new Color(1f, 0f, 0f, 0.3f);
			((Renderer)val2).material = val4;
			for (int i = 0; i < 8; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					dotOffsets.Add(new Vector3((float)j, 0f, (float)i));
					GameObject val5 = GameObject.CreatePrimitive((PrimitiveType)0);
					val5.SetActive(isVisible);
					val5.transform.SetParent(val.transform, false);
					val5.transform.position = boardOrigin + new Vector3((float)j * 0.8f, 0f, (float)i * 0.8f);
					val5.transform.localScale = Vector3.one * 0.2f;
					Object.Destroy((Object)(object)val5.GetComponent<Collider>());
					Material val6 = new Material(Shader.Find("Unlit/Color"));
					val6.color = Color.blue;
					val5.GetComponent<Renderer>().material = val6;
					dots.Add(val5);
				}
			}
		}

		private void UpdatePlanePosition()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			debugPlane.transform.position = ChessManager.Instance.GetChessBoardPosition();
			debugPlane.GetComponent<MeshFilter>().mesh = MakeMesh();
		}

		private void UpdateDotPosition()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0069: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			Vector3 chessBoardPosition = ChessManager.Instance.GetChessBoardPosition();
			Quaternion chessBoardRotation = ChessManager.Instance.GetChessBoardRotation();
			Plugin.Log.LogDebug((object)$"[DebugPlane] Pivot: {chessBoardPosition}");
			Plugin.Log.LogDebug((object)$"[DebugPlane] Rotation: {chessBoardRotation}");
			for (int i = 0; i < dots.Count && i < dotOffsets.Count; i++)
			{
				Vector3 initial = ChessManager.Instance.GetChessBoardOrigin() + dotOffsets[i] * 0.8f;
				dots[i].transform.position = Util.CalculatePositionAfterPivotRotation(initial, chessBoardPosition, chessBoardRotation);
			}
		}

		public void Update()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)debugPlane == (Object)null)
			{
				return;
			}
			if (Input.GetKeyDown(Plugin.DebugButton.Value))
			{
				isVisible = !isVisible;
				debugPlane.SetActive(isVisible);
				foreach (GameObject dot in dots)
				{
					dot.SetActive(isVisible);
				}
			}
			ChessManager instance = ChessManager.Instance;
			if (BoardTransformChanged(instance.GetChessBoardPosition(), instance.GetChessBoardRotation(), instance.GetChessBoardScale()))
			{
				UpdatePlanePosition();
				UpdateDotPosition();
				_lastRotation = instance.GetChessBoardRotation();
				_lastPosition = instance.GetChessBoardPosition();
				_lastScale = instance.GetChessBoardScale();
			}
		}

		private bool AngleChanged(Quaternion rotation)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.Angle(rotation, _lastRotation) >= 0.0001f;
		}

		private bool PositionChanged(Vector3 position)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Distance(position, _lastPosition) >= 0.0001f;
		}

		private bool ScaleChanged(Vector3 scale)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Distance(scale, _lastScale) >= 0.0001f;
		}

		public bool BoardTransformChanged(Vector3 position, Quaternion rotation, Vector3 scale)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!PositionChanged(position) && !AngleChanged(rotation))
			{
				return ScaleChanged(scale);
			}
			return true;
		}

		private Mesh MakeMesh()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_007b: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//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_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)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = (float)(8 + 2 * Plugin.BoardOffsetGrids.Value) * 0.8f * Vector2.one;
			Vector3 val2 = ChessManager.Instance.GetChessBoardRotation() * Quaternion.Euler(180f, 0f, 0f) * Vector3.right;
			Vector3 val3 = ChessManager.Instance.GetChessBoardRotation() * Quaternion.Euler(180f, 0f, 0f) * Vector3.forward;
			float num = val.x / 2f;
			float num2 = val.y / 2f;
			return MakePlane((Vector3[])(object)new Vector3[4]
			{
				heightOffset + val2 * num + val3 * num2,
				heightOffset - val2 * num + val3 * num2,
				heightOffset - val2 * num - val3 * num2,
				heightOffset + val2 * num - val3 * num2
			});
		}

		private Vector3[] RotateVertices(Vector3[] vertices, Vector3 pivot, Quaternion rotation)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < vertices.Length; i++)
			{
				vertices[i] = rotation * vertices[i];
			}
			return vertices;
		}

		private Vector3[] GetVertices(Vector3 corner, float size)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0036: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			return (Vector3[])(object)new Vector3[4]
			{
				corner,
				corner + new Vector3(0f, 0f, size),
				corner + new Vector3(size, 0f, size),
				corner + new Vector3(size, 0f, 0f)
			};
		}

		private Vector3[] GetVertices(float size, float heightOffset = 0.01f)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			float num = size / 2f;
			return (Vector3[])(object)new Vector3[4]
			{
				new Vector3(0f - num, heightOffset, 0f - num),
				new Vector3(0f - num, heightOffset, num),
				new Vector3(num, heightOffset, num),
				new Vector3(num, heightOffset, 0f - num)
			};
		}

		private Vector3[] GetVertices(Vector3 min, Vector3 max)
		{
			//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_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c1: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_015a: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (min + max) * 0.5f;
			return (Vector3[])(object)new Vector3[4]
			{
				val + new Vector3((float)Plugin.BoardOffsetGrids.Value * 0.8f, 0f, (float)Plugin.BoardOffsetGrids.Value * 0.8f) + new Vector3(BoardPosition.HalfSize, 0f, BoardPosition.HalfSize),
				val + new Vector3((float)(-Plugin.BoardOffsetGrids.Value) * 0.8f, 0f, (float)Plugin.BoardOffsetGrids.Value * 0.8f) + new Vector3(0f - BoardPosition.HalfSize, 0f, BoardPosition.HalfSize),
				val + new Vector3((float)(-Plugin.BoardOffsetGrids.Value) * 0.8f, 0f, (float)(-Plugin.BoardOffsetGrids.Value) * 0.8f) + new Vector3(0f - BoardPosition.HalfSize, 0f, 0f - BoardPosition.HalfSize),
				val + new Vector3((float)Plugin.BoardOffsetGrids.Value * 0.8f, 0f, (float)(-Plugin.BoardOffsetGrids.Value) * 0.8f) + new Vector3(BoardPosition.HalfSize, 0f, 0f - BoardPosition.HalfSize)
			};
		}

		private Mesh MakeSquareCentered(float size, float heightOffset = 0.01f)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			float num = size / 2f;
			Mesh val = new Mesh();
			Vector3[] vertices = GetVertices(size, heightOffset);
			int[] triangles = new int[6] { 0, 2, 1, 0, 3, 2 };
			Vector2[] uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f),
				new Vector2(1f, 0f)
			};
			val.vertices = vertices;
			val.uv = uv;
			val.triangles = triangles;
			val.RecalculateNormals();
			return val;
		}

		private Mesh MakeSquare(Vector3 corner, float size)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0049: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			Vector3[] vertices = GetVertices(corner, size);
			int[] triangles = new int[6] { 0, 2, 1, 0, 3, 2 };
			Vector2[] uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f),
				new Vector2(1f, 0f)
			};
			val.vertices = vertices;
			val.uv = uv;
			val.triangles = triangles;
			val.RecalculateNormals();
			return val;
		}

		private Mesh MakePlane(Vector3[] corners)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0047: 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)
			//IL_005d: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			int[] triangles = new int[6] { 0, 2, 1, 0, 3, 2 };
			Vector2[] uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f),
				new Vector2(1f, 0f)
			};
			val.vertices = corners;
			val.uv = uv;
			val.triangles = triangles;
			val.RecalculateNormals();
			return val;
		}

		private Mesh MakeQuad(Vector3 min, Vector3 max)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0049: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			Vector3[] vertices = GetVertices(min, max);
			int[] triangles = new int[6] { 0, 2, 1, 0, 3, 2 };
			Vector2[] uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f),
				new Vector2(1f, 0f)
			};
			val.vertices = vertices;
			val.uv = uv;
			val.triangles = triangles;
			val.RecalculateNormals();
			return val;
		}

		public bool IsInitialized()
		{
			return (Object)(object)debugPlane != (Object)null;
		}
	}
	public static class MovableChessboardWrapper
	{
		private static bool initialized;

		private static bool available;

		private static bool? _enabled;

		private static object? _managerInstance;

		private static EventInfo? _onBoardLoaded;

		private static EventInfo? _onPositionChanged;

		private static EventInfo? _onRotationChanged;

		private static EventInfo? _onScaleChanged;

		public static bool IsAvailable => available;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.github.Kirshoo.MovableChessboard");
				}
				return _enabled.Value;
			}
		}

		public static void Init()
		{
			if (initialized)
			{
				return;
			}
			initialized = true;
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "com.github.Kirshoo.MovableChessboard");
			if (assembly == null)
			{
				Plugin.Log.LogWarning((object)"Unable to find com.github.Kirshoo.MovableChessboard assembly...");
				available = false;
				return;
			}
			Type type = assembly.GetType("MovableChessboard.BoardManager");
			if (type == null)
			{
				Plugin.Log.LogWarning((object)"Unable to find BoardManager of MovableChessboard namespace...");
				available = false;
				return;
			}
			_managerInstance = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
			if (_managerInstance == null)
			{
				Plugin.Log.LogWarning((object)"Unable to get Instance of BoardManager...");
				available = false;
				return;
			}
			_managerInstance.GetType().GetMethod("Init").Invoke(_managerInstance, null);
			_onBoardLoaded = type.GetEvent("OnBoardLoaded");
			_onPositionChanged = type.GetEvent("OnBoardChangedPosition");
			_onRotationChanged = type.GetEvent("OnBoardChangedRotation");
			_onScaleChanged = type.GetEvent("OnBoardChangedScale");
			available = true;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SubscirbeToPositionChanged(Action<Vector3> callback)
		{
			if (!enabled || !initialized || _onPositionChanged == null)
			{
				Plugin.Log.LogError((object)"[MCWrapper] Failed to subscribe to position changed event.");
				Plugin.Log.LogDebug((object)$"[MCWrapper] Enabled? {enabled}; Initialized? {initialized}; HasEvent? {_onPositionChanged != null}");
			}
			else
			{
				Delegate handler = Delegate.CreateDelegate(_onPositionChanged.EventHandlerType, callback.Target, callback.Method);
				_onPositionChanged.AddEventHandler(_managerInstance, handler);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SubscirbeToRotationChanged(Action<Quaternion> callback)
		{
			if (!enabled || !initialized || _onRotationChanged == null)
			{
				Plugin.Log.LogError((object)"[MCWrapper] Failed to subscribe to rotation changed event.");
				Plugin.Log.LogDebug((object)$"[MCWrapper] Enabled? {enabled}; Initialized? {initialized}; HasEvent? {_onRotationChanged != null}");
			}
			else
			{
				Delegate handler = Delegate.CreateDelegate(_onRotationChanged.EventHandlerType, callback.Target, callback.Method);
				_onRotationChanged.AddEventHandler(_managerInstance, handler);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SubscirbeToScaleChanged(Action<Vector3> callback)
		{
			if (!enabled || !initialized || _onScaleChanged == null)
			{
				Plugin.Log.LogError((object)"[MCWrapper] Failed to subscribe to scale changed event.");
				Plugin.Log.LogDebug((object)$"[MCWrapper] Enabled? {enabled}; Initialized? {initialized}; HasEvent? {_onScaleChanged != null}");
			}
			else
			{
				Delegate handler = Delegate.CreateDelegate(_onScaleChanged.EventHandlerType, callback.Target, callback.Method);
				_onScaleChanged.AddEventHandler(_managerInstance, handler);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SubscirbeToBoardLoaded(Action callback)
		{
			if (enabled && initialized && !(_onBoardLoaded == null))
			{
				Delegate handler = Delegate.CreateDelegate(_onBoardLoaded.EventHandlerType, callback.Target, callback.Method);
				_onBoardLoaded.AddEventHandler(_managerInstance, handler);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject? GetBoard()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			if (!enabled || _managerInstance == null)
			{
				Plugin.Log.LogWarning((object)"Ignoring attempt at accessing board: Wrapper is not enabled.");
				return null;
			}
			MethodInfo method = _managerInstance.GetType().GetMethod("GetBoard");
			return (GameObject)method.Invoke(_managerInstance, null);
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static Vector3 GetBoardPosition()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!enabled || _managerInstance == null)
			{
				Plugin.Log.LogWarning((object)"Ignoring attempt at accessing board position: Wrapper is not enabled.");
				return Vector3.zero;
			}
			MethodInfo method = _managerInstance.GetType().GetMethod("GetBoardPosition");
			return (Vector3)method.Invoke(_managerInstance, null);
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static Quaternion GetBoardRotation()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!enabled || _managerInstance == null)
			{
				Plugin.Log.LogWarning((object)"Ignoring attempt at accessing board rotation: Wrapper is not enabled.");
				return Quaternion.identity;
			}
			MethodInfo method = _managerInstance.GetType().GetMethod("GetBoardRotation");
			return (Quaternion)method.Invoke(_managerInstance, null);
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static Vector3 GetBoardScale()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!enabled || _managerInstance == null)
			{
				Plugin.Log.LogWarning((object)"Ignoring attempt at accessing board scale: Wrapper is not enabled.");
				return Vector3.zero;
			}
			MethodInfo method = _managerInstance.GetType().GetMethod("GetBoardScale");
			return (Vector3)method.Invoke(_managerInstance, null);
		}
	}
	internal class PieceMovement
	{
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.github.Kirshoo.BetterChess", "BetterChess", "0.6.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ConfigEntry<float> LerpSpeed;

		internal static ConfigEntry<int> BoardOffsetGrids;

		internal static ConfigEntry<KeyCode> ResetButton;

		internal static ConfigEntry<KeyCode> DebugButton;

		internal static ConfigEntry<string> DefaultPosition;

		internal static DebugSnapPlane snapPlane;

		public const string Id = "com.github.Kirshoo.BetterChess";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "BetterChess";

		public static string Version => "0.6.0";

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			BindConfig();
			new Harmony("com.github.Kirshoo.BetterChess").PatchAll(typeof(PieceSnappingPatch));
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void BindConfig()
		{
			BoardOffsetGrids = ((BaseUnityPlugin)this).Config.Bind<int>("Snapping", "BoardOffsetGrids", 2, "Range outside chessboard where snapping will affect the pieces. \r\nRepresented in terms of grids cells.\r\nIf set to 0 or lower, will only snap pieces within the chessboard.");
			if (BoardOffsetGrids.Value < 0)
			{
				BoardOffsetGrids.Value = 0;
			}
			LerpSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Snapping", "SnapSpeed", 2f, "Speed at which pieces are snapped to their positions within the grid.\r\nAllowed range: 0.5 - 5");
			if ((double)LerpSpeed.Value < 0.5)
			{
				LerpSpeed.Value = 0.5f;
			}
			else if (LerpSpeed.Value > 5f)
			{
				LerpSpeed.Value = 5f;
			}
			ResetButton = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ResetButton", (KeyCode)99, "Button that resets the chessboard state located in airport.\r\nWhen first loaded to the airport, press this button TWICE to ensure proper initialization.");
			DebugButton = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "DebugButton", (KeyCode)111, "Button that shows visualisation of internal areas and positions for debug purposes.\r\nRed area is the area in which pieces are \"captured\" and will snap to the nearest position on the board.\r\nBlue dots are snapping poits and should correspond to the center of the chess board cell.");
			DefaultPosition = ((BaseUnityPlugin)this).Config.Bind<string>("General", "DefaultBoardState", "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "Represents default state which board will reset to, when ResetButton is pressed.\r\nValue is in FEN notation. You can see more information about it on this wiki page:\r\nhttps://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation");
		}

		private void Start()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			ChessManager.Instance.Init();
			GameObject val = new GameObject("DebugPlaneManager");
			snapPlane = val.AddComponent<DebugSnapPlane>();
			Object.DontDestroyOnLoad((Object)(object)val);
			if (MovableChessboardWrapper.enabled)
			{
				MovableChessboardWrapper.SubscirbeToBoardLoaded(delegate
				{
					//IL_000a: Unknown result type (might be due to invalid IL or missing references)
					snapPlane.CreatePlane(ChessManager.Instance.GetChessBoardOrigin());
				});
			}
		}

		private void Update()
		{
			//IL_0005: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(ResetButton.Value))
			{
				if (!Util.IsInAirport())
				{
					Log.LogInfo((object)"Cannot reset the state of chessboard whilst not being in Airport");
					return;
				}
				if (!PhotonNetwork.IsMasterClient)
				{
					Log.LogInfo((object)"Only HOST can reset chessboard state");
					return;
				}
				ChessLogic.ResetBoardPosition(DefaultPosition.Value);
			}
			if (Input.GetKeyUp(DebugButton.Value))
			{
				if (!Util.IsInAirport())
				{
					Log.LogInfo((object)"Cannot show debug the state of SnapPlane whilst not being in Airport");
				}
				else if (!snapPlane.IsInitialized())
				{
					Log.LogInfo((object)"Creating DebugPlane.");
					snapPlane.CreatePlane(ChessManager.Instance.GetChessBoardOrigin());
				}
			}
		}
	}
	internal class PieceSnappingPatch
	{
		[CompilerGenerated]
		private sealed class <SnapToGridLerp>d__9 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public ChessStabilizer chessPiece;

			public PhotonView view;

			private Transform <piece>5__2;

			private Collider <col>5__3;

			private Vector3 <start>5__4;

			private Vector3 <target>5__5;

			private float <t>5__6;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<piece>5__2 = null;
				<col>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: 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_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: 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_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_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: 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_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: 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_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_0164: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0218: Unknown result type (might be due to invalid IL or missing references)
				//IL_0230: 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)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
				{
					<>1__state = -1;
					<piece>5__2 = ((Component)chessPiece).transform;
					<col>5__3 = ((Component)<piece>5__2).GetComponent<Collider>();
					if ((Object)(object)<col>5__3 != (Object)null)
					{
						<col>5__3.enabled = false;
					}
					<start>5__4 = <piece>5__2.position;
					Vector3 chessBoardPosition = ChessManager.Instance.GetChessBoardPosition();
					Quaternion chessBoardRotation = ChessManager.Instance.GetChessBoardRotation();
					Vector3 val = Quaternion.Inverse(chessBoardRotation) * (<start>5__4 - chessBoardPosition);
					float num = 3.5f;
					float num2 = val.x / 0.8f;
					int num3 = Mathf.RoundToInt(num2 + num);
					num3 = Mathf.Clamp(num3, 0, 7);
					float num4 = ((float)num3 - num) * 0.8f;
					float num5 = val.z / 0.8f;
					int num6 = Mathf.RoundToInt(num5 + num);
					num6 = Mathf.Clamp(num6, 0, 7);
					float num7 = ((float)num6 - num) * 0.8f;
					Vector3 val2 = default(Vector3);
					((Vector3)(ref val2))..ctor(num4, val.y, num7);
					<target>5__5 = chessBoardPosition + chessBoardRotation * val2;
					<t>5__6 = 0f;
					break;
				}
				case 1:
					<>1__state = -1;
					break;
				}
				if (<t>5__6 < 1f)
				{
					<t>5__6 += Time.fixedDeltaTime * 2f;
					<piece>5__2.position = Vector3.Lerp(<start>5__4, <target>5__5, <t>5__6);
					chessPiece.groundTimer = <t>5__6;
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				if ((Object)(object)<col>5__3 != (Object)null)
				{
					<col>5__3.enabled = true;
				}
				if (ChessManager.Instance.TryGetChessPiece(((Component)chessPiece).gameObject, out ChessPiece piece))
				{
					piece.UpdatePosition(<target>5__5);
				}
				else
				{
					ChessManager.Instance.RegisterPiece(((Component)chessPiece).gameObject);
				}
				view.RPC("SetKinematicRPC", (RpcTarget)3, new object[3]
				{
					true,
					<target>5__5,
					Quaternion.Euler(0f, <piece>5__2.eulerAngles.y, 0f)
				});
				return false;
			}

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

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

		private const float LerpSpeed = 2f;

		private const float SnapTimeOffset = 1f;

		internal static readonly Vector3 boardMinOffset = new Vector3((float)Plugin.BoardOffsetGrids.Value * 0.8f, 0f, (float)Plugin.BoardOffsetGrids.Value * 0.8f);

		internal static readonly Vector3 boardMaxOffset = new Vector3((float)(7 + Plugin.BoardOffsetGrids.Value) * 0.8f, 0f, (float)(7 + Plugin.BoardOffsetGrids.Value) * 0.8f);

		private static readonly HashSet<ChessStabilizer> snappedPieces = new HashSet<ChessStabilizer>();

		private static void ClearUpSnappedCollection()
		{
			snappedPieces.RemoveWhere((ChessStabilizer component) => (Object)(object)component == (Object)null);
		}

		private static bool ReadyToSnap(Rigidbody rb, ChessStabilizer stabilizer)
		{
			//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_0034: 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_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)
			if (!((Object)(object)rb == (Object)null) && !rb.isKinematic && !(stabilizer.groundTimer < 1f))
			{
				Vector3 val = rb.linearVelocity;
				if (!(((Vector3)(ref val)).sqrMagnitude >= 0.8f))
				{
					val = rb.angularVelocity;
					if (!(((Vector3)(ref val)).sqrMagnitude >= 0.8f))
					{
						return !(Vector3.Angle(((Component)stabilizer).transform.up, Vector3.up) >= 2.5f);
					}
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(ChessStabilizer), "FixedUpdate")]
		[HarmonyPostfix]
		private static void SnapPiece(ChessStabilizer __instance)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			Rigidbody rig = __instance.item.rig;
			if (ReadyToSnap(rig, __instance) && WithinBoardArea(((Component)__instance).transform.position))
			{
				ClearUpSnappedCollection();
				if (!snappedPieces.Contains(__instance))
				{
					snappedPieces.Add(__instance);
					((MonoBehaviour)__instance).StartCoroutine(SnapToGridLerp(__instance, ((Component)__instance).gameObject.GetComponent<PhotonView>()));
				}
			}
		}

		private static bool WithinBoardArea(Vector3 position)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)(8 + 2 * Plugin.BoardOffsetGrids.Value) * 0.8f;
			return Util.IsPointInsideArea(position, ChessManager.Instance.GetChessBoardPosition(), ChessManager.Instance.GetChessBoardRotation(), num * Vector2.one);
		}

		[IteratorStateMachine(typeof(<SnapToGridLerp>d__9))]
		private static IEnumerator SnapToGridLerp(ChessStabilizer chessPiece, PhotonView view)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SnapToGridLerp>d__9(0)
			{
				chessPiece = chessPiece,
				view = view
			};
		}
	}
	internal static class Util
	{
		private const string AirportSceneName = "Airport";

		internal static bool IsInAirport()
		{
			//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)
			Scene activeScene = SceneManager.GetActiveScene();
			return ((Scene)(ref activeScene)).name == "Airport";
		}

		internal static void ApplyBoardMovement(Transform obj, Vector3 deltaMovement)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)obj).transform;
			transform.position += deltaMovement;
		}

		internal static Vector3 CalculatePositionAfterPivotRotation(Vector3 initial, Vector3 pivot, Quaternion rotation)
		{
			//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_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return pivot + rotation * (initial - pivot);
		}

		internal static void RotateAroundPivot(Transform obj, Vector3 pivot, Quaternion rotation)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			obj.position = CalculatePositionAfterPivotRotation(obj.position, pivot, rotation);
			obj.rotation = rotation * obj.rotation;
		}

		internal static void ApplyBoardScale(Transform obj, Vector3 center, Vector3 oldScale, Vector3 newScale)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(newScale.x / oldScale.x, newScale.y / oldScale.y, newScale.z / oldScale.z);
			Vector3 val2 = obj.position - center;
			val2 = Vector3.Scale(val2, val);
			obj.position = center + val2;
			obj.localScale = Vector3.Scale(obj.localScale, val);
		}

		internal static bool IsPointInsideArea(Vector3 point, Vector3 center, Quaternion rotation, Vector2 size)
		{
			//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_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = rotation * Vector3.right;
			Vector3 val2 = rotation * Vector3.forward;
			float num = size.x / 2f;
			float num2 = size.y / 2f;
			Vector3 val3 = point - center;
			float num3 = Vector3.Dot(val3, val);
			float num4 = Vector3.Dot(val3, val2);
			if (Mathf.Abs(num3) <= num)
			{
				return Mathf.Abs(num4) <= num2;
			}
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}