Decompiled source of MapsExtended v1.4.2

plugins\MapsExtended.dll

Decompiled 6 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Utils;
using MapsExt.Compatibility;
using MapsExt.Compatibility.V0;
using MapsExt.Compatibility.V0.MapObjects;
using MapsExt.Compatibility.V1.MapObjects;
using MapsExt.MapObjects;
using MapsExt.Properties;
using MapsExt.Utils;
using On;
using Photon.Pun;
using Sirenix.Serialization;
using Sirenix.Utilities;
using Sonigon;
using Sonigon.Internal;
using UnboundLib;
using UnboundLib.GameModes;
using UnboundLib.Networking;
using UnboundLib.Utils;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Serialization;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: BindTypeNameToType("MapsExt.MapObjects.MapObject", typeof(MapObjectData))]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
internal class ThisAssembly
{
	[GeneratedCode("ThisAssembly.Project", "1.0.0")]
	[CompilerGenerated]
	public static class Project
	{
		public const string RootNamespace = "MapsExt";

		public const string AssemblyName = "MapsExtended";

		public const string TargetFrameworkVersion = "v4.7.2";

		public const string TargetFrameworkIdentifier = ".NETFramework";

		public const string TargetFrameworkMoniker = ".NETFramework,Version=v4.7.2";

		public const string Version = "1.4.2";
	}
}
namespace MapsExt
{
	public enum CurveType
	{
		Linear,
		EaseIn,
		EaseOut,
		EaseInOut
	}
	public class AnimationKeyframe
	{
		[SerializeField]
		private List<ILinearProperty> _componentValues;

		[SerializeField]
		private float _duration;

		[SerializeField]
		private CurveType _curveType;

		private BezierCurve _curve;

		public List<ILinearProperty> ComponentValues
		{
			get
			{
				return _componentValues;
			}
			set
			{
				_componentValues = value;
			}
		}

		public float Duration
		{
			get
			{
				return _duration;
			}
			set
			{
				_duration = value;
			}
		}

		public CurveType CurveType
		{
			get
			{
				return _curveType;
			}
			set
			{
				_curveType = value;
			}
		}

		public BezierCurve Curve
		{
			get
			{
				return _curve;
			}
			set
			{
				_curve = value;
			}
		}

		public AnimationKeyframe()
		{
			ComponentValues = new List<ILinearProperty>();
			Duration = 1f;
			CurveType = CurveType.Linear;
			UpdateCurve();
		}

		public AnimationKeyframe(params ILinearProperty[] values)
			: this((IEnumerable<ILinearProperty>)values)
		{
		}

		public AnimationKeyframe(IEnumerable<ILinearProperty> values)
		{
			ComponentValues = values.ToList();
			Duration = 1f;
			CurveType = CurveType.Linear;
			UpdateCurve();
		}

		public AnimationKeyframe(AnimationKeyframe frame)
		{
			ComponentValues = frame.ComponentValues.ToList();
			Duration = frame.Duration;
			CurveType = frame.CurveType;
			UpdateCurve();
		}

		public void UpdateCurve()
		{
			Curve = GetCurve();
		}

		public T GetComponentValue<T>() where T : IProperty
		{
			return (T)ComponentValues.Find((ILinearProperty v) => typeof(T).IsAssignableFrom(v.GetType()));
		}

		public ILinearProperty GetComponentValue(Type propertyType)
		{
			return ComponentValues.Find((ILinearProperty v) => propertyType.IsAssignableFrom(v.GetType()));
		}

		private BezierCurve GetCurve()
		{
			//IL_0031: 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_0059: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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)
			CurveType curveType = CurveType;
			if (1 == 0)
			{
			}
			BezierCurve result = curveType switch
			{
				CurveType.Linear => new BezierCurve(new Vector2(0.33f, 0.33f), new Vector2(0.66f, 0.66f)), 
				CurveType.EaseIn => new BezierCurve(new Vector2(0.12f, 0f), new Vector2(0.39f, 0f)), 
				CurveType.EaseOut => new BezierCurve(new Vector2(0.61f, 1f), new Vector2(0.88f, 1f)), 
				CurveType.EaseInOut => new BezierCurve(new Vector2(0.37f, 0f), new Vector2(0.63f, 1f)), 
				_ => null, 
			};
			if (1 == 0)
			{
			}
			return result;
		}
	}
	public class BezierCurve
	{
		private class DistanceToPoint : IComparable<DistanceToPoint>, IComparable
		{
			public float Distance { get; set; }

			public Vector2 Point { get; set; }

			public DistanceToPoint(float distance, Vector2 point)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				Distance = distance;
				Point = point;
			}

			public int CompareTo(DistanceToPoint obj)
			{
				return Distance.CompareTo(obj.Distance);
			}

			public int CompareTo(object obj)
			{
				return CompareTo((DistanceToPoint)obj);
			}
		}

		private const int DefaultSegmentCount = 40;

		private readonly DistanceToPoint[] _distancesToPoints;

		public Vector2 P0 { get; }

		public Vector2 P1 { get; }

		public Vector2 P2 { get; }

		public Vector2 P3 { get; }

		public Vector2[] Points => _distancesToPoints.Select((DistanceToPoint s) => s.Point).ToArray();

		public float Length => _distancesToPoints.Last().Distance;

		private static Vector2 FindPositionForDistance(float distance, DistanceToPoint[] segments)
		{
			//IL_0003: 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_006d: 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_0078: 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_0041: 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)
			int num = Array.BinarySearch(segments, new DistanceToPoint(distance, Vector2.zero));
			if (num < 0)
			{
				num = ~num - 1;
			}
			if (num >= segments.Length - 1)
			{
				return segments.Last().Point;
			}
			DistanceToPoint distanceToPoint = segments[num];
			DistanceToPoint distanceToPoint2 = segments[num + 1];
			float num2 = (distance - distanceToPoint.Distance) / (distanceToPoint2.Distance - distanceToPoint.Distance);
			return Vector2.Lerp(distanceToPoint.Point, distanceToPoint2.Point, num2);
		}

		public BezierCurve(Vector2 p1, Vector2 p2, int segmentCount = 40)
			: this(Vector2.zero, p1, p2, Vector2.one, segmentCount)
		{
		}//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_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)


		public BezierCurve(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, int segmentCount = 40)
		{
			//IL_0023: 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_002b: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (segmentCount < 2)
			{
				throw new ArgumentOutOfRangeException("segmentCount", "Must be at least 2");
			}
			P0 = p0;
			P1 = p1;
			P2 = p2;
			P3 = p3;
			_distancesToPoints = GetDistancesToPoints(segmentCount);
		}

		public float Evaluate(float t)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return EvaluatePosition(t).y;
		}

		public Vector2 EvaluatePosition(float t)
		{
			//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_0031: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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)
			float num = t * t;
			float num2 = num * t;
			float num3 = 1f - t;
			float num4 = num3 * num3;
			float num5 = num4 * num3;
			return num5 * P0 + 3f * num4 * t * P1 + 3f * num3 * num * P2 + num2 * P3;
		}

		public float EvaluateForDistance(float distance)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return EvaluatePositionForDistance(distance).y;
		}

		public Vector2 EvaluatePositionForDistance(float distance)
		{
			//IL_0014: 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_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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			if (distance <= 0f)
			{
				return P0;
			}
			if (distance >= 1f)
			{
				return P3;
			}
			float num = distance * Length;
			int num2 = (int)(distance * (float)(_distancesToPoints.Length - 1));
			DistanceToPoint distanceToPoint = _distancesToPoints[num2];
			DistanceToPoint distanceToPoint2 = _distancesToPoints[num2 + 1];
			float num3 = (num - distanceToPoint.Distance) / (distanceToPoint2.Distance - distanceToPoint.Distance);
			return Vector2.Lerp(distanceToPoint.Point, distanceToPoint2.Point, num3);
		}

		private DistanceToPoint[] GetDistancesToPoints(int count)
		{
			//IL_0012: 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)
			//IL_003d: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			DistanceToPoint[] array = new DistanceToPoint[count + 1];
			array[0] = new DistanceToPoint(0f, P0);
			for (int i = 1; i <= count; i++)
			{
				float t = (float)i / (float)count;
				Vector2 val = EvaluatePosition(t);
				float distance = array[i - 1].Distance + Vector2.Distance(val, array[i - 1].Point);
				array[i] = new DistanceToPoint(distance, val);
			}
			float num = array[count].Distance / (float)count;
			DistanceToPoint[] array2 = new DistanceToPoint[count + 1];
			for (int j = 0; j <= count; j++)
			{
				float distance2 = (float)j * num;
				array2[j] = new DistanceToPoint(distance2, FindPositionForDistance(distance2, array));
			}
			return array2;
		}
	}
	public sealed class CameraHandler : MonoBehaviour
	{
		public enum CameraMode
		{
			Static,
			FollowPlayer,
			Disabled
		}

		private CameraZoomHandler _zoomHandler;

		private Camera[] _cameras;

		private float _refUpdateDelay = 0f;

		private Vector2 _targetPosition;

		private float _targetSize;

		private bool _isPickPhase = false;

		private bool _playersHaveSpawned = false;

		public static CameraMode Mode { get; set; } = CameraMode.FollowPlayer;


		public static float StaticZoom { get; set; } = 20f;


		private void Awake()
		{
			_zoomHandler = ((Component)this).GetComponent<CameraZoomHandler>();
		}

		private void OnEnable()
		{
			GameModeManager.AddHook("GameStart", (Func<IGameModeHandler, IEnumerator>)OnGameStart);
			GameModeManager.AddHook("PickStart", (Func<IGameModeHandler, IEnumerator>)OnPickStart);
			GameModeManager.AddHook("PickEnd", (Func<IGameModeHandler, IEnumerator>)OnPickEnd);
			GameModeManager.AddHook("PointStart", (Func<IGameModeHandler, IEnumerator>)OnPlayersActive);
			GameModeManager.AddHook("PointEnd", (Func<IGameModeHandler, IEnumerator>)OnPlayersInactive);
			GameModeManager.AddHook("RoundStart", (Func<IGameModeHandler, IEnumerator>)OnPlayersActive);
			GameModeManager.AddHook("RoundEnd", (Func<IGameModeHandler, IEnumerator>)OnPlayersInactive);
			if ((Object)(object)_zoomHandler != (Object)null)
			{
				((Behaviour)_zoomHandler).enabled = false;
			}
		}

		private void OnDisable()
		{
			GameModeManager.RemoveHook("GameStart", (Func<IGameModeHandler, IEnumerator>)OnGameStart);
			GameModeManager.RemoveHook("PickStart", (Func<IGameModeHandler, IEnumerator>)OnPickStart);
			GameModeManager.RemoveHook("PickEnd", (Func<IGameModeHandler, IEnumerator>)OnPickEnd);
			GameModeManager.RemoveHook("PointStart", (Func<IGameModeHandler, IEnumerator>)OnPlayersActive);
			GameModeManager.RemoveHook("PointEnd", (Func<IGameModeHandler, IEnumerator>)OnPlayersInactive);
			GameModeManager.RemoveHook("RoundStart", (Func<IGameModeHandler, IEnumerator>)OnPlayersActive);
			GameModeManager.RemoveHook("RoundEnd", (Func<IGameModeHandler, IEnumerator>)OnPlayersInactive);
			if ((Object)(object)_zoomHandler != (Object)null)
			{
				((Behaviour)_zoomHandler).enabled = true;
			}
		}

		private IEnumerator OnGameStart(IGameModeHandler gm)
		{
			if (GameModeManager.CurrentHandler.Name != "Sandbox")
			{
				UpdateTargets();
				ForceTargetPosition();
				ForceTargetSize();
			}
			yield break;
		}

		private IEnumerator OnPickStart(IGameModeHandler gm)
		{
			_isPickPhase = true;
			UpdateTargets();
			ForceTargetPosition();
			ForceTargetSize();
			yield break;
		}

		private IEnumerator OnPickEnd(IGameModeHandler gm)
		{
			_isPickPhase = false;
			yield break;
		}

		private IEnumerator OnPlayersActive(IGameModeHandler gm)
		{
			_playersHaveSpawned = true;
			yield break;
		}

		private IEnumerator OnPlayersInactive(IGameModeHandler gm)
		{
			_playersHaveSpawned = false;
			yield break;
		}

		private void Update()
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			((Behaviour)_zoomHandler).enabled = Mode == CameraMode.Disabled && !_isPickPhase;
			_refUpdateDelay -= Time.deltaTime;
			if (_refUpdateDelay <= 0f)
			{
				_cameras = ((Component)this).GetComponentsInChildren<Camera>();
				_refUpdateDelay = 1f;
			}
			if (Mode != CameraMode.Disabled)
			{
				UpdateTargets();
				LerpOrthographicSize(_targetSize);
				if (Mode != 0)
				{
					LerpPosition(_targetPosition);
				}
			}
		}

		internal void UpdateTargets()
		{
			//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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00bc: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0102: 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_010e: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: 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_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: 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_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			if (Mode == CameraMode.Static)
			{
				_targetSize = StaticZoom;
				return;
			}
			if (MapManager.instance.currentMap == null || _isPickPhase)
			{
				_targetSize = 20f;
				_targetPosition = Vector2.zero;
				return;
			}
			CustomMap currentCustomMap = MapManager.instance.GetCurrentCustomMap();
			if (currentCustomMap == null)
			{
				_targetSize = MapManager.instance.currentMap.Map.size;
				_targetPosition = Vector2.zero;
				return;
			}
			float aspect = MainCam.instance.cam.aspect;
			Vector2 mapSize = currentCustomMap.Settings.MapSize;
			Vector2 val = ConversionUtils.ScreenToWorldUnits(mapSize);
			Bounds val2 = default(Bounds);
			((Bounds)(ref val2))..ctor(Vector2.op_Implicit(Vector2.zero), Vector2.op_Implicit(val));
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor((float)currentCustomMap.Settings.ViewportHeight * aspect, (float)currentCustomMap.Settings.ViewportHeight);
			Vector2 val4 = ConversionUtils.ScreenToWorldUnits(val3);
			Vector2 val5 = Vector2.op_Implicit(((Bounds)(ref val2)).min) + val4 * 0.5f;
			Vector2 val6 = Vector2.op_Implicit(((Bounds)(ref val2)).max) - val4 * 0.5f;
			List<Bounds> list = new List<Bounds>();
			if (_playersHaveSpawned)
			{
				Bounds item = default(Bounds);
				foreach (Player item2 in PlayerManager.instance.players.Where(delegate(Player p)
				{
					int result;
					if (p == null)
					{
						result = 0;
					}
					else
					{
						CharacterData data = p.data;
						bool? obj;
						if (data == null)
						{
							obj = null;
						}
						else
						{
							PhotonView view = data.view;
							obj = ((view != null) ? new bool?(view.IsMine) : null);
						}
						result = ((obj == true) ? 1 : 0);
					}
					return (byte)result != 0;
				}))
				{
					float num = ((val3.x >= mapSize.x) ? 0f : Mathf.Clamp(((Component)item2).transform.position.x, val5.x, val6.x));
					float num2 = ((val3.y >= mapSize.y) ? 0f : Mathf.Clamp(((Component)item2).transform.position.y, val5.y, val6.y));
					((Bounds)(ref item))..ctor(Vector2.op_Implicit(new Vector2(num, num2)), Vector2.op_Implicit(val4));
					list.Add(item);
				}
			}
			float num3 = Mathf.Max(((Bounds)(ref val2)).size.y, ((Bounds)(ref val2)).size.x / aspect);
			Vector2 val7 = default(Vector2);
			((Vector2)(ref val7))..ctor(num3 * aspect, num3);
			Bounds val8 = (Bounds)((list.Count > 0) ? list[0] : new Bounds(Vector2.op_Implicit(Vector2.zero), Vector2.op_Implicit(val7)));
			for (int i = 1; i < list.Count; i++)
			{
				((Bounds)(ref val8)).Encapsulate(list[i]);
			}
			float num4 = Mathf.Max(((Bounds)(ref val8)).size.y, ((Bounds)(ref val8)).size.x / aspect);
			Vector2 val9 = default(Vector2);
			((Vector2)(ref val9))..ctor(num4 * aspect, num4);
			_targetSize = val9.y * 0.5f;
			Vector2 val10 = Vector2.op_Implicit(((Bounds)(ref val2)).min) + val9 * 0.5f;
			Vector2 val11 = Vector2.op_Implicit(((Bounds)(ref val2)).max) - val9 * 0.5f;
			float num5 = ((val9.x >= val.x) ? 0f : Mathf.Clamp(((Bounds)(ref val8)).center.x, val10.x, val11.x));
			float num6 = ((val9.y >= val.y) ? 0f : Mathf.Clamp(((Bounds)(ref val8)).center.y, val10.y, val11.y));
			_targetPosition = new Vector2(num5, num6);
		}

		private void LerpOrthographicSize(float size)
		{
			foreach (Camera item in _cameras.Where((Camera c) => ((Component)c).gameObject.activeInHierarchy))
			{
				item.orthographicSize = Mathf.Lerp(item.orthographicSize, size, Time.unscaledDeltaTime * 5f);
			}
		}

		private void LerpPosition(Vector2 position)
		{
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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)
			Vector3 val = default(Vector3);
			foreach (Camera item in _cameras.Where((Camera c) => ((Component)c).gameObject.activeInHierarchy))
			{
				((Vector3)(ref val))..ctor(position.x, position.y, ((Component)item).transform.position.z);
				((Component)item).transform.position = Vector3.Lerp(((Component)item).transform.position, val, Time.unscaledDeltaTime * 5f);
			}
		}

		internal void ForceTargetPosition()
		{
			//IL_005e: 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)
			foreach (Camera item in _cameras.Where((Camera c) => ((Component)c).gameObject.activeInHierarchy))
			{
				((Component)item).transform.position = new Vector3(_targetPosition.x, _targetPosition.y, ((Component)item).transform.position.z);
			}
		}

		internal void ForceTargetSize()
		{
			foreach (Camera item in _cameras.Where((Camera c) => ((Component)c).gameObject.activeInHierarchy))
			{
				item.orthographicSize = _targetSize;
			}
		}
	}
	public class CustomMap : ISerializationCallbackReceiver
	{
		[SerializeField]
		private readonly string _id;

		[SerializeField]
		private readonly string _name;

		[SerializeField]
		private readonly string _version;

		[SerializeField]
		private CustomMapSettings _settings;

		[SerializeField]
		private readonly MapObjectData[] _mapObjects;

		[NonSerialized]
		[Obsolete("Deprecated")]
		public string id;

		public string Id => _id;

		public string Name => _name;

		public string Version => _version;

		public CustomMapSettings Settings => _settings;

		public MapObjectData[] MapObjects => _mapObjects;

		public CustomMap(string id, string name, string version, CustomMapSettings settings, MapObjectData[] mapObjects)
		{
			_id = id;
			_name = name;
			_settings = settings;
			_mapObjects = mapObjects;
			_version = version;
			this.id = id;
		}

		void ISerializationCallbackReceiver.OnAfterDeserialize()
		{
			if (_mapObjects == null)
			{
				throw new Exception("Could not load map: " + (Name ?? "<unnamed>") + " (" + Id + ")");
			}
			if (_settings == null)
			{
				_settings = new CustomMapSettings();
			}
			for (int i = 0; i < _mapObjects.Length; i++)
			{
				if (_mapObjects[i] == null)
				{
					throw new Exception(string.Format("Could not load map: {0} ({1}) (index: {2})", Name ?? "<unnamed>", Id, i));
				}
			}
			id = _id;
		}

		public void OnBeforeSerialize()
		{
		}
	}
	public class CustomMapInfo
	{
		public string Id { get; private set; }

		public string Name { get; private set; }

		public string Version { get; private set; }

		public byte[] Data { get; private set; }

		public CustomMapInfo(string id, string name, string version, byte[] data)
		{
			Id = id;
			Name = name;
			Version = version;
			Data = data;
		}
	}
	public class CustomMapSettings
	{
		private static readonly Vector2 s_defaultMapSize = new Vector2(1920f, 1080f);

		private static readonly int s_defaultViewportSize = 1080;

		[SerializeField]
		private Vector2 _mapSize;

		[SerializeField]
		private int _viewportHeight;

		public static Vector2 DefaultMapSize => s_defaultMapSize;

		public static int DefaultViewportHeight => s_defaultViewportSize;

		public Vector2 MapSize
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return _mapSize;
			}
			set
			{
				//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)
				_mapSize = value;
			}
		}

		public int ViewportHeight
		{
			get
			{
				return _viewportHeight;
			}
			set
			{
				_viewportHeight = value;
			}
		}

		public CustomMapSettings()
			: this(DefaultMapSize, DefaultViewportHeight)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)


		public CustomMapSettings(CustomMapSettings settings)
			: this(settings.MapSize, settings.ViewportHeight)
		{
		}//IL_0002: Unknown result type (might be due to invalid IL or missing references)


		public CustomMapSettings(Vector2 mapSize, int viewportHeight)
		{
			//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)
			_mapSize = mapSize;
			_viewportHeight = viewportHeight;
		}
	}
	[RequireComponent(typeof(PolygonCollider2D))]
	public class EllipseCollider2D : MonoBehaviour
	{
		[SerializeField]
		private Vector2 _radius = Vector2.one;

		[SerializeField]
		private int _smoothness = 24;

		public Vector2 Radius
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return _radius;
			}
			set
			{
				//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)
				_radius = value;
				UpdatePath();
			}
		}

		public int Smoothness
		{
			get
			{
				return _smoothness;
			}
			set
			{
				_smoothness = value;
				UpdatePath();
			}
		}

		protected void Awake()
		{
			UpdatePath();
		}

		protected virtual void UpdatePath()
		{
			//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_004d: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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)
			float num = 360f / (float)_smoothness;
			PolygonCollider2D component = ((Component)this).gameObject.GetComponent<PolygonCollider2D>();
			List<Vector2> list = new List<Vector2>();
			for (int i = 0; i < _smoothness; i++)
			{
				Quaternion val = Quaternion.Euler(0f, 0f, (float)i * num);
				Vector3 val2 = val * Vector2.op_Implicit(new Vector2(0f, _radius.y));
				val2.x *= _radius.x / _radius.y;
				list.Add(Vector2.op_Implicit(val2));
			}
			component.SetPath(0, list.ToArray());
		}

		protected void OnValidate()
		{
			UpdatePath();
		}
	}
	public static class ManualLogSourceExtensions
	{
		public static void LogException(this ManualLogSource source, Exception ex)
		{
			string text = ex.Message + "\n" + ex.StackTrace;
			while (ex.InnerException != null)
			{
				ex = ex.InnerException;
				text = ex.StackTrace + "\n" + text;
			}
			MapsExtended.Log.LogError((object)text);
		}
	}
	public static class MapManagerExtensions
	{
		private class MapManagerExtraData
		{
			public CustomMap CurrentCustomMap { get; set; }
		}

		private static readonly ConditionalWeakTable<MapManager, MapManagerExtraData> s_extraData = new ConditionalWeakTable<MapManager, MapManagerExtraData>();

		public static void SetCurrentCustomMap(this MapManager mgr, CustomMap customMap)
		{
			MapManagerExtraData orCreateValue = s_extraData.GetOrCreateValue(mgr);
			orCreateValue.CurrentCustomMap = customMap;
		}

		public static CustomMap GetCurrentCustomMap(this MapManager mgr)
		{
			MapManagerExtraData orCreateValue = s_extraData.GetOrCreateValue(mgr);
			return orCreateValue.CurrentCustomMap;
		}
	}
	public static class MapObjectExtensions
	{
		public static MapObjectData ReadMapObject(this GameObject mapObject)
		{
			return MapObjectManager.Current.ReadMapObject(mapObject);
		}

		public static MapObjectData ReadMapObject(this Component comp)
		{
			return MapObjectManager.Current.ReadMapObject(comp.gameObject);
		}

		public static void WriteMapObject(this MapObjectData data, GameObject target)
		{
			MapObjectManager.Current.WriteMapObject(data, target);
		}
	}
	public static class PropertyExtensions
	{
		public static IProperty ReadProperty(this GameObject mapObject, Type propertyType)
		{
			return PropertyManager.Current.Read(mapObject, propertyType);
		}

		public static T ReadProperty<T>(this GameObject mapObject) where T : IProperty
		{
			return (T)mapObject.ReadProperty(typeof(T));
		}

		public static IEnumerable<IProperty> ReadProperties(this GameObject mapObject, Type propertyType)
		{
			return PropertyManager.Current.ReadAll(mapObject, propertyType);
		}

		public static IEnumerable<T> ReadProperties<T>(this GameObject mapObject) where T : IProperty
		{
			return mapObject.ReadProperties(typeof(T)).Cast<T>();
		}

		public static bool TryWriteProperty<T>(this GameObject mapObject, T prop) where T : IProperty
		{
			try
			{
				mapObject.WriteProperty(prop);
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static void WriteProperty<T>(this GameObject mapObject, T prop) where T : IProperty
		{
			PropertyManager.Current.Write(prop, mapObject);
		}

		public static T ReadProperty<T>(this Component comp) where T : IProperty
		{
			return comp.gameObject.ReadProperty<T>();
		}

		public static IProperty ReadProperty(this Component comp, Type propertyType)
		{
			return comp.gameObject.ReadProperty(propertyType);
		}

		public static void WriteProperty<T>(this Component comp, T prop) where T : IProperty
		{
			comp.gameObject.WriteProperty(prop);
		}

		public static bool TryWriteProperty<T>(this Component comp, T prop) where T : IProperty
		{
			return comp.gameObject.TryWriteProperty(prop);
		}
	}
	public static class ReflectionExtensions
	{
		public static object GetFieldOrPropertyValue(this MemberInfo info, object instance)
		{
			object? value;
			if (!(info is FieldInfo fieldInfo))
			{
				if (!(info is PropertyInfo propertyInfo))
				{
					throw new ArgumentException("MemberInfo must be of type FieldInfo or PropertyInfo");
				}
				value = propertyInfo.GetValue(instance);
			}
			else
			{
				value = fieldInfo.GetValue(instance);
			}
			return value;
		}

		public static bool HasFieldOrProperty(this Type type, Type returnType)
		{
			return type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy).Any((PropertyInfo p) => TypeExtensions.GetReturnType((MemberInfo)p) == returnType) || type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy).Any((FieldInfo p) => TypeExtensions.GetReturnType((MemberInfo)p) == returnType);
		}
	}
	public static class RoundsExtensions
	{
		private class ExtraRopeData
		{
			public Action<AnchoredJoint2D> ropeListener = delegate
			{
			};
		}

		internal class ExtraPlayerManagerData
		{
			public bool IsAnyPlayerBeingMoved => PlayersBeingMoved?.Any((bool p) => p) ?? false;

			public bool[] PlayersBeingMoved { get; set; } = new bool[0];

		}

		private static readonly ConditionalWeakTable<MapObjet_Rope, ExtraRopeData> s_ropeData = new ConditionalWeakTable<MapObjet_Rope, ExtraRopeData>();

		private static readonly ConditionalWeakTable<PlayerManager, ExtraPlayerManagerData> s_pmData = new ConditionalWeakTable<PlayerManager, ExtraPlayerManagerData>();

		internal static void OnJointAdded(this MapObjet_Rope instance, Action<AnchoredJoint2D> cb)
		{
			ExtraRopeData orCreateValue = s_ropeData.GetOrCreateValue(instance);
			orCreateValue.ropeListener = (Action<AnchoredJoint2D>)Delegate.Combine(orCreateValue.ropeListener, cb);
		}

		internal static void JointAdded(this MapObjet_Rope instance, AnchoredJoint2D joint)
		{
			s_ropeData.GetOrCreateValue(instance).ropeListener(joint);
		}

		internal static ExtraPlayerManagerData GetExtraData(this PlayerManager instance)
		{
			return s_pmData.GetOrCreateValue(instance);
		}
	}
	public static class VectorExtensions
	{
		public static Vector3 Round(this Vector3 vector, int decimalPlaces)
		{
			//IL_0001: 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_001d: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3((float)Math.Round(vector.x, decimalPlaces), (float)Math.Round(vector.y, decimalPlaces), (float)Math.Round(vector.z, decimalPlaces));
		}

		public static Vector2 Round(this Vector2 vector, int decimalPlaces)
		{
			//IL_0001: 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_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_0025: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2((float)Math.Round(vector.x, decimalPlaces), (float)Math.Round(vector.y, decimalPlaces));
		}
	}
	public sealed class LightHandler : MonoBehaviour
	{
		private const float DefaultParticleBoundsX = 80f;

		private const float DefaultParticleBoundsY = 60f;

		private const float DefaultParticleBoundsArea = 4800f;

		private const int DefaultMaxParticles = 1000;

		private const int DefaultParticleEmissionRate = 50;

		private const float DefaultLightAreaX = 200f;

		private const float DefaultLightAreaY = 200f;

		private const float DefaultMapSizeX = 71.12f;

		private const float DefaultMapSizeY = 40f;

		private ParticleSystem[] _particleSystems;

		private SFLight[] _lights;

		private void Start()
		{
			_particleSystems = ((Component)this).GetComponentsInChildren<ParticleSystem>(true);
			_lights = ((Component)this).GetComponentsInChildren<SFLight>(true);
		}

		private void Update()
		{
			//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_0015: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b6: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			Vector2 currentMapWorldSize = GetCurrentMapWorldSize();
			float num = currentMapWorldSize.x / 71.12f;
			float num2 = currentMapWorldSize.y / 40f;
			float num3 = Mathf.Max(80f, 80f * num);
			float num4 = Mathf.Max(60f, 60f * num2);
			float num5 = num3 * num4;
			float num6 = num5 / 4800f;
			float num7 = 1000f * num6;
			float num8 = 50f * num6;
			ParticleSystem[] particleSystems = _particleSystems;
			foreach (ParticleSystem val in particleSystems)
			{
				ShapeModule shape = val.shape;
				((ShapeModule)(ref shape)).scale = new Vector3(num3, num4, ((ShapeModule)(ref shape)).scale.z);
				MainModule main = val.main;
				EmissionModule emission = val.emission;
				((MainModule)(ref main)).maxParticles = (int)Mathf.Max(1000f, num7);
				((EmissionModule)(ref emission)).rateOverTimeMultiplier = (int)Mathf.Max(50f, num8);
			}
			float num9 = Mathf.Max(200f, 200f * num);
			float num10 = Mathf.Max(200f, 200f * num2);
			SFLight[] lights = _lights;
			Vector2 val3 = default(Vector2);
			foreach (SFLight val2 in lights)
			{
				RectTransform component = ((Component)val2).GetComponent<RectTransform>();
				((Vector2)(ref val3))..ctor(num9, num10);
				component.sizeDelta = Vector2.Lerp(component.sizeDelta, val3, Time.deltaTime * 5f);
			}
		}

		private Vector2 GetCurrentMapWorldSize()
		{
			//IL_002d: 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_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_003a: Unknown result type (might be due to invalid IL or missing references)
			CustomMap currentCustomMap = MapManager.instance.GetCurrentCustomMap();
			if (currentCustomMap == null)
			{
				return new Vector2(71.12f, 40f);
			}
			return ConversionUtils.ScreenToWorldUnits(currentCustomMap.Settings.MapSize);
		}
	}
	public class MapObjectAnchor : MonoBehaviour
	{
		private Vector2 _targetLocalPosition;

		public GameObject Target { get; private set; }

		public bool IsAttached => (Object)(object)Target != (Object)(object)((Component)this).gameObject;

		protected virtual void Awake()
		{
			Target = ((Component)this).gameObject;
		}

		protected virtual void Update()
		{
			if (IsAttached)
			{
				UpdatePosition();
			}
		}

		private void UpdatePosition()
		{
			//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)
			((Component)this).transform.position = Vector2.op_Implicit(GetAnchoredPosition());
		}

		public Vector2 GetAnchoredPosition()
		{
			//IL_0031: 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_0045: 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_0022: 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)
			if ((Object)(object)Target == (Object)null)
			{
				return Vector2.op_Implicit(((Component)this).transform.position);
			}
			return Vector2.op_Implicit(Target.transform.TransformPoint(Vector2.op_Implicit(_targetLocalPosition)));
		}

		public void UpdateAttachment()
		{
			//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)
			//IL_000e: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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)
			Vector3 position = ((Component)this).transform.position;
			Collider2D[] array = Physics2D.OverlapPointAll(Vector2.op_Implicit(position));
			Collider2D val = Array.Find(array, (Collider2D c) => (Object)(object)((Component)c).gameObject.GetComponent<MapObjectInstance>() != (Object)null && (Object)(object)((Component)c).gameObject == (Object)(object)Target) ?? Array.Find(array, (Collider2D c) => (Object)(object)((Component)c).gameObject.GetComponent<MapObjectInstance>() != (Object)null);
			if ((Object)(object)val == (Object)null)
			{
				Detach();
			}
			else if ((Object)(object)((Component)val).gameObject != (Object)(object)Target)
			{
				Target = ((Component)val).gameObject;
				_targetLocalPosition = Vector2.op_Implicit(Target.transform.InverseTransformPoint(position));
			}
		}

		public void Detach()
		{
			//IL_000f: 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)
			Target = ((Component)this).gameObject;
			_targetLocalPosition = Vector2.zero;
		}
	}
	public class MapObjectAnimation : MonoBehaviour
	{
		private class RigidBodyParams
		{
			public float gravityScale;

			public bool isKinematic;

			public bool useFullKinematicContacts;

			public RigidBodyParams(Rigidbody2D rb)
			{
				gravityScale = rb.gravityScale;
				isKinematic = rb.isKinematic;
				useFullKinematicContacts = rb.useFullKinematicContacts;
			}
		}

		private const float SyncThreshold = 1f / 60f;

		private float _elapsedTime;

		private int _currentFrameIndex;

		private bool _mapEntered;

		private string _rpcKey;

		public List<AnimationKeyframe> Keyframes { get; set; } = new List<AnimationKeyframe>();


		public bool PlayOnAwake { get; set; } = true;


		public bool IsPlaying { get; private set; }

		protected virtual void Awake()
		{
			Rigidbody2D orAddComponent = ExtensionMethods.GetOrAddComponent<Rigidbody2D>(((Component)this).gameObject, false);
			orAddComponent.gravityScale = 0f;
			orAddComponent.constraints = (RigidbodyConstraints2D)7;
			orAddComponent.isKinematic = true;
			orAddComponent.useFullKinematicContacts = true;
		}

		protected virtual void OnEnable()
		{
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 1, (Action)delegate
			{
				PhotonMapObject component = ((Component)this).GetComponent<PhotonMapObject>();
				if ((!Object.op_Implicit((Object)(object)component) || (bool)ExtensionMethods.GetFieldValue((object)component, "photonSpawned")) && PlayOnAwake)
				{
					Play();
				}
			});
		}

		protected virtual void OnDisable()
		{
			Stop();
		}

		protected virtual void Start()
		{
			Map componentInParent = ((Component)this).GetComponentInParent<Map>();
			_mapEntered = componentInParent.hasEntered;
			componentInParent.mapIsReadyAction = (Action)Delegate.Combine(componentInParent.mapIsReadyAction, (Action)delegate
			{
				_mapEntered = true;
			});
			componentInParent.mapMovingOutAction = (Action)Delegate.Combine(componentInParent.mapMovingOutAction, (Action)delegate
			{
				_mapEntered = false;
			});
			_rpcKey = string.Format("MapObject {0} {1}", ExtensionMethods.GetFieldValue((object)componentInParent, "levelID"), ((Component)this).transform.GetSiblingIndex());
			ChildRPC component = ((Component)MapManager.instance).GetComponent<ChildRPC>();
			component.childRPCsVector2[_rpcKey] = RPCA_SyncAnimation;
		}

		private void OnDestroy()
		{
			MapManager instance = MapManager.instance;
			ChildRPC val = ((instance != null) ? ((Component)instance).GetComponent<ChildRPC>() : null);
			if (_rpcKey != null && val.childRPCsVector2.ContainsKey(_rpcKey))
			{
				val.childRPCsVector2.Remove(_rpcKey);
			}
		}

		protected virtual void Update()
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (!IsPlaying || !_mapEntered || PlayerManager.instance.GetExtraData().IsAnyPlayerBeingMoved)
			{
				return;
			}
			ApplyKeyframe(_currentFrameIndex, _elapsedTime);
			_elapsedTime += TimeHandler.deltaTime;
			if (_currentFrameIndex == 0 || _elapsedTime > Keyframes[_currentFrameIndex].Duration)
			{
				_elapsedTime -= ((_currentFrameIndex == 0) ? 0f : Keyframes[_currentFrameIndex].Duration);
				_currentFrameIndex = (_currentFrameIndex + 1) % Keyframes.Count;
				if (PhotonNetwork.IsMasterClient)
				{
					((Component)MapManager.instance).GetComponent<ChildRPC>().CallFunction(_rpcKey, new Vector2((float)_currentFrameIndex, _elapsedTime));
				}
			}
		}

		public void Initialize(AnimationKeyframe keyFrame)
		{
			Keyframes.Clear();
			Keyframes.Add(keyFrame);
		}

		public void Play()
		{
			IsPlaying = true;
			_elapsedTime = 0f;
			_currentFrameIndex = 0;
		}

		public void Stop()
		{
			IsPlaying = false;
		}

		private void ApplyKeyframe(int frameIndex, float time = 0f)
		{
			if (frameIndex <= Keyframes.Count - 1)
			{
				AnimationKeyframe animationKeyframe = ((frameIndex > 0) ? Keyframes[frameIndex - 1] : Keyframes[0]);
				AnimationKeyframe animationKeyframe2 = Keyframes[frameIndex];
				float t = animationKeyframe2.Curve.EvaluateForDistance(time / animationKeyframe2.Duration);
				for (int i = 0; i < animationKeyframe.ComponentValues.Count; i++)
				{
					ILinearProperty linearProperty = animationKeyframe.ComponentValues[i];
					ILinearProperty componentValue = animationKeyframe2.GetComponentValue(linearProperty.GetType());
					IProperty property = linearProperty.Lerp(componentValue, t);
					MapsExtended.PropertyManager.Write(property, ((Component)this).gameObject);
				}
			}
		}

		private void RPCA_SyncAnimation(Vector2 frameAndTime)
		{
			int num = (int)((Vector2)(ref frameAndTime))[0];
			float num2 = ((Vector2)(ref frameAndTime))[1];
			if (_currentFrameIndex != num || Mathf.Abs(_elapsedTime - num2) > 1f / 60f)
			{
				_currentFrameIndex = num;
				_elapsedTime = num2;
			}
		}
	}
	public abstract class MapObjectManager : MonoBehaviour
	{
		private static AssetBundle s_mapObjectBundle;

		private readonly Dictionary<Type, IMapObjectSerializer> _serializers = new Dictionary<Type, IMapObjectSerializer>();

		private readonly Dictionary<Type, IMapObject> _mapObjects = new Dictionary<Type, IMapObject>();

		public static MapObjectManager Current { get; set; }

		public static TObj LoadCustomAsset<TObj>(string name) where TObj : Object
		{
			return s_mapObjectBundle.LoadAsset<TObj>(name);
		}

		protected virtual void Awake()
		{
			if ((Object)(object)s_mapObjectBundle == (Object)null)
			{
				s_mapObjectBundle = AssetUtils.LoadAssetBundleFromResources("mapobjects", typeof(NetworkedMapObjectManager).Assembly);
			}
		}

		public virtual void RegisterMapObject(Type dataType, IMapObject mapObject, IMapObjectSerializer serializer)
		{
			if ((Object)(object)mapObject.Prefab == (Object)null)
			{
				throw new ArgumentException("Prefab cannot be null");
			}
			if (_mapObjects.ContainsKey(dataType))
			{
				throw new ArgumentException(dataType.Name + " is already registered");
			}
			_mapObjects[dataType] = mapObject;
			_serializers[dataType] = serializer;
		}

		protected IMapObject GetMapObject(Type dataType)
		{
			return CollectionExtensions.GetValueOrDefault<Type, IMapObject>((IReadOnlyDictionary<Type, IMapObject>)_mapObjects, dataType) ?? throw new ArgumentException($"Map object type not registered: {dataType}");
		}

		protected IMapObjectSerializer GetSerializer(Type dataType)
		{
			return CollectionExtensions.GetValueOrDefault<Type, IMapObjectSerializer>((IReadOnlyDictionary<Type, IMapObjectSerializer>)_serializers, dataType) ?? throw new ArgumentException($"Map object type not registered: {dataType}");
		}

		public void WriteMapObject(MapObjectData data, GameObject target)
		{
			GetSerializer(data.GetType()).WriteMapObject(data, target);
		}

		public MapObjectData ReadMapObject(GameObject go)
		{
			return ReadMapObject(go.GetComponent<MapObjectInstance>());
		}

		public MapObjectData ReadMapObject(MapObjectInstance mapObjectInstance)
		{
			if ((Object)(object)mapObjectInstance == (Object)null)
			{
				throw new ArgumentNullException("mapObjectInstance");
			}
			if (mapObjectInstance.DataType == null)
			{
				throw new ArgumentException("Cannot read map object (" + ((Object)((Component)mapObjectInstance).gameObject).name + "): null DataType");
			}
			Type dataType = mapObjectInstance.DataType;
			IMapObjectSerializer serializer = GetSerializer(dataType);
			return serializer.ReadMapObject(mapObjectInstance);
		}

		public void Instantiate<TData>(Transform parent, Action<GameObject> onInstantiate = null) where TData : MapObjectData
		{
			Instantiate(typeof(TData), parent, onInstantiate);
		}

		public void Instantiate(Type dataType, Transform parent, Action<GameObject> onInstantiate = null)
		{
			MapObjectData data = (MapObjectData)Activator.CreateInstance(dataType);
			Instantiate(data, parent, onInstantiate);
		}

		public abstract void Instantiate(MapObjectData data, Transform parent, Action<GameObject> onInstantiate = null);
	}
	public class MapObjectSerializationException : Exception
	{
		public MapObjectSerializationException()
		{
		}

		public MapObjectSerializationException(string message)
			: base(message)
		{
		}

		public MapObjectSerializationException(string message, Exception innerException)
			: base(message, innerException)
		{
		}
	}
	[Obsolete("Deprecated")]
	public class MapObjectSpecSerializer : IMapObjectSerializer
	{
		protected DeserializerAction<MapObjectData> Writer { get; }

		protected SerializerAction<MapObjectData> Reader { get; }

		public MapObjectSpecSerializer(DeserializerAction<MapObjectData> deserializer, SerializerAction<MapObjectData> serializer)
		{
			Writer = deserializer ?? throw new ArgumentException("Deserializer cannot be null");
			Reader = serializer ?? throw new ArgumentException("Serializer cannot be null");
		}

		public void WriteMapObject(MapObjectData data, GameObject target)
		{
			try
			{
				MapObjectInstance orAddComponent = ExtensionMethods.GetOrAddComponent<MapObjectInstance>(target, false);
				orAddComponent.MapObjectId = data.MapObjectId ?? Guid.NewGuid().ToString();
				orAddComponent.DataType = data.GetType();
				target.SetActive(data.Active);
				Writer(data, target);
			}
			catch (Exception innerException)
			{
				throw new MapObjectSerializationException($"Could not deserialize {data.GetType()} into {((Object)target).name}", innerException);
			}
		}

		public MapObjectData ReadMapObject(MapObjectInstance mapObjectInstance)
		{
			try
			{
				MapObjectData mapObjectData = (MapObjectData)Activator.CreateInstance(mapObjectInstance.DataType);
				mapObjectData.MapObjectId = mapObjectInstance.MapObjectId;
				mapObjectData.Active = ((Component)mapObjectInstance).gameObject.activeSelf;
				Reader(((Component)mapObjectInstance).gameObject, mapObjectData);
				return mapObjectData;
			}
			catch (Exception innerException)
			{
				throw new MapObjectSerializationException("Could not serialize " + ((Object)((Component)mapObjectInstance).gameObject).name, innerException);
			}
		}
	}
	[BepInDependency("com.willis.rounds.unbound", "3.2.8")]
	[BepInPlugin("io.olavim.rounds.mapsextended", "MapsExtended", "1.4.2")]
	public sealed class MapsExtended : BaseUnityPlugin
	{
		private class VirtualMapObject : IMapObject
		{
			public GameObject Prefab { get; }

			public VirtualMapObject(GameObject prefab)
			{
				Prefab = prefab;
			}

			public void OnInstantiate(GameObject instance)
			{
			}

			public virtual void OnWrite(GameObject instance, MapObjectData data)
			{
			}
		}

		public const string ModId = "io.olavim.rounds.mapsextended";

		public const string ModName = "MapsExtended";

		public const string ModVersion = "1.4.2";

		[Obsolete("Deprecated")]
		public static MapsExtended instance;

		internal static ManualLogSource Log;

		[Obsolete("Map objects are registered automatically")]
		public Action<Assembly> RegisterMapObjectsAction;

		[Obsolete("Deprecated")]
		public List<CustomMap> maps = new List<CustomMap>();

		private readonly Dictionary<PhotonMapObject, Action<GameObject>> _photonInstantiationListeners = new Dictionary<PhotonMapObject, Action<GameObject>>();

		private readonly PropertyManager _propertyManager = new PropertyManager();

		private NetworkedMapObjectManager _mapObjectManager;

		private List<(CustomMapInfo mapInfo, string path)> _mapInfos;

		private Dictionary<string, CustomMap> _loadedMaps;

		private Dictionary<Type, ICompatibilityPatch> _compatibilityPatches = new Dictionary<Type, ICompatibilityPatch>();

		internal static MapsExtended Instance { get; private set; }

		public static NetworkedMapObjectManager MapObjectManager => Instance._mapObjectManager;

		public static PropertyManager PropertyManager => Instance._propertyManager;

		[Obsolete("Deprecated")]
		public static IEnumerable<CustomMap> LoadedMaps => Instance._loadedMaps.Values.Concat(Instance.maps);

		private void Awake()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			instance = this;
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			AssetUtils.LoadAssetBundleFromResources("mapbase", typeof(MapsExtended).Assembly);
			GameObject val = new GameObject("Root Map Object Manager");
			Object.DontDestroyOnLoad((Object)(object)val);
			_mapObjectManager = val.AddComponent<NetworkedMapObjectManager>();
			_mapObjectManager.SetNetworkID("io.olavim.rounds.mapsextended/RootMapObjectManager");
			MainMenuHandler.Awake += (hook_Awake)delegate(orig_Awake orig, MainMenuHandler self)
			{
				orig.Invoke(self);
				((Component)((Component)MainCam.instance.cam).GetComponentInParent<CameraZoomHandler>()).gameObject.AddComponent<CameraHandler>();
				GameObject.Find("/Game/Visual/Rendering /").AddComponent<LightHandler>();
				OnInit();
			};
		}

		private void Start()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("io.olavim.rounds.mapsextended").PatchAll();
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				RegisterMapObjectProperties(assembly);
				RegisterMapObjects(assembly);
			}
			ApplyCompatibilityPatches();
		}

		private static void RefreshLevelMenu()
		{
			if ((Object)(object)ToggleLevelMenuHandler.instance != (Object)null)
			{
				AccessTools.Field(typeof(ToggleLevelMenuHandler), "ScrollViews").SetValue(null, new Dictionary<string, Transform>());
				Object.Destroy((Object)(object)ToggleLevelMenuHandler.instance.mapMenuCanvas);
				Object.Destroy((Object)(object)((Component)Unbound.Instance).gameObject.GetComponent<ToggleLevelMenuHandler>());
				((Component)Unbound.Instance).gameObject.AddComponent<ToggleLevelMenuHandler>();
			}
		}

		private void OnInit()
		{
			PropertyManager.Current = Instance._propertyManager;
			MapsExt.MapObjectManager.Current = Instance._mapObjectManager;
			RefreshLevelMenu();
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 1, (Action)delegate
			{
				UpdateMapFiles();
			});
		}

		private void Update()
		{
			Debug.developerConsoleVisible = false;
		}

		private void ApplyCompatibilityPatches()
		{
			Type[] assemblyTypes = ReflectionUtils.GetAssemblyTypes(Assembly.GetExecutingAssembly());
			foreach (Type item in assemblyTypes.Where((Type t) => Attribute.IsDefined(t, typeof(CompatibilityPatchAttribute))))
			{
				if (!TypeExtensions.ImplementsOrInherits(item, typeof(ICompatibilityPatch)))
				{
					throw new Exception($"Compatibility patch {item} does not implement {typeof(ICompatibilityPatch).Name}");
				}
				ICompatibilityPatch patch = (ICompatibilityPatch)Activator.CreateInstance(item);
				_compatibilityPatches.Add(item, patch);
				ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 1, (Action)delegate
				{
					patch.Apply();
				});
			}
		}

		public static T GetCompatibilityPatch<T>() where T : ICompatibilityPatch
		{
			T val = (T)CollectionExtensions.GetValueOrDefault<Type, ICompatibilityPatch>((IReadOnlyDictionary<Type, ICompatibilityPatch>)Instance._compatibilityPatches, typeof(T), (ICompatibilityPatch)null);
			if (val == null)
			{
				throw new ArgumentException($"No compatibility patch of type {typeof(T)} loaded");
			}
			return val;
		}

		[Obsolete("Map objects are registered automatically")]
		public void RegisterMapObjects()
		{
		}

		private void RegisterMapObjectProperties(Assembly assembly)
		{
			Type[] assemblyTypes = ReflectionUtils.GetAssemblyTypes(assembly);
			foreach (Type item in assemblyTypes.Where((Type t) => Attribute.IsDefined(t, typeof(PropertySerializerAttribute))))
			{
				try
				{
					PropertySerializerAttribute customAttribute = TypeExtensions.GetCustomAttribute<PropertySerializerAttribute>(item);
					Type propertyType = customAttribute.PropertyType;
					object serializer = Activator.CreateInstance(item);
					LazyPropertySerializer serializer2 = new LazyPropertySerializer(serializer, propertyType);
					_propertyManager.RegisterProperty(propertyType, serializer2);
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Could not register map object serializer " + item.Name + ": " + ex.Message));
					Log.LogError((object)ex.StackTrace);
				}
			}
		}

		private void RegisterMapObjects(Assembly assembly)
		{
			PropertyCompositeSerializer serializer = new PropertyCompositeSerializer(_propertyManager);
			Type[] assemblyTypes = ReflectionUtils.GetAssemblyTypes(assembly);
			foreach (Type item in assemblyTypes.Where((Type t) => Attribute.IsDefined(t, typeof(MapObjectAttribute))))
			{
				try
				{
					MapObjectAttribute customAttribute = TypeExtensions.GetCustomAttribute<MapObjectAttribute>(item);
					Type dataType = customAttribute.DataType;
					if (!typeof(MapObjectData).IsAssignableFrom(dataType))
					{
						throw new Exception($"Data type {item.Name} is not assignable to {typeof(MapObjectData)}");
					}
					if (!typeof(IMapObject).IsAssignableFrom(item))
					{
						throw new Exception($"{item.Name} is not assignable to {typeof(IMapObject)}");
					}
					if (item.GetConstructor(Type.EmptyTypes) == null)
					{
						throw new Exception(item.Name + " does not have a default constructor");
					}
					IMapObject mapObject = (IMapObject)AccessTools.CreateInstance(item);
					_mapObjectManager.RegisterMapObject(dataType, mapObject, serializer);
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Could not register map object " + item.Name + ": " + ex.Message));
					Log.LogError((object)ex.StackTrace);
				}
			}
			RegisterV0MapObjects(assembly);
		}

		private void UpdateMapFiles()
		{
			//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)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0093: Expected O, but got Unknown
			//IL_0099: Expected O, but got Unknown
			//IL_009c: Expected O, but got Unknown
			LevelManager.RemoveLevels(LevelManager.levels.Keys.Where((string m) => m.StartsWith("MapsExtended:")).ToArray());
			string[] files = Directory.GetFiles(Paths.PluginPath, "*.map", SearchOption.AllDirectories);
			string path = Path.Combine(Paths.GameRootPath, "maps");
			Directory.CreateDirectory(path);
			string[] files2 = Directory.GetFiles(path, "*.map", SearchOption.AllDirectories);
			List<(CustomMapInfo, string)> list = new List<(CustomMapInfo, string)>();
			DeserializationContext context = new DeserializationContext
			{
				Config = new SerializationConfig
				{
					DebugContext = new DebugContext
					{
						ErrorHandlingPolicy = (ErrorHandlingPolicy)1
					}
				}
			};
			string[] array = files2;
			foreach (string text in array)
			{
				try
				{
					list.Add((MapLoader.LoadInfoFromPath(text, context), text));
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogException(ex);
				}
			}
			Dictionary<string, List<(CustomMapInfo, string)>> dictionary = new Dictionary<string, List<(CustomMapInfo, string)>>();
			string[] array2 = files;
			foreach (string text2 in array2)
			{
				string text3 = Path.GetDirectoryName(text2).Replace("_", " ");
				if (text3.Contains("-"))
				{
					text3 = text3.Substring(text3.LastIndexOf("-") + 1);
				}
				text3 = text3.Trim();
				if (!dictionary.ContainsKey(text3))
				{
					dictionary[text3] = new List<(CustomMapInfo, string)>();
				}
				try
				{
					dictionary[text3].Add((MapLoader.LoadInfoFromPath(text2, context), text2));
				}
				catch (Exception ex2)
				{
					((BaseUnityPlugin)this).Logger.LogException(ex2);
				}
			}
			_loadedMaps = new Dictionary<string, CustomMap>();
			_mapInfos = new List<(CustomMapInfo, string)>();
			_mapInfos.AddRange(list);
			foreach (List<(CustomMapInfo, string)> value in dictionary.Values)
			{
				_mapInfos.AddRange(value);
			}
			((BaseUnityPlugin)this).Logger.LogMessage((object)$"Loaded {_mapInfos.Count} custom maps");
			RegisterNamedMaps(list, "Personal");
			foreach (string key in dictionary.Keys)
			{
				RegisterNamedMaps(dictionary[key], key);
			}
			((MonoBehaviour)this).StartCoroutine(ValidateMaps());
		}

		private IEnumerator ValidateMaps()
		{
			int taskCount = (int)Mathf.Ceil((float)_mapInfos.Count / 5f);
			List<Task> tasks = new List<Task>();
			ConcurrentBag<string> invalidMaps = new ConcurrentBag<string>();
			for (int i = 0; i < taskCount; i++)
			{
				List<(CustomMapInfo mapInfo, string path)> mapInfos = _mapInfos.Skip(i * 5).Take(5).ToList();
				tasks.Add(Task.Run(delegate
				{
					//IL_0035: Unknown result type (might be due to invalid IL or missing references)
					//IL_003f: Expected O, but got Unknown
					//IL_003a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0041: Expected O, but got Unknown
					//IL_0042: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
					//IL_00aa: Invalid comparison between Unknown and I4
					string text = default(string);
					string text2 = default(string);
					foreach (var item2 in mapInfos)
					{
						CustomMapInfo item = item2.mapInfo;
						try
						{
							using MemoryStream memoryStream = new MemoryStream(item.Data);
							List<string> list = new List<string>();
							JsonTextReader val = new JsonTextReader((Stream)memoryStream, new DeserializationContext());
							try
							{
								EntryType val2 = (EntryType)0;
								while ((int)val2 != 15)
								{
									val.ReadToNextEntry(ref text, ref text2, ref val2);
									if (text == "$type" && text2.StartsWith("\""))
									{
										list.Add(text2.Trim(new char[1] { '"' }).Split(new char[1] { '|' })[1]);
									}
								}
								MapLoader mapLoader = MapLoader.ForVersion(item.Version);
								foreach (string item3 in list)
								{
									Type type = mapLoader.Context.Binder.BindToType(item3, (DebugContext)null);
									if (type == null)
									{
										invalidMaps.Add(item.Id);
										throw new Exception("Could not load map " + item.Name + ": Missing type \"" + item3 + "\"");
									}
								}
							}
							finally
							{
								((IDisposable)val)?.Dispose();
							}
						}
						catch (Exception ex)
						{
							((BaseUnityPlugin)this).Logger.LogError((object)ex.Message);
						}
					}
				}));
			}
			while (tasks.Any((Task t) => !t.IsCompleted))
			{
				yield return null;
			}
			if (invalidMaps.Count <= 0)
			{
				yield break;
			}
			_mapInfos.RemoveAll(((CustomMapInfo mapInfo, string path) m) => invalidMaps.Contains(m.mapInfo.Id));
			foreach (string id2 in invalidMaps)
			{
				_loadedMaps.Remove(id2);
			}
			LevelManager.RemoveLevels(invalidMaps.Select((string id) => "MapsExtended:" + id).ToArray());
			RefreshLevelMenu();
		}

		private void RegisterNamedMaps(IEnumerable<(CustomMapInfo, string)> maps, string category)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (var map in maps)
			{
				CustomMapInfo item = map.Item1;
				dictionary["MapsExtended:" + item.Id] = item.Name;
			}
			LevelManager.RegisterNamedMaps((IEnumerable<string>)dictionary.Keys, (IDictionary<string, string>)dictionary, category);
		}

		internal CustomMap GetMapById(string id)
		{
			if (!_loadedMaps.ContainsKey(id))
			{
				(CustomMapInfo, string) tuple = _mapInfos.FirstOrDefault(((CustomMapInfo mapInfo, string path) m) => m.mapInfo.Id == id);
				CustomMapInfo customMapInfo;
				string text;
				(customMapInfo, text) = tuple;
				if (customMapInfo == null && text == null)
				{
					throw new ArgumentException("No map with id " + id + " found");
				}
				Dictionary<string, CustomMap> loadedMaps = _loadedMaps;
				string key = id;
				(CustomMapInfo, string) tuple3 = tuple;
				customMapInfo = tuple3.Item1;
				text = tuple3.Item2;
				loadedMaps[key] = ((customMapInfo == null && text == null) ? null : MapLoader.LoadPath(tuple.Item2));
			}
			return _loadedMaps[id];
		}

		internal static void AddPhotonInstantiateListener(PhotonMapObject mapObject, Action<GameObject> callback)
		{
			Instance._photonInstantiationListeners.Add(mapObject, callback);
		}

		internal static void OnPhotonInstantiate(GameObject instance, PhotonMapObject mapObject)
		{
			Instance._photonInstantiationListeners.TryGetValue(mapObject, out var value);
			if (value != null)
			{
				value(instance);
				Instance._photonInstantiationListeners.Remove(mapObject);
			}
		}

		[Obsolete("Use MapLoader.LoadPath instead")]
		private static CustomMap LoadMapData(string path)
		{
			return MapLoader.LoadPath(path);
		}

		public static void LoadMap(GameObject container, string mapFilePath, MapObjectManager mapObjectManager, Action onLoad = null)
		{
			CustomMap mapData = MapLoader.LoadPath(mapFilePath);
			LoadMap(container, mapData, mapObjectManager, onLoad);
		}

		public static void LoadMap(GameObject container, CustomMap mapData, MapObjectManager mapObjectManager, Action onLoad = null)
		{
			((MonoBehaviour)Instance).StartCoroutine(LoadMapCoroutine(container, mapData, mapObjectManager, onLoad));
		}

		private static IEnumerator LoadMapCoroutine(GameObject container, CustomMap mapData, MapObjectManager mapObjectManager, Action onLoad = null)
		{
			MapsExt.Utils.GameObjectUtils.DestroyChildrenImmediateSafe(container);
			int toLoad = mapData.MapObjects.Length;
			MapObjectData[] mapObjects = mapData.MapObjects;
			foreach (MapObjectData mapObject in mapObjects)
			{
				mapObjectManager.Instantiate(mapObject, container.transform, delegate
				{
					toLoad--;
				});
			}
			while (toLoad > 0)
			{
				yield return null;
			}
			onLoad?.Invoke();
		}

		private void RegisterV0MapObjects(Assembly assembly)
		{
			Type[] source;
			try
			{
				source = assembly.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				source = ex.Types.Where((Type t) => t != null).ToArray();
			}
			foreach (Type item in source.Where((Type t) => Attribute.IsDefined(t, typeof(MapObjectSpec))))
			{
				try
				{
					MapObjectSpec customAttribute = item.GetCustomAttribute<MapObjectSpec>();
					GameObject attributedProperty = ReflectionUtils.GetAttributedProperty<GameObject>(item, typeof(MapObjectPrefab));
					DeserializerAction<MapObjectData> attributedMethod = ReflectionUtils.GetAttributedMethod<DeserializerAction<MapObjectData>>(item, typeof(MapObjectDeserializer));
					SerializerAction<MapObjectData> attributedMethod2 = ReflectionUtils.GetAttributedMethod<SerializerAction<MapObjectData>>(item, typeof(MapObjectSerializer));
					MapObjectSpecSerializer serializer = new MapObjectSpecSerializer(attributedMethod, attributedMethod2);
					_mapObjectManager.RegisterMapObject(customAttribute.dataType, new VirtualMapObject(attributedProperty), serializer);
				}
				catch (Exception ex2)
				{
					Log.LogError((object)("Could not register legacy map object " + item.Name + ": " + ex2.Message));
					Log.LogError((object)ex2.StackTrace);
				}
			}
		}
	}
	[HarmonyPatch(typeof(MapManager))]
	internal static class MapManagerPatch
	{
		private static CustomMap s_loadedMap;

		private static string s_loadedMapSceneName;

		private static void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
		{
			if (MapManager.instance.currentMap != null)
			{
				MapManager.instance.currentMap.Map.wasSpawned = false;
			}
			SceneManager.sceneLoaded -= OnLevelFinishedLoading;
			Map val = (from obj in ((Scene)(ref scene)).GetRootGameObjects()
				select obj.GetComponent<Map>()).FirstOrDefault((Func<Map, bool>)((Map m) => (Object)(object)m != (Object)null));
			MapsExtended.LoadMap(((Component)val).gameObject, s_loadedMap, MapsExtended.MapObjectManager);
		}

		[HarmonyPrefix]
		[HarmonyPatch("RPCA_LoadLevel")]
		public static void Prefix_LoadLevel(ref string sceneName)
		{
			string obj = sceneName;
			if (obj != null && obj.StartsWith("MapsExtended:"))
			{
				string id = sceneName.Split(new char[1] { ':' })[1];
				s_loadedMap = MapsExtended.Instance.GetMapById(id);
				s_loadedMapSceneName = sceneName;
				MapManager.instance.SetCurrentCustomMap(s_loadedMap);
				sceneName = "NewMap";
				SceneManager.sceneLoaded += OnLevelFinishedLoading;
			}
			else
			{
				MapManager.instance.SetCurrentCustomMap(null);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("GetIDFromScene")]
		public static bool Prefix_GetIDFromScene(Scene scene, MapManager __instance, ref int __result)
		{
			if (((Scene)(ref scene)).name == "NewMap")
			{
				__result = __instance.levels.ToList().IndexOf(s_loadedMapSceneName);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MapManager), "GetSpawnPoints")]
	internal static class MapManagerPatch_GetSpawnPoints
	{
		public static void Postfix(ref SpawnPoint[] __result)
		{
			//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_0074: 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)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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)
			//IL_0102: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			List<SpawnPoint> list = __result.ToList();
			int count = PlayerManager.instance.players.Count;
			int num = PlayerManager.instance.players.Select((Player p) => p.teamID).Distinct().Count();
			if (list.Count == 0)
			{
				list.Add(new SpawnPoint
				{
					ID = 0,
					TEAMID = 0,
					localStartPos = Vector2.op_Implicit(Vector2.zero)
				});
			}
			while (list.Count < count)
			{
				SpawnPoint val = list[list.Count - 1];
				int count2 = list.Count;
				int tEAMID = list.Count % num;
				SpawnPoint val2 = ((list.Count > num) ? list[list.Count - 1 - num] : null);
				Vector3 localStartPos = (Object.op_Implicit((Object)(object)val2) ? val2.localStartPos : val.localStartPos);
				list.Add(new SpawnPoint
				{
					ID = count2,
					TEAMID = tEAMID,
					localStartPos = localStartPos
				});
			}
			__result = list.ToArray();
		}
	}
	[HarmonyPatch(typeof(MapTransition), "Toggle")]
	internal static class MapTransitionPatch_Toggle
	{
		public static void Postfix(GameObject obj, bool enabled)
		{
			MapObjectAnimation component = obj.GetComponent<MapObjectAnimation>();
			if (Object.op_Implicit((Object)(object)component))
			{
				((Behaviour)component).enabled = enabled;
			}
		}
	}
	[HarmonyPatch(typeof(MapTransition))]
	internal static class MapTransitionPatch_EnterExit
	{
		private class MapData
		{
			public bool Entered { get; set; }
		}

		private static readonly ConditionalWeakTable<Map, MapData> s_mapData = new ConditionalWeakTable<Map, MapData>();

		[HarmonyPatch("Enter")]
		[HarmonyPrefix]
		public static void EnterPrefix(Map map)
		{
			s_mapData.GetOrCreateValue(map).Entered = true;
		}

		[HarmonyPatch("Exit")]
		[HarmonyPrefix]
		public static bool ExitPrefix(Map map)
		{
			return s_mapData.GetOrCreateValue(map).Entered;
		}
	}
	[HarmonyPatch(typeof(MapObjet_Rope), "AddJoint")]
	internal static class RopePatch_AddJoint
	{
		public static void Postfix(MapObjet_Rope __instance, AnchoredJoint2D ___joint)
		{
			__instance.JointAdded(___joint);
		}
	}
	[HarmonyPatch(typeof(NetworkPhysicsObject), "BulletPush")]
	internal static class NetworkPhysicsObject_BulletPush
	{
		public static bool Prefix(NetworkPhysicsObject __instance)
		{
			return (Object)(object)((Component)__instance).gameObject.GetComponent<MapObjectAnimation>() == (Object)null;
		}
	}
	[HarmonyPatch(typeof(NetworkPhysicsObject), "Push")]
	internal static class NetworkPhysicsObject_Push
	{
		public static bool Prefix(NetworkPhysicsObject __instance)
		{
			return (Object)(object)((Component)__instance).gameObject.GetComponent<MapObjectAnimation>() == (Object)null;
		}
	}
	[HarmonyPatch(typeof(DamageBox), "Collide")]
	internal static class DamageBox_Collide
	{
		public static bool Prefix(Collision2D collision)
		{
			return ((Component)collision.transform).GetComponent<DamageableMapObjectInstance>()?.damageableByEnvironment ?? true;
		}

		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Expected O, but got Unknown
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			FieldInfo fieldInfo = AccessTools.Field(typeof(DamageBox), "shake");
			MethodInfo methodInfo = AccessTools.Method(typeof(Component), "GetComponent", (Type[])null, new Type[1] { typeof(CharacterData) });
			MethodInfo methodInfo2 = typeof(Object).GetMethods(BindingFlags.Static | BindingFlags.Public).First((MethodInfo mi) => mi.Name == "op_Implicit" && mi.ReturnType == typeof(bool));
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.IsLdloc(list[i], (LocalBuilder)null) && CodeInstructionExtensions.Calls(list[i + 1], methodInfo))
				{
					list2.Add(new CodeInstruction(OpCodes.Ldloc_1, (object)null));
					list2.Add(list[i + 1]);
					i++;
				}
				else if (CodeInstructionExtensions.IsLdarg(list[i], (int?)0) && CodeInstructionExtensions.LoadsField(list[i + 1], fieldInfo, false) && CodeInstructionExtensions.LoadsConstant(list[i + 2], 0.0))
				{
					list2.Add(new CodeInstruction(OpCodes.Ldloc_S, (object)4));
					list2.Add(new CodeInstruction(OpCodes.Call, (object)methodInfo2));
					list2.Add(new CodeInstruction(OpCodes.Brfalse, list[i + 3].operand));
					list2.Add(list[i]);
					list2.Add(list[i + 1]);
					list2.Add(list[i + 2]);
					list2.Add(list[i + 3]);
					i += 3;
				}
				else
				{
					list2.Add(list[i]);
				}
			}
			return list2;
		}
	}
	[HarmonyPatch(typeof(PhotonMapObject), "Start")]
	internal static class PhotonMapObjectPatch_Start
	{
		public static bool Prefix(PhotonMapObject __instance)
		{
			PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
			if (component != null && component.InstantiationData?.Length >= 1 && component.InstantiationData[0] as string == "lateInstantiated")
			{
				ExtensionMethods.SetFieldValue((object)__instance, "photonSpawned", (object)true);
				ExtensionMethods.SetFieldValue((object)__instance, "map", (object)((Component)__instance).GetComponentInParent<Map>());
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PhotonMapObject), "Update")]
	internal static class PhotonMapObjectPatch_Update
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			MethodInfo methodInfo = ExtensionMethods.GetMethodInfo(typeof(PhotonNetwork), "Instantiate");
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(list[i], methodInfo))
				{
					list2.Add(list[i]);
					list2.Add(new CodeInstruction(OpCodes.Ldarg_0, (object)null));
					list2.Add(CodeInstruction.Call(typeof(MapsExtended), "OnPhotonInstantiate", (Type[])null, (Type[])null));
					i++;
				}
				else
				{
					list2.Add(list[i]);
				}
			}
			return list2;
		}
	}
	[HarmonyPatch(typeof(Voice), "SetVolumeRatioUpdate")]
	internal static class SonigonDebugPatch
	{
		public static bool Prefix(SoundContainer ___soundContainer)
		{
			return (Object)(object)___soundContainer != (Object)null;
		}
	}
	[HarmonyPatch(typeof(PlayerManager), "MovePlayers")]
	internal static class PlayerManagerPatch_MovePlayers
	{
		public static void Prefix(PlayerManager __instance)
		{
			__instance.GetExtraData().PlayersBeingMoved = new bool[__instance.players.Count];
			for (int i = 0; i < __instance.players.Count; i++)
			{
				__instance.GetExtraData().PlayersBeingMoved[i] = true;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerManager), "Move")]
	internal static class GM_ArmsRace_Patch_PointTransition
	{
		public static IEnumerator Postfix(IEnumerator e, PlayerManager __instance, PlayerVelocity player)
		{
			while (e.MoveNext())
			{
				yield return e.Current;
			}
			int index = __instance.players.FindIndex((Player p) => (Object)(object)p.data.playerVel == (Object)(object)player);
			__instance.GetExtraData().PlayersBeingMoved[index] = false;
		}
	}
	[HarmonyPatch(typeof(OutOfBoundsHandler))]
	internal static class OutOfBoundsHandler_Patch
	{
		private static readonly MethodInfo m_minX = AccessTools.Method(typeof(OutOfBoundsHandler_Patch), "GetMinX", (Type[])null, (Type[])null);

		private static readonly MethodInfo m_maxX = AccessTools.Method(typeof(OutOfBoundsHandler_Patch), "GetMaxX", (Type[])null, (Type[])null);

		private static readonly MethodInfo m_minY = AccessTools.Method(typeof(OutOfBoundsHandler_Patch), "GetMinY", (Type[])null, (Type[])null);

		private static readonly MethodInfo m_maxY = AccessTools.Method(typeof(OutOfBoundsHandler_Patch), "GetMaxY", (Type[])null, (Type[])null);

		private static Vector2 GetMapSize()
		{
			//IL_002b: 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_001a: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			CustomMap currentCustomMap = MapManager.instance.GetCurrentCustomMap();
			return (Vector2)((currentCustomMap == null) ? new Vector2(71.12f, 40f) : ConversionUtils.ScreenToWorldUnits(currentCustomMap.Settings.MapSize));
		}

		private static float GetMinX()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return (0f - GetMapSize().x) * 0.5f;
		}

		private static float GetMaxX()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return GetMapSize().x * 0.5f;
		}

		private static float GetMinY()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return (0f - GetMapSize().y) * 0.5f;
		}

		private static float GetMaxY()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return GetMapSize().y * 0.5f;
		}

		private static IEnumerable<CodeInstruction> SwitchOutDefaultMapSizes(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction ins in instructions)
			{
				if (CodeInstructionExtensions.LoadsConstant(ins, -35.560001373291016))
				{
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Call, (object)m_minX), (IEnumerable<Label>)ins.labels);
				}
				else if (CodeInstructionExtensions.LoadsConstant(ins, 35.560001373291016))
				{
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Call, (object)m_maxX), (IEnumerable<Label>)ins.labels);
				}
				else if (CodeInstructionExtensions.LoadsConstant(ins, -20.0))
				{
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Call, (object)m_minY), (IEnumerable<Label>)ins.labels);
				}
				else if (CodeInstructionExtensions.LoadsConstant(ins, 20.0))
				{
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Call, (object)m_maxY), (IEnumerable<Label>)ins.labels);
				}
				else
				{
					yield return ins;
				}
			}
		}

		[HarmonyPatch("LateUpdate")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> OutOfBoundsHandler_Transpiler1(IEnumerable<CodeInstruction> instructions)
		{
			return SwitchOutDefaultMapSizes(instructions);
		}

		[HarmonyPatch("GetPoint")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> OutOfBoundsHandler_Transpiler2(IEnumerable<CodeInstruction> instructions)
		{
			return SwitchOutDefaultMapSizes(instructions);
		}
	}
	[HarmonyPatch(typeof(ScreenEdgeBounce), "Update")]
	internal static class ScreenEdgeBounce_Patch
	{
		private static Vector2 GetMapSize()
		{
			//IL_002b: 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_001a: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			CustomMap currentCustomMap = MapManager.instance.GetCurrentCustomMap();
			return (Vector2)((currentCustomMap == null) ? new Vector2(71.12f, 40f) : ConversionUtils.ScreenToWorldUnits(currentCustomMap.Settings.MapSize));
		}

		private static Vector3 GetNormalizedMapPosition(Vector3 worldPosition)
		{
			//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_0007: 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_001f: 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_0031: 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_0050: 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_0064: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			Vector2 mapSize = GetMapSize();
			float num = Mathf.Clamp(worldPosition.x + mapSize.x * 0.5f, 0f, mapSize.x);
			float num2 = Mathf.Clamp(worldPosition.y + mapSize.y * 0.5f, 0f, mapSize.y);
			return new Vector3(num / mapSize.x, num2 / mapSize.y, 0f);
		}

		private static Vector3 NormalizedMapPositionToWorldPosition(Vector3 normalizedPosition)
		{
			//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_0007: 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_001a: 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_002d: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			Vector2 mapSize = GetMapSize();
			return new Vector3(mapSize.x * (normalizedPosition.x - 0.5f), mapSize.y * (normalizedPosition.y - 0.5f), normalizedPosition.z);
		}

		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo m_normalizedMapPos = AccessTools.Method(typeof(ScreenEdgeBounce_Patch), "GetNormalizedMapPosition", (Type[])null, (Type[])null);
			MethodInfo m_normalizedMapPosToWorldPos = AccessTools.Method(typeof(ScreenEdgeBounce_Patch), "NormalizedMapPositionToWorldPosition", (Type[])null, (Type[])null);
			MethodInfo m_worldToScreenPoint = typeof(Camera).GetMethod("WorldToScreenPoint", new Type[1] { typeof(Vector3) });
			MethodInfo m_screenToWorldPoint = typeof(Camera).GetMethod("ScreenToWorldPoint", new Type[1] { typeof(Vector3) });
			MethodInfo m_screenWidth = typeof(Screen).GetProperty("width").GetGetMethod();
			MethodInfo m_screenHeight = typeof(Screen).GetProperty("height").GetGetMethod();
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (i < list.Count - 5 && CodeInstructionExtensions.IsLdarg(list[i], (int?)0) && CodeInstructionExtensions.Calls(list[i + 5], m_worldToScreenPoint))
				{
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Nop, (object)null), (IEnumerable<Label>)list[i].labels);
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Nop, (object)null), (IEnumerable<Label>)list[i + 1].labels);
					yield return list[i + 2];
					yield return list[i + 3];
					yield return list[i + 4];
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Call, (object)m_normalizedMapPos), (IEnumerable<Label>)list[i + 5].labels);
					i += 5;
				}
				else if (CodeInstructionExtensions.Calls(list[i], m_screenWidth))
				{
					yield return new CodeInstruction(OpCodes.Ldc_I4_1, (object)null);
				}
				else if (CodeInstructionExtensions.Calls(list[i], m_screenHeight))
				{
					yield return new CodeInstruction(OpCodes.Ldc_I4_1, (object)null);
				}
				else if (i < list.Count - 4 && CodeInstructionExtensions.IsLdloc(list[i], (LocalBuilder)null) && CodeInstructionExtensions.Calls(list[i + 4], m_screenToWorldPoint))
				{
					yield return list[i];
					yield return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
					yield return new CodeInstruction(OpCodes.Call, (object)m_normalizedMapPosToWorldPos);
					yield return new CodeInstruction(OpCodes.Nop, (object)null);
					yield return new CodeInstruction(OpCodes.Nop, (object)null);
					yield return list[i + 5];
					yield return list[i + 6];
					i += 6;
				}
				else
				{
					yield return list[i];
				}
			}
		}
	}
	[HarmonyPatch(typeof(CardBar), "OnHover")]
	internal static class CardBarPatch_OnHover_Patch
	{
		public static void Postfix(GameObject ___currentCard)
		{
			//IL_000d: 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)
			Transform transform = ((Component)___currentCard.GetComponentInChildren<SetScaleToZero>()).transform;
			transform.localScale *= MainCam.instance.cam.orthographicSize / 20f;
		}
	}
	[HarmonyPatch(typeof(CardVisuals), "ChangeSelected")]
	internal static class CardVisuals_ChangeSelected_Patch
	{
		public static void Postfix(ScaleShake ___shake)
		{
			___shake.targetScale *= MainCam.instance.cam.orthographicSize / 20f;
		}
	}
	[HarmonyPatch(typeof(MapTransition), "MoveObject")]
	internal static class MapTransition_MoveObject_Patch
	{
		public static void Prefix(ref Vector3 targetPos)
		{
			//IL_0031: 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_003d: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if (MapManager.instance.GetCurrentCustomMap() != null && targetPos.x < 0f)
			{
				Vector2 val = ConversionUtils.ScreenToWorldUnits(MapManager.instance.GetCurrentCustomMap().Settings.MapSize);
				targetPos = new Vector3(0f - (val.x + 20f), targetPos.y, targetPos.z);
			}
			if (targetPos.x < 0f && targetPos.x > -90f)
			{
				targetPos = new Vector3(-90f, targetPos.y, targetPos.z);
			}
		}
	}
	[HarmonyPatch(typeof(MapTransition), "SetStartPos")]
	internal static class MapTransition_SetStartPos_Patch
	{
		public static void Postfix(Map map)
		{
			//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_001f: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0054: 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_0076: 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_009f: 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)
			Vector3 position = ((Component)map).transform.position;
			if (MapManager.instance.GetCurrentCustomMap() != null && ((Component)map).transform.position.x > 0f)
			{
				Vector2 val = ConversionUtils.ScreenToWorldUnits(MapManager.instance.GetCurrentCustomMap().Settings.MapSize);
				((Vector3)(ref position))..ctor(val.x + 20f, ((Component)map).transform.position.y, ((Component)map).transform.position.z);
			}
			if (position.x < 90f)
			{
				((Vector3)(ref position))..ctor(90f, position.y, position.z);
			}
			((Component)map).transform.position = position;
		}
	}
	public sealed class NetworkedMapObjectManager : MapObjectManager
	{
		private static readonly Dictionary<string, TargetSyncedStore<int>> s_syncStores = new Dictionary<string, TargetSyncedStore<int>>();

		private string _networkID;

		[UnboundRPC]
		public static void RPC_SyncInstantiation(string networkID, int instantiationID, int viewID)
		{
			s_syncStores[networkID].Set(instantiationID, viewID);
		}

		public override void RegisterMapObject(Type dataType, IMapObject mapObject, IMapObjectSerializer serializer)
		{
			base.RegisterMapObject(dataType, mapObject, serializer);
			if (Object.op_Implicit((Object)(object)mapObject.Prefab.GetComponent<PhotonMapObject>()))
			{
				PhotonNetwork.PrefabPool.RegisterPrefab(GetInstanceName(dataType), mapObject.Prefab);
				PhotonNetwork.PrefabPool.RegisterPrefab("4 Map Objects/" + GetInstanceName(dataType), mapObject.Prefab);
			}
		}

		public void SetNetworkID(string id)
		{
			if (_networkID != null)
			{
				s_syncStores.Remove(_networkID);
			}
			_networkID = id;
			s_syncStores.Add(id, new TargetSyncedStore<int>());
		}

		private string GetInstanceName(Type type)
		{
			return _networkID + "/" + type.FullName;
		}

		public override void Instantiate(MapObjectData data, Transform parent, Action<GameObject> onInstantiate = null)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			IMapObject mapObject = GetMapObject(data.GetType());
			GameObject prefab = mapObject.Prefab;
			TargetSyncedStore<int> targetSyncedStore = s_syncStores[_networkID];
			int instantiationID = targetSyncedStore.Allocate(parent);
			GameObject val = Object.Instantiate<GameObject>(prefab, Vector3.zero, Quaternion.identity, parent);
			if ((Object)(object)prefab.GetComponent<PhotonMapObject>() != (Object)null)
			{
				if (PhotonNetwork.IsMasterClient)
				{
					MapsExtended.AddPhotonInstantiateListener(val.GetComponent<PhotonMapObject>(), delegate(GameObject networkInstance)
					{
						mapObject.OnInstantiate(networkIns