Decompiled source of MapsExtendedEditor v1.4.2

plugins\MapsExtended.Editor.dll

Decompiled a year ago
#define DEBUG
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Utils;
using MapsExt.Compatibility;
using MapsExt.Editor;
using MapsExt.Editor.Events;
using MapsExt.Editor.MapObjects;
using MapsExt.Editor.Properties;
using MapsExt.Editor.UI;
using MapsExt.Editor.Utils;
using MapsExt.Geometry;
using MapsExt.MapObjects;
using MapsExt.Properties;
using MapsExt.Utils;
using MapsExt.Visualizers;
using NetTopologySuite.Algorithm;
using NetTopologySuite.Algorithm.Locate;
using NetTopologySuite.Geometries;
using NetTopologySuite.Operation.Union;
using Sirenix.Serialization;
using Sirenix.Utilities;
using TMPro;
using UnboundLib;
using UnboundLib.GameModes;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.UI.ProceduralImage;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace System.Runtime.CompilerServices
{
	internal static class IsExternalInit
	{
	}
}
namespace MapsExt
{
	public class StateHistory<T>
	{
		private readonly List<T> _states;

		private int _stateIndex;

		public T CurrentState => _states[_stateIndex];

		public StateHistory(T initialState)
		{
			_states = new List<T> { initialState };
			_stateIndex = 0;
		}

		public bool CanRedo()
		{
			return _stateIndex < _states.Count - 1;
		}

		public bool CanUndo()
		{
			return _stateIndex > 0;
		}

		public void AddState(T state)
		{
			while (_stateIndex < _states.Count - 1)
			{
				_states.RemoveAt(_stateIndex + 1);
			}
			_states.Add(state);
			_stateIndex++;
		}

		public void Redo()
		{
			_stateIndex++;
		}

		public void Undo()
		{
			_stateIndex--;
		}
	}
	public class PointerDownHandler : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler
	{
		public Action<GameObject> PointerDown { get; set; }

		public Action<GameObject> PointerUp { get; set; }

		public virtual void OnPointerDown(PointerEventData eventData)
		{
			PointerDown?.Invoke(((Component)this).gameObject);
		}

		public virtual void OnPointerUp(PointerEventData eventData)
		{
			PointerUp?.Invoke(((Component)this).gameObject);
		}
	}
}
namespace MapsExt.Visualizers
{
	internal interface IMapObjectVisualizer
	{
		void SetEnabled(bool enabled);
	}
	public class RopeVisualizer : MonoBehaviour, IMapObjectVisualizer
	{
		private EditorRope.RopeInstance _rope;

		private LineRenderer _renderer;

		private Graphic _startGraphic;

		private Graphic _endGraphic;

		public void SetEnabled(bool enabled)
		{
			((Behaviour)this).enabled = enabled;
		}

		protected virtual void Start()
		{
			_rope = ((Component)this).gameObject.GetComponent<EditorRope.RopeInstance>();
		}

		protected virtual void OnEnable()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0096: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			_renderer = ((Component)this).gameObject.GetComponent<LineRenderer>();
			((Renderer)_renderer).material = new Material(Shader.Find("Sprites/Default"));
			_renderer.startColor = new Color(0.039f, 0.039f, 0.039f, 1f);
			_renderer.endColor = _renderer.startColor;
			_renderer.startWidth = 0.2f;
			_renderer.endWidth = 0.2f;
			GameObject val = new GameObject("Canvas");
			val.transform.SetParent(((Component)this).transform);
			Canvas val2 = val.AddComponent<Canvas>();
			val2.renderMode = (RenderMode)0;
			GameObject val3 = new GameObject("Rope Start");
			GameObject val4 = new GameObject("Rope End");
			val3.transform.SetParent(val.transform);
			val4.transform.SetParent(val.transform);
			_startGraphic = (Graphic)(object)val3.AddComponent<ProceduralImage>();
			_endGraphic = (Graphic)(object)val4.AddComponent<ProceduralImage>();
			_startGraphic.rectTransform.sizeDelta = Vector2.one * 10f;
			_endGraphic.rectTransform.sizeDelta = Vector2.one * 10f;
			_startGraphic.color = new Color(1f, 1f, 1f, 0.5f);
			_endGraphic.color = new Color(1f, 1f, 1f, 0.5f);
			UniformModifier val5 = val3.AddComponent<UniformModifier>();
			UniformModifier val6 = val4.AddComponent<UniformModifier>();
			val5.Radius = 5f;
			val6.Radius = 5f;
		}

		protected virtual void OnDisable()
		{
			_renderer = null;
			_startGraphic = null;
			_endGraphic = null;
			Object.Destroy((Object)(object)((Component)((Component)this).transform.Find("Canvas")).gameObject);
		}

		private void LateUpdate()
		{
			//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_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)
			//IL_0072: 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_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_009b: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_renderer) && Object.op_Implicit((Object)(object)_startGraphic) && Object.op_Implicit((Object)(object)_endGraphic))
			{
				Vector3 position = ((Component)_rope.GetAnchor(0)).transform.position;
				Vector3 position2 = ((Component)_rope.GetAnchor(1)).transform.position;
				_renderer.SetPositions((Vector3[])(object)new Vector3[2] { position, position2 });
				((Component)_startGraphic).transform.position = MainCam.instance.cam.WorldToScreenPoint(position);
				((Component)_endGraphic).transform.position = MainCam.instance.cam.WorldToScreenPoint(position2);
				_startGraphic.color = (_rope.GetAnchor(0).IsAttached ? new Color(0f, 0.5f, 1f) : new Color(1f, 1f, 1f));
				_endGraphic.color = (_rope.GetAnchor(1).IsAttached ? new Color(0f, 0.5f, 1f) : new Color(1f, 1f, 1f));
			}
		}
	}
	public class SpawnVisualizer : MonoBehaviour, IMapObjectVisualizer
	{
		private Image _labelBg;

		private TextMeshProUGUI _label;

		private Image _positionIndicator;

		private Canvas _canvas;

		public void SetEnabled(bool enabled)
		{
			((Behaviour)this).enabled = enabled;
		}

		protected virtual void OnEnable()
		{
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Expected O, but got Unknown
			//IL_0221: 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)
			BoxCollider2D val = ((Component)this).gameObject.AddComponent<BoxCollider2D>();
			val.size = Vector2.op_Implicit(new Vector3(3f, 3f));
			GameObject val2 = new GameObject("Label Collider");
			val2.transform.SetParent(((Component)this).transform);
			val2.transform.localPosition = new Vector3(0f, 2f);
			BoxCollider2D val3 = val2.AddComponent<BoxCollider2D>();
			val3.size = new Vector2(3f, 1f);
			GameObject val4 = new GameObject("Canvas");
			val4.transform.SetParent(((Component)this).transform);
			val4.transform.localPosition = Vector3.zero;
			_canvas = val4.AddComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = 1;
			GameObject val5 = new GameObject("Image");
			val5.transform.SetParent(val4.transform);
			val5.transform.localScale = Vector3.one;
			_labelBg = (Image)(object)val5.AddComponent<ProceduralImage>();
			((Graphic)_labelBg).rectTransform.sizeDelta = new Vector2(80f, 30f);
			((Graphic)_labelBg).color = new Color(0f, 0.57f, 0.45f, 0.2f);
			UniformModifier val6 = val5.AddComponent<UniformModifier>();
			val6.Radius = 8f;
			GameObject val7 = new GameObject("Text");
			val7.transform.SetParent(val4.transform);
			_label = val7.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_label).fontSize = 12f;
			((TMP_Text)_label).fontStyle = (FontStyles)1;
			((Graphic)_label).color = new Color(1f, 1f, 1f, 0.8f);
			((TMP_Text)_label).alignment = (TextAlignmentOptions)514;
			GameObject val8 = new GameObject("Position Indicator");
			val8.transform.SetParent(val4.transform);
			_positionIndicator = val8.AddComponent<Image>();
			((Graphic)_positionIndicator).rectTransform.sizeDelta = Vector2.one * 10f;
		}

		protected virtual void OnDisable()
		{
			Object.Destroy((Object)(object)((Component)this).gameObject.GetComponent<BoxCollider2D>());
			Object.Destroy((Object)(object)((Component)((Component)this).transform.Find("Canvas")).gameObject);
			Object.Destroy((Object)(object)((Component)((Component)this).transform.Find("Label Collider")).gameObject);
		}

		private void LateUpdate()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			SpawnPoint component = ((Component)this).gameObject.GetComponent<SpawnPoint>();
			((TMP_Text)_label).text = $"Spawn {component.ID}";
			Vector3 val = MainCam.instance.cam.WorldToScreenPoint(((Component)this).transform.position) - MainCam.instance.cam.WorldToScreenPoint(((Component)MainCam.instance.cam).transform.position);
			((Graphic)_positionIndicator).rectTransform.anchoredPosition = Vector2.op_Implicit(val);
			((TMP_Text)_label).rectTransform.anchoredPosition = Vector2.op_Implicit(val + new Vector3(0f, 50f, 0f));
			((Graphic)_labelBg).rectTransform.anchoredPosition = Vector2.op_Implicit(val + new Vector3(0f, 50f, 0f));
		}
	}
}
namespace MapsExt.UI
{
	public class MapBorder : MonoBehaviour
	{
		private MapEditor _editor;

		private LineRenderer _lineRenderer;

		protected virtual void Start()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			_editor = ((Component)this).GetComponentInParent<MapEditor>();
			_lineRenderer = ExtensionMethods.GetOrAddComponent<LineRenderer>(((Component)this).gameObject, false);
			((Renderer)_lineRenderer).material = new Material(Shader.Find("Sprites/Default"));
			_lineRenderer.widthMultiplier = 0.2f;
			_lineRenderer.positionCount = 4;
			_lineRenderer.startColor = new Color(0.5f, 0.5f, 0.6f, 0.02f);
			_lineRenderer.endColor = _lineRenderer.startColor;
			_lineRenderer.loop = true;
		}

		protected virtual void LateUpdate()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			Vector2 mapSize = _editor.MapSettings.MapSize;
			Vector2 val = ConversionUtils.ScreenToWorldUnits(mapSize);
			Vector2 val2 = -(val * 0.5f);
			Vector2 val3 = val * 0.5f;
			Vector3[] positions = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(val2.x, val2.y),
				new Vector3(val3.x, val2.y),
				new Vector3(val3.x, val3.y),
				new Vector3(val2.x, val3.y)
			};
			_lineRenderer.SetPositions(positions);
		}
	}
}
namespace MapsExt.Geometry
{
	public class Triangulator
	{
		private class Vertex
		{
			public int index;

			public Coordinate position;

			public bool isConvex;

			public Vertex(int index, Coordinate position)
			{
				this.index = index;
				this.position = position;
			}
		}

		private class Edge
		{
			public Vertex first;

			public Vertex second;

			public LineSegment Segment => new LineSegment(first.position, second.position);

			public Edge(Vertex first, Vertex second)
			{
				this.first = first;
				this.second = second;
			}

			public Coordinate IntersectLine(LineSegment line)
			{
				Coordinate val = Segment.LineIntersection(line);
				return (val != null && ((first.position.Y <= val.Y && second.position.Y >= val.Y) || (first.position.Y >= val.Y && second.position.Y <= val.Y))) ? val : null;
			}
		}

		private class PolygonHull
		{
			public readonly Coordinate[] vertices;

			public readonly int vertexOffset;

			public PolygonHull(LineString ring, int vertexOffset)
			{
				List<Coordinate> list = ((Geometry)ring).Coordinates.ToList();
				if (list.Count > 0)
				{
					list.RemoveAt(list.Count - 1);
				}
				vertices = list.ToArray();
				this.vertexOffset = vertexOffset;
			}
		}

		private class PolygonWrapper
		{
			public readonly PolygonHull[] hulls;

			public readonly Coordinate[] vertices;

			public PolygonHull Exterior => hulls[0];

			public PolygonHull[] Interiors => hulls.Skip(1).ToArray();

			public PolygonWrapper(Polygon polygon)
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Expected O, but got Unknown
				LineString val = polygon.ExteriorRing;
				LineString[] interiorRings = polygon.InteriorRings;
				if (!Orientation.IsCCW(((Geometry)val).Coordinates))
				{
					val = (LineString)((Geometry)val).Reverse();
				}
				for (int i = 0; i < interiorRings.Length; i++)
				{
					if (Orientation.IsCCW(((Geometry)interiorRings[i]).Coordinates))
					{
						interiorRings[i] = (LineString)((Geometry)interiorRings[i]).Reverse();
					}
				}
				List<LineString> list = interiorRings.Where((LineString r) => ((Geometry)r).Coordinates.Length != 0).ToList();
				list.Sort((LineString a, LineString b) => ((Geometry)b).Coordinates.Max((Coordinate c) => c.X).CompareTo(((Geometry)a).Coordinates.Max((Coordinate c) => c.X)));
				List<PolygonHull> list2 = new List<PolygonHull>
				{
					new PolygonHull(val, 0)
				};
				foreach (LineString item in list)
				{
					PolygonHull polygonHull = list2[list2.Count - 1];
					list2.Add(new PolygonHull(item, polygonHull.vertexOffset + polygonHull.vertices.Length));
				}
				hulls = list2.ToArray();
				vertices = hulls.SelectMany((PolygonHull h) => h.vertices).ToArray();
			}

			public bool IsValid()
			{
				for (int i = 0; i < vertices.Length; i++)
				{
					for (int j = 0; j < vertices.Length; j++)
					{
						if (i != j && vertices[i].Distance(vertices[j]) < 9.999999747378752E-05)
						{
							return false;
						}
					}
				}
				return true;
			}
		}

		private readonly PolygonWrapper _polygon;

		public Triangulator(Polygon polygon)
		{
			_polygon = new PolygonWrapper(polygon);
		}

		public Mesh GetMesh()
		{
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			if (!_polygon.IsValid())
			{
				return null;
			}
			LinkedList<Vertex> linkedList = BuildVertexList();
			int[] array = new int[(linkedList.Count - 2) * 3];
			int num = 0;
			while (linkedList.Count >= 3)
			{
				bool flag = false;
				LinkedListNode<Vertex> linkedListNode = linkedList.First;
				for (int i = 0; i < linkedList.Count; i++)
				{
					LinkedListNode<Vertex> linkedListNode2 = linkedListNode.Previous ?? linkedList.Last;
					LinkedListNode<Vertex> linkedListNode3 = linkedListNode.Next ?? linkedList.First;
					if (linkedListNode.Value.isConvex && IsEar(linkedList, linkedListNode))
					{
						array[num * 3 + 2] = linkedListNode2.Value.index;
						array[num * 3 + 1] = linkedListNode.Value.index;
						array[num * 3] = linkedListNode3.Value.index;
						num++;
						linkedList.Remove(linkedListNode);
						UpdateVertex(linkedList, linkedListNode2);
						UpdateVertex(linkedList, linkedListNode3);
						flag = true;
						break;
					}
					linkedListNode = linkedListNode3;
				}
				if (!flag)
				{
					return null;
				}
			}
			return new Mesh
			{
				vertices = ((IEnumerable<Coordinate>)_polygon.vertices).Select((Func<Coordinate, Vector3>)((Coordinate c) => new Vector3((float)c.X, (float)c.Y, 0f))).ToArray(),
				triangles = array
			};
		}

		private LinkedList<Vertex> BuildVertexList()
		{
			LinkedList<Vertex> linkedList = new LinkedList<Vertex>();
			for (int i = 0; i < _polygon.Exterior.vertices.Length; i++)
			{
				Vertex value = new Vertex(i, _polygon.Exterior.vertices[i]);
				linkedList.AddLast(value);
			}
			for (LinkedListNode<Vertex> linkedListNode = linkedList.First; linkedListNode != null; linkedListNode = linkedListNode.Next)
			{
				UpdateVertex(linkedList, linkedListNode);
			}
			for (int j = 0; j < _polygon.Interiors.Length; j++)
			{
				PolygonHull polygonHull = _polygon.Interiors[j];
				Coordinate val = polygonHull.vertices.Aggregate((Coordinate a, Coordinate b) => (a.X > b.X) ? a : b);
				Vertex vertex = FindMutuallyVisibleVertex(linkedList, val);
				LinkedListNode<Vertex> linkedListNode2 = linkedList.Find(vertex);
				LinkedListNode<Vertex> node = linkedListNode2;
				int num = Array.IndexOf(polygonHull.vertices, val);
				for (int k = 0; k <= polygonHull.vertices.Length; k++)
				{
					int num2 = (num + k) % polygonHull.vertices.Length;
					Vertex value2 = new Vertex(polygonHull.vertexOffset + num2, polygonHull.vertices[num2]);
					node = linkedList.AddAfter(node, value2);
				}
				Vertex value3 = new Vertex(vertex.index, vertex.position);
				LinkedListNode<Vertex> linkedListNode3 = linkedList.AddAfter(node, value3);
				for (LinkedListNode<Vertex> linkedListNode4 = linkedListNode2; linkedListNode4 != (linkedListNode3.Next ?? linkedList.First); linkedListNode4 = linkedListNode4.Next ?? linkedList.First)
				{
					LinkedListNode<Vertex> linkedListNode5 = linkedListNode4.Next ?? linkedList.First;
					UpdateVertex(linkedList, linkedListNode4);
				}
			}
			return linkedList;
		}

		private Vertex FindMutuallyVisibleVertex(LinkedList<Vertex> vertices, Coordinate point)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			List<Edge> list = new List<Edge>();
			for (LinkedListNode<Vertex> linkedListNode = vertices.First; linkedListNode != null; linkedListNode = linkedListNode.Next)
			{
				LinkedListNode<Vertex> linkedListNode2 = linkedListNode.Next ?? vertices.First;
				list.Add(new Edge(linkedListNode.Value, linkedListNode2.Value));
			}
			LineSegment ray = new LineSegment(point, new Coordinate(point.X + 1.0, point.Y));
			var list2 = (from e in list
				select new
				{
					edge = e,
					coord = e.IntersectLine(ray)
				} into e
				where e.coord != null && e.coord.X > point.X
				select e).ToList();
			list2.Sort((a, b) => point.Distance(a.coord).CompareTo(point.Distance(b.coord)));
			Edge edge = list2[0].edge;
			Coordinate coord = list2[0].coord;
			Vertex candidateVertex = ((edge.first.position.X > edge.second.position.X) ? edge.first : edge.second);
			Polygon val = new Polygon(new LinearRing((Coordinate[])(object)new Coordinate[4] { point, coord, candidateVertex.position, point }));
			IndexedPointInAreaLocator locator = new IndexedPointInAreaLocator((Geometry)(object)val);
			List<Vertex> list3 = vertices.Where((Vertex v) => !v.isConvex && v != candidateVertex && (int)locator.Locate(v.position) != 2).ToList();
			return (list3.Count == 0) ? candidateVertex : list3.Select((Vertex v) => new
			{
				vertex = v,
				angle = Mathf.Abs((float)(v.position.Y - point.Y))
			}).Aggregate((a, b) => (a.angle < b.angle) ? a : b).vertex;
		}

		private void UpdateVertex(LinkedList<Vertex> vertices, LinkedListNode<Vertex> node)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			LinkedListNode<Vertex> linkedListNode = node.Previous ?? vertices.Last;
			LinkedListNode<Vertex> linkedListNode2 = node.Next ?? vertices.First;
			Coordinate position = linkedListNode.Value.position;
			Coordinate position2 = linkedListNode2.Value.position;
			Coordinate position3 = node.Value.position;
			node.Value.isConvex = (int)Orientation.Index(position, position2, position3) == -1;
		}

		private bool IsEar(LinkedList<Vertex> vertices, LinkedListNode<Vertex> node)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			LinkedListNode<Vertex> linkedListNode = node.Previous ?? vertices.Last;
			LinkedListNode<Vertex> linkedListNode2 = node.Next ?? vertices.First;
			Coordinate position = linkedListNode.Value.position;
			Coordinate position2 = linkedListNode2.Value.position;
			Coordinate position3 = node.Value.position;
			Polygon val = new Polygon(new LinearRing((Coordinate[])(object)new Coordinate[4] { position, position3, position2, position }));
			IndexedPointInAreaLocator locator = new IndexedPointInAreaLocator((Geometry)(object)val);
			return vertices.All((Vertex v) => (int)locator.Locate(v.position) > 0);
		}
	}
}
namespace MapsExt.Editor
{
	public class DefaultInputSource : IInputSource
	{
		public Vector2 MouseScrollDelta => Input.mouseScrollDelta;

		public Vector3 MousePosition => Input.mousePosition;

		public bool GetMouseButtonDown(int button)
		{
			return Input.GetMouseButtonDown(button);
		}

		public bool GetMouseButtonUp(int button)
		{
			return Input.GetMouseButtonUp(button);
		}

		public bool GetMouseButton(int button)
		{
			return Input.GetMouseButton(button);
		}

		public bool GetKeyDown(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return Input.GetKeyDown(key);
		}

		public bool GetKeyUp(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return Input.GetKeyUp(key);
		}

		public bool GetKey(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return Input.GetKey(key);
		}
	}
	public class Direction2D
	{
		public static readonly Direction2D Middle = new Direction2D(new Vector2(0f, 0f));

		public static readonly Direction2D North = new Direction2D(new Vector2(0f, 1f));

		public static readonly Direction2D South = new Direction2D(new Vector2(0f, -1f));

		public static readonly Direction2D East = new Direction2D(new Vector2(1f, 0f));

		public static readonly Direction2D West = new Direction2D(new Vector2(-1f, 0f));

		public static readonly Direction2D NorthEast = new Direction2D(new Vector2(1f, 1f));

		public static readonly Direction2D NorthWest = new Direction2D(new Vector2(-1f, 1f));

		public static readonly Direction2D SouthEast = new Direction2D(new Vector2(1f, -1f));

		public static readonly Direction2D SouthWest = new Direction2D(new Vector2(-1f, -1f));

		private Vector2 directionMultiplier;

		private Direction2D(Vector2 directionMultiplier)
		{
			//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)
			this.directionMultiplier = directionMultiplier;
		}

		public Direction2D Abs()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return new Direction2D(new Vector2(Mathf.Abs(directionMultiplier.x), Mathf.Abs(directionMultiplier.y)));
		}

		public override string ToString()
		{
			if (1 == 0)
			{
			}
			string result = ((this != Middle) ? ((this != North) ? ((this != South) ? ((this != East) ? ((this != West) ? ((this != NorthEast) ? ((this != NorthWest) ? ((this != SouthEast) ? ((this != SouthWest) ? base.ToString() : "SouthWest") : "SouthEast") : "NorthWest") : "NorthEast") : "West") : "East") : "South") : "North") : "Middle");
			if (1 == 0)
			{
			}
			return result;
		}

		public static Vector2 operator *(Direction2D dir, Vector2 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return Vector2.Scale(v, dir.directionMultiplier);
		}

		public static Vector2 operator *(Vector2 v, Direction2D dir)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return Vector2.Scale(v, dir.directionMultiplier);
		}
	}
	public class EditorBaseInput : BaseInput
	{
		public override Vector2 mousePosition => EditorInput.MousePosition;

		public override Vector2 mouseScrollDelta => EditorInput.MouseScrollDelta;

		public override bool GetMouseButton(int button)
		{
			return EditorInput.GetMouseButton(button);
		}

		public override bool GetMouseButtonDown(int button)
		{
			return EditorInput.GetMouseButtonDown(button);
		}

		public override bool GetMouseButtonUp(int button)
		{
			return EditorInput.GetMouseButtonUp(button);
		}
	}
	public static class EditorInput
	{
		private static IInputSource inputSource = DefaultInputSource;

		public static DefaultInputSource DefaultInputSource { get; } = new DefaultInputSource();


		public static Vector2 MouseScrollDelta => inputSource.MouseScrollDelta;

		public static Vector2 MousePosition => Vector2.op_Implicit(inputSource.MousePosition);

		public static bool GetMouseButton(int button)
		{
			return inputSource.GetMouseButton(button);
		}

		public static bool GetMouseButtonDown(int button)
		{
			return inputSource.GetMouseButtonDown(button);
		}

		public static bool GetMouseButtonUp(int button)
		{
			return inputSource.GetMouseButtonUp(button);
		}

		public static bool GetKeyDown(KeyCode key)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return inputSource.GetKeyDown(key);
		}

		public static bool GetKeyUp(KeyCode key)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return inputSource.GetKeyUp(key);
		}

		public static bool GetKey(KeyCode key)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return inputSource.GetKey(key);
		}

		public static void SetInputSource(IInputSource source)
		{
			inputSource = source;
		}
	}
	public sealed class EditorMapObjectManager : MapObjectManager
	{
		public override void Instantiate(MapObjectData data, Transform parent, Action<GameObject> onInstantiate = null)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			IMapObject mapObject = ((MapObjectManager)this).GetMapObject(((object)data).GetType());
			GameObject prefab = mapObject.Prefab;
			GameObject val = Object.Instantiate<GameObject>(prefab, Vector3.zero, Quaternion.identity, parent);
			if (Object.op_Implicit((Object)(object)val.GetComponent<PhotonMapObject>()))
			{
				Object.Destroy((Object)(object)val.GetComponent<PhotonMapObject>());
			}
			((Object)val).name = ((object)data).GetType().Name;
			mapObject.OnInstantiate(val);
			((MapObjectManager)this).WriteMapObject(data, val);
			IMapObjectDataWriteCallbackReceiver val2 = (IMapObjectDataWriteCallbackReceiver)(object)((mapObject is IMapObjectDataWriteCallbackReceiver) ? mapObject : null);
			if (val2 != null)
			{
				val2.OnDataWrite(val, data);
			}
			if (val.GetComponentsInChildren<MapObjectPart>().Count() == 0)
			{
				val.AddComponent<MapObjectPart>();
			}
			onInstantiate?.Invoke(val);
		}
	}
	public interface IInputSource
	{
		Vector2 MouseScrollDelta { get; }

		Vector3 MousePosition { get; }

		bool GetMouseButtonDown(int button);

		bool GetMouseButtonUp(int button);

		bool GetMouseButton(int button);

		bool GetKeyDown(KeyCode key);

		bool GetKeyUp(KeyCode key);

		bool GetKey(KeyCode key);
	}
	public class KeyMonitor : MonoBehaviour
	{
		private const float HeldThreshold = 0.5f;

		private const float HeldInterval = 0.05f;

		private Dictionary<KeyCode, float> _heldKeys;

		private Dictionary<KeyCode, Action> _listeners;

		protected virtual void Awake()
		{
			_heldKeys = new Dictionary<KeyCode, float>();
			_listeners = new Dictionary<KeyCode, Action>();
		}

		public void AddListener(KeyCode code, Action action)
		{
			//IL_0007: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_001b: 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)
			if (!_listeners.ContainsKey(code))
			{
				_listeners.Add(code, delegate
				{
				});
				_heldKeys.Add(code, 0f);
			}
			Dictionary<KeyCode, Action> listeners = _listeners;
			listeners[code] = (Action)Delegate.Combine(listeners[code], action);
		}

		public void RemoveListener(KeyCode code, Action action)
		{
			//IL_0007: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (_listeners.ContainsKey(code))
			{
				Dictionary<KeyCode, Action> listeners = _listeners;
				listeners[code] = (Action)Delegate.Remove(listeners[code], action);
				if (_listeners[code].GetInvocationList().Length == 0)
				{
					_listeners.Remove(code);
					_heldKeys.Remove(code);
				}
			}
		}

		protected virtual void Update()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			foreach (KeyCode key in _listeners.Keys)
			{
				if (GetHeldKey(key))
				{
					_listeners[key]();
				}
			}
		}

		private bool GetHeldKey(KeyCode code)
		{
			//IL_0001: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (!EditorInput.GetKey(code))
			{
				_heldKeys[code] = 0f;
				return false;
			}
			float num = _heldKeys[code];
			_heldKeys[code] += Time.deltaTime;
			bool flag = num == 0f;
			bool flag2 = num > 0.55f;
			if (flag2)
			{
				_heldKeys[code] = 0.5f;
			}
			return flag || flag2;
		}
	}
	public class MapEditor : MonoBehaviour
	{
		[SerializeField]
		private GameObject _content;

		[SerializeField]
		private GameObject _simulatedContent;

		[SerializeField]
		private MapEditorAnimationHandler _animationHandler;

		[SerializeField]
		private Grid _grid;

		private StateHistory<CustomMap> _stateHistory;

		private bool _isCreatingSelection;

		private Vector3 _selectionStartPosition;

		private Rect _selectionRect;

		private List<MapObjectData> _clipboardMapObjects;

		private GameObject _tempSpawn;

		private GameObject _dummyGroup;

		private GameObject _activeMapObjectPart;

		private GameObject _activeMapObjectOverride;

		private MapWrapper _mapWrapper;

		private CustomMapSettings _mapSettings = new CustomMapSettings();

		public GameObject ActiveMapObjectPart => _activeMapObjectPart;

		public GameObject ActiveMapObject => _activeMapObjectOverride ?? ((SelectedMapObjects.Count == 1) ? SelectedMapObjects.First() : null);

		public GameObject Content
		{
			get
			{
				return _content;
			}
			set
			{
				_content = value;
			}
		}

		public GameObject SimulatedContent
		{
			get
			{
				return _simulatedContent;
			}
			set
			{
				_simulatedContent = value;
			}
		}

		public MapEditorAnimationHandler AnimationHandler
		{
			get
			{
				return _animationHandler;
			}
			set
			{
				_animationHandler = value;
			}
		}

		public Grid Grid
		{
			get
			{
				return _grid;
			}
			set
			{
				_grid = value;
			}
		}

		public HashSet<GameObject> SelectedMapObjectParts { get; } = new HashSet<GameObject>();


		public HashSet<GameObject> SelectedMapObjects { get; } = new HashSet<GameObject>();


		public CustomMapSettings MapSettings => new CustomMapSettings(_mapSettings);

		public IEnumerable<GameObject> MapObjects => from x in Content.GetComponentsInChildren<MapObjectInstance>(true)
			select ((Component)x).gameObject;

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


		public string CurrentMapName { get; private set; }

		public bool IsSimulating { get; private set; }

		public float GridSize
		{
			get
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				return Grid.cellSize.x;
			}
			set
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				Grid.cellSize = Vector2.op_Implicit(Vector2.one * value);
			}
		}

		public event EventHandler<IEditorEvent> EditorEvent;

		protected virtual void Awake()
		{
			_stateHistory = new StateHistory<CustomMap>(GetMapData());
			((Component)this).gameObject.AddComponent<MapEditorInputHandler>();
		}

		protected virtual void Start()
		{
			Camera cam = MainCam.instance.cam;
			cam.cullingMask &= -1073741825;
			Camera cam2 = MainCam.instance.cam;
			cam2.cullingMask &= 0x7FFFFFFF;
			_mapWrapper = MapManager.instance.currentMap;
			MapManagerExtensions.SetCurrentCustomMap(MapManager.instance, GetMapData());
		}

		protected virtual void Update()
		{
			if (_isCreatingSelection)
			{
				UpdateSelection();
			}
		}

		public void ClearHistory()
		{
			_stateHistory = new StateHistory<CustomMap>(GetMapData());
		}

		public void LoadMap(string mapFilePath)
		{
			CustomMap val = MapLoader.LoadPath(mapFilePath, (DeserializationContext)null);
			LoadMap(val);
			string gameRootPath = Paths.GameRootPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			string value = Path.Combine(gameRootPath, "maps" + directorySeparatorChar);
			CurrentMapName = (mapFilePath.StartsWith(value) ? val.Name : null);
		}

		public void LoadMap(CustomMap map)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			MapsExtended.LoadMap(Content, map, (MapObjectManager)(object)MapsExtendedEditor.MapObjectManager, (Action)null);
			CurrentMapName = map.Name;
			SetMapSettings(new CustomMapSettings(map.Settings));
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 1, (Action)delegate
			{
				_stateHistory = new StateHistory<CustomMap>(GetMapData());
				ResetSpawnLabels();
				ClearSelected();
			});
		}

		public void SaveMap(string filename)
		{
			byte[] bytes = SerializationUtility.SerializeValue<CustomMap>(GetMapData(filename), (DataFormat)1, (SerializationContext)null);
			string path = ((filename == null) ? Path.GetTempFileName() : Path.Combine(Path.Combine(Paths.GameRootPath, "maps"), filename + ".map"));
			File.WriteAllBytes(path, bytes);
			CurrentMapName = filename;
		}

		private CustomMap GetMapData(string name = null)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			List<MapObjectData> list = new List<MapObjectData>();
			MapObjectInstance[] componentsInChildren = Content.GetComponentsInChildren<MapObjectInstance>(true);
			foreach (MapObjectInstance val in componentsInChildren)
			{
				MapObjectData val2 = MapObjectExtensions.ReadMapObject((Component)(object)val);
				if (!val2.Active)
				{
					GameObject gameObject = ((Component)val).gameObject;
					MapObjectAnimation animation = AnimationHandler.Animation;
					if ((Object)(object)gameObject == (Object)(object)((animation != null) ? ((Component)animation).gameObject : null))
					{
						val2.Active = true;
					}
				}
				list.Add(val2);
			}
			return new CustomMap(Guid.NewGuid().ToString(), name, "1.4.2", MapSettings, list.ToArray());
		}

		public void CopySelected()
		{
			_clipboardMapObjects = new List<MapObjectData>();
			IEnumerable<MapObjectInstance> enumerable = SelectedMapObjectParts.Select((GameObject obj) => obj.GetComponent<MapObjectInstance>() ?? obj.GetComponentInParent<MapObjectInstance>()).Distinct();
			foreach (MapObjectInstance item in enumerable)
			{
				MapObjectData val = MapObjectExtensions.ReadMapObject((Component)(object)item);
				val.MapObjectId = Guid.NewGuid().ToString();
				_clipboardMapObjects.Add(val);
			}
			this.EditorEvent?.Invoke(this, new CopyEvent());
		}

		public IEnumerator Paste()
		{
			if (_clipboardMapObjects == null || _clipboardMapObjects.Count == 0)
			{
				yield break;
			}
			ClearSelected();
			List<GameObject> pastedMapObjects = new List<GameObject>();
			foreach (MapObjectData mapObject in _clipboardMapObjects)
			{
				((MapObjectManager)MapsExtendedEditor.MapObjectManager).Instantiate(mapObject, Content.transform, (Action<GameObject>)delegate(GameObject obj)
				{
					pastedMapObjects.Add(obj);
				});
			}
			while (pastedMapObjects.Count < _clipboardMapObjects.Count)
			{
				yield return null;
			}
			IEnumerable<GameObject> pastedObjects = from obj in pastedMapObjects.SelectMany((GameObject obj) => obj.GetComponentsInChildren<MapObjectPart>())
				select ((Component)obj).gameObject;
			AddSelected(pastedObjects);
			ResetSpawnLabels();
			this.EditorEvent?.Invoke(this, new PasteEvent());
			yield return null;
			TakeSnaphot();
		}

		public void Undo()
		{
			_stateHistory.Undo();
			LoadState(_stateHistory.CurrentState);
		}

		public void Redo()
		{
			_stateHistory.Redo();
			LoadState(_stateHistory.CurrentState);
		}

		private void LoadState(CustomMap state)
		{
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			Dictionary<string, GameObject> dict = Content.GetComponentsInChildren<MapObjectInstance>(true).ToDictionary((MapObjectInstance item) => item.MapObjectId, (MapObjectInstance item) => ((Component)item).gameObject);
			MapObjectData[] mapObjects = state.MapObjects;
			foreach (MapObjectData val in mapObjects)
			{
				if (dict.ContainsKey(val.MapObjectId))
				{
					MapObjectExtensions.WriteMapObject(val, dict[val.MapObjectId]);
					dict.Remove(val.MapObjectId);
				}
				else
				{
					((MapObjectManager)MapsExtendedEditor.MapObjectManager).Instantiate(val, Content.transform, (Action<GameObject>)null);
				}
			}
			List<GameObject> list = SelectedMapObjectParts.Where((GameObject obj) => !dict.ContainsKey(obj.GetComponentInParent<MapObjectInstance>().MapObjectId)).ToList();
			foreach (string key in dict.Keys)
			{
				GameObject obj2 = dict[key];
				MapObjectAnimation animation = AnimationHandler.Animation;
				if ((Object)(object)obj2 == (Object)(object)((animation != null) ? ((Component)animation).gameObject : null))
				{
					AnimationHandler.SetAnimation(null);
				}
				GameObjectUtils.DestroyImmediateSafe(dict[key]);
			}
			ClearSelected();
			AddSelected((IEnumerable<GameObject>)list);
			AnimationHandler.Refresh();
			SetMapSettings(new CustomMapSettings(state.Settings));
		}

		public bool CanUndo()
		{
			return _stateHistory.CanUndo();
		}

		public bool CanRedo()
		{
			return _stateHistory.CanRedo();
		}

		public void CreateMapObject(Type mapObjectDataType)
		{
			ClearSelected();
			((MapObjectManager)MapsExtendedEditor.MapObjectManager).Instantiate(mapObjectDataType, Content.transform, (Action<GameObject>)delegate(GameObject obj)
			{
				IEnumerable<GameObject> list = from h in obj.GetComponentsInChildren<MapObjectPart>()
					select ((Component)h).gameObject;
				AddSelected(list);
				ResetSpawnLabels();
				TakeSnaphot();
			});
		}

		public void ZoomIn()
		{
			CameraHandler.StaticZoom = Mathf.Max(2f, CameraHandler.StaticZoom - 2f);
		}

		public void ZoomOut()
		{
			CameraHandler.StaticZoom = Mathf.Min(500f, CameraHandler.StaticZoom + 2f);
		}

		public void ToggleSnapToGrid(bool enabled)
		{
			SnapToGrid = enabled;
		}

		public void DeleteSelectedMapObjects()
		{
			if ((Object)(object)AnimationHandler.Animation != (Object)null)
			{
				throw new Exception("Cannot delete map objects while animating a map object.");
			}
			GameObject[] array = SelectedMapObjectParts.Select((GameObject obj) => ((Component)obj.GetComponentInParent<MapObjectInstance>()).gameObject).Distinct().ToArray();
			foreach (GameObject val in array)
			{
				MapObjectAnimation animation = AnimationHandler.Animation;
				if ((Object)(object)val == (Object)(object)((animation != null) ? ((Component)animation).gameObject : null))
				{
					AnimationHandler.SetAnimation(null);
				}
				GameObjectUtils.DestroyImmediateSafe(val);
			}
			ResetSpawnLabels();
			ClearSelected();
			TakeSnaphot();
		}

		public void StartSimulation()
		{
			ClearSelected();
			((Behaviour)AnimationHandler).enabled = false;
			IsSimulating = true;
			_isCreatingSelection = false;
			if (Content.GetComponentsInChildren<SpawnPoint>().Length == 0)
			{
				((MapObjectManager)MapsExtendedEditor.MapObjectManager).Instantiate<SpawnData>(Content.transform, (Action<GameObject>)delegate(GameObject instance)
				{
					Object.Destroy((Object)(object)instance.GetComponent<SpawnVisualizer>());
					_tempSpawn = instance;
					ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 1, (Action)DoStartSimulation);
				});
			}
			else
			{
				ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 1, (Action)DoStartSimulation);
			}
		}

		private void DoStartSimulation()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			Map simulatedMap = ExtensionMethods.GetOrAddComponent<Map>(SimulatedContent, false);
			ExtensionMethods.SetFieldValue((object)simulatedMap, "spawnPoints", (object)null);
			simulatedMap.wasSpawned = true;
			simulatedMap.hasEntered = true;
			ExtensionMethods.SetFieldValue((object)simulatedMap, "missingObjects", (object)0);
			ExtensionMethods.SetFieldValue((object)simulatedMap, "hasCalledReady", (object)true);
			ExtensionMethods.SetFieldValue((object)simulatedMap, "levelID", (object)MapManager.instance.currentLevelID);
			simulatedMap.mapIsReadyEarlyAction = null;
			simulatedMap.mapIsReadyAction = null;
			CustomMap mapData = GetMapData();
			MapManager.instance.currentMap = new MapWrapper(simulatedMap, _mapWrapper.Scene);
			MapManagerExtensions.SetCurrentCustomMap(MapManager.instance, mapData);
			CameraHandler.Mode = (CameraMode)1;
			MapsExtended.LoadMap(SimulatedContent, mapData, (MapObjectManager)(object)MapsExtended.MapObjectManager, (Action)delegate
			{
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				Content.SetActive(false);
				SimulatedContent.SetActive(true);
				GameModeManager.SetGameMode("Sandbox");
				GameModeManager.CurrentHandler.StartGame();
				GM_Test val = (GM_Test)GameModeManager.CurrentHandler.GameMode;
				val.testMap = true;
				((Behaviour)((Component)val).gameObject.GetComponentInChildren<CurveAnimation>(true)).enabled = false;
				ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 1, (Action)delegate
				{
					simulatedMap.mapIsReadyEarlyAction?.Invoke();
					simulatedMap.allRigs = SimulatedContent.GetComponentsInChildren<Rigidbody2D>();
					ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 1, (Action)delegate
					{
						simulatedMap.mapIsReadyAction?.Invoke();
					});
				});
			});
		}

		public void StopSimulation()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			GM_Test val = (GM_Test)GameModeManager.CurrentHandler.GameMode;
			((Behaviour)((Component)val).gameObject.GetComponentInChildren<CurveAnimation>(true)).enabled = true;
			IsSimulating = false;
			GameModeManager.SetGameMode((string)null);
			PlayerManager.instance.RemovePlayers();
			CardBarHandler.instance.ResetCardBards();
			CameraHandler.Mode = (CameraMode)0;
			if ((Object)(object)_tempSpawn != (Object)null)
			{
				GameObjectUtils.DestroyImmediateSafe(_tempSpawn);
				_tempSpawn = null;
			}
			GameObjectUtils.DestroyChildrenImmediateSafe(SimulatedContent);
			Content.SetActive(true);
			SimulatedContent.SetActive(false);
			MapManager.instance.currentMap = _mapWrapper;
			((Behaviour)AnimationHandler).enabled = true;
		}

		public void StartSelection()
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			_selectionStartPosition = Vector2.op_Implicit(EditorInput.MousePosition);
			_isCreatingSelection = true;
		}

		public void EndSelection()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			if (((Rect)(ref _selectionRect)).width > 2f && ((Rect)(ref _selectionRect)).height > 2f)
			{
				ClearSelected();
				List<MapObjectPart> containedMapObjectParts = EditorUtils.GetContainedMapObjectParts(UIUtils.GUIToWorldRect(_selectionRect));
				if ((Object)(object)AnimationHandler.Animation != (Object)null && containedMapObjectParts.Any((MapObjectPart p) => (Object)(object)((Component)p).gameObject == (Object)(object)AnimationHandler.KeyframeMapObject))
				{
					AddSelected(AnimationHandler.KeyframeMapObject);
				}
				else if ((Object)(object)AnimationHandler.Animation == (Object)null)
				{
					AddSelected(containedMapObjectParts.Select((MapObjectPart p) => ((Component)p).gameObject));
				}
			}
			_isCreatingSelection = false;
			_selectionRect = Rect.zero;
		}

		public Rect GetSelection()
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			return _selectionRect;
		}

		internal void OnClickMapObjectParts(List<MapObjectPart> parts)
		{
			List<GameObject> list = (from p in parts
				where (Object)(object)((Component)p).GetComponentInParent<MapObjectInstance>() != (Object)null
				select ((Component)p).gameObject).ToList();
			list.Sort((GameObject a, GameObject b) => ((Object)a).GetInstanceID() - ((Object)b).GetInstanceID());
			GameObject val = null;
			if ((Object)(object)AnimationHandler.Animation != (Object)null && list.Any((GameObject obj) => (Object)(object)obj == (Object)(object)AnimationHandler.KeyframeMapObject))
			{
				val = AnimationHandler.KeyframeMapObject;
			}
			else if ((Object)(object)AnimationHandler.Animation == (Object)null && list.Count > 0)
			{
				val = list[0];
				if (SelectedMapObjectParts.Count == 1)
				{
					int num = list.FindIndex(SelectedMapObjectParts.Contains);
					if (num != -1)
					{
						val = list[(num + 1) % list.Count];
					}
				}
			}
			int count = SelectedMapObjectParts.Count;
			bool flag = SelectedMapObjectParts.Contains(val);
			ClearSelected();
			if (!((Object)(object)val == (Object)null))
			{
				bool flag2 = flag && count > 1;
				bool flag3 = !flag;
				if (flag2 || flag3)
				{
					AddSelected(val);
				}
			}
		}

		internal void OnPointerDown()
		{
			this.EditorEvent?.Invoke(this, new PointerDownEvent());
		}

		internal void OnPointerUp()
		{
			this.EditorEvent?.Invoke(this, new PointerUpEvent());
		}

		internal void OnKeyDown(KeyCode key)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			this.EditorEvent?.Invoke(this, new KeyDownEvent(key));
		}

		internal void OnKeyUp(KeyCode key)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			this.EditorEvent?.Invoke(this, new KeyUpEvent(key));
		}

		private void UpdateSelection()
		{
			//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_0012: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector2 mousePosition = EditorInput.MousePosition;
			float num = Mathf.Abs(_selectionStartPosition.x - mousePosition.x);
			float num2 = Mathf.Abs(_selectionStartPosition.y - mousePosition.y);
			float num3 = Mathf.Min(_selectionStartPosition.x, mousePosition.x);
			float num4 = (float)Screen.height - Mathf.Min(_selectionStartPosition.y, mousePosition.y) - num2;
			_selectionRect = new Rect(num3, num4, num, num2);
		}

		public void ClearSelected()
		{
			this.EditorEvent?.Invoke(this, new DeselectEvent());
			if ((Object)(object)_dummyGroup != (Object)null)
			{
				GameObjectUtils.DestroyImmediateSafe(_dummyGroup);
			}
			SelectedMapObjectParts.Clear();
			SelectedMapObjects.Clear();
			_activeMapObjectPart = null;
		}

		public void AddSelected(GameObject obj)
		{
			AddSelected((IEnumerable<GameObject>)(object)new GameObject[1] { obj });
		}

		public void AddSelected(IEnumerable<GameObject> list)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			if (list.Any((GameObject obj) => (Object)(object)obj.GetComponentInParent<MapObjectInstance>() == (Object)null))
			{
				GameObject val = list.First((GameObject obj) => (Object)(object)obj.GetComponentInParent<MapObjectInstance>() == (Object)null);
				throw new ArgumentException("Cannot select " + ((Object)val).name + ": One of the object's parents must contain a MapObjectInstance.");
			}
			if (list.Count() >= 2)
			{
				_dummyGroup = new GameObject("Group");
				_dummyGroup.transform.SetParent(Content.transform);
				_dummyGroup.SetActive(false);
				_dummyGroup.AddComponent<MapObjectPart>();
				List<Tuple<Type, Type>> list2 = new List<Tuple<Type, Type>>();
				foreach (Type key in MapsExtendedEditor.GroupEditorEventHandlers.Keys)
				{
					Type[] requiredTypes = MapsExtendedEditor.GroupEditorEventHandlers[key];
					if (list.All((GameObject obj) => requiredTypes.All((Type t) => (Object)(object)obj.GetComponent(t) != (Object)null)))
					{
						_dummyGroup.AddComponent(key);
					}
				}
				_dummyGroup.SetActive(true);
				_activeMapObjectPart = _dummyGroup;
			}
			else
			{
				_activeMapObjectPart = list.FirstOrDefault();
			}
			SelectedMapObjectParts.UnionWith(list);
			SelectedMapObjects.UnionWith(from x in list.Select(delegate(GameObject x)
				{
					MapObjectInstance componentInParent = x.GetComponentInParent<MapObjectInstance>();
					return (componentInParent != null) ? ((Component)componentInParent).gameObject : null;
				})
				where (Object)(object)x != (Object)null
				select x);
			this.EditorEvent?.Invoke(this, new SelectEvent());
		}

		public void SelectAll()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			ClearSelected();
			if ((Object)(object)AnimationHandler.Animation != (Object)null)
			{
				AddSelected(AnimationHandler.KeyframeMapObject);
				return;
			}
			List<GameObject> list = new List<GameObject>();
			foreach (Transform item in Content.transform)
			{
				Transform val = item;
				list.Add(((Component)val).gameObject);
			}
			AddSelected((IEnumerable<GameObject>)list);
		}

		private void ResetSpawnLabels()
		{
			List<SpawnPoint> list = Content.GetComponentsInChildren<SpawnPoint>().ToList();
			for (int i = 0; i < list.Count; i++)
			{
				list[i].ID = i;
				list[i].TEAMID = i;
				((Object)((Component)list[i]).gameObject).name = $"SPAWN POINT {i}";
			}
		}

		public void TakeSnaphot()
		{
			_stateHistory.AddState(GetMapData());
		}

		public void SetMapSize(Vector2 size)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			SetMapSettings(new CustomMapSettings(_mapSettings)
			{
				MapSize = size
			});
		}

		public void SetViewportHeight(int height)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			SetMapSettings(new CustomMapSettings(_mapSettings)
			{
				ViewportHeight = height
			});
		}

		private void SetMapSettings(CustomMapSettings settings)
		{
			_mapSettings = settings;
			MapManagerExtensions.SetCurrentCustomMap(MapManager.instance, GetMapData());
		}

		public void OverrideActiveMapObject(GameObject obj)
		{
			if ((Object)(object)obj != (Object)null && (Object)(object)obj.GetComponentInParent<MapObjectInstance>() == (Object)null)
			{
				throw new ArgumentException("Object must be null or have a MapObjectInstance component.");
			}
			_activeMapObjectOverride = obj;
		}
	}
	public class MapEditorAnimationHandler : MonoBehaviour
	{
		[SerializeField]
		private MapEditor _editor;

		[SerializeField]
		private Camera _animationCamera;

		private SmoothLineRenderer _lineRenderer;

		private GameObject _curtain;

		private int _prevKeyframe = -1;

		private GameObject _particles;

		private GameObject _keyframeMapObject;

		private GameObject _postProcessCamera;

		public MapEditor Editor
		{
			get
			{
				return _editor;
			}
			set
			{
				_editor = value;
			}
		}

		public Camera AnimationCamera
		{
			get
			{
				return _animationCamera;
			}
			set
			{
				_animationCamera = value;
			}
		}

		public SmoothLineRenderer LineRenderer
		{
			get
			{
				return _lineRenderer;
			}
			set
			{
				_lineRenderer = value;
			}
		}

		public MapObjectAnimation Animation { get; private set; }

		public GameObject KeyframeMapObject
		{
			get
			{
				return _keyframeMapObject;
			}
			private set
			{
				_keyframeMapObject = value;
			}
		}

		public int KeyframeIndex { get; private set; }

		public AnimationKeyframe Keyframe => (Object.op_Implicit((Object)(object)Animation) && KeyframeIndex >= 0 && KeyframeIndex < Animation.Keyframes.Count) ? Animation.Keyframes[KeyframeIndex] : null;

		protected virtual void Awake()
		{
			SetupLayerCurtain();
			SetupPostProcessing();
			_lineRenderer = ((Component)this).gameObject.AddComponent<SmoothLineRenderer>();
			((Renderer)_lineRenderer.Renderer).sortingLayerID = SortingLayer.NameToID("MostFront");
			((Renderer)_lineRenderer.Renderer).sortingOrder = 9;
		}

		private void SetupPostProcessing()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			_postProcessCamera = new GameObject("PostProcessCamera");
			_postProcessCamera.transform.SetParent(((Component)this).transform);
			Camera val = _postProcessCamera.AddComponent<Camera>();
			val.CopyFrom(MainCam.instance.cam);
			val.depth = 2f;
			val.cullingMask = 0;
			PostProcessLayer val2 = _postProcessCamera.AddComponent<PostProcessLayer>();
			val2.Init((PostProcessResources)ExtensionMethods.GetFieldValue((object)((Component)MainCam.instance).gameObject.GetComponent<PostProcessLayer>(), "m_Resources"));
			val2.volumeTrigger = _postProcessCamera.transform;
			val2.volumeLayer = LayerMask.op_Implicit(1 << LayerMask.NameToLayer("Default Post"));
			val2.antialiasingMode = (Antialiasing)1;
		}

		private void SetupLayerCurtain()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_007c: 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)
			_curtain = new GameObject("Curtain");
			_curtain.transform.SetParent(((Component)this).transform);
			_curtain.SetActive(false);
			Canvas val = _curtain.AddComponent<Canvas>();
			val.sortingLayerID = SortingLayer.NameToID("MostFront");
			val.sortingOrder = 10;
			Image val2 = _curtain.AddComponent<Image>();
			((Graphic)val2).color = new Color(0.15f, 0.15f, 0.15f, 0.95f);
			((Graphic)val2).rectTransform.sizeDelta = new Vector2((float)Screen.width, (float)Screen.height);
		}

		protected virtual void OnEnable()
		{
			((Behaviour)((Component)MainCam.instance).gameObject.GetComponent<PostProcessLayer>()).enabled = false;
			_postProcessCamera.SetActive(true);
			if (!((Object)(object)Animation == (Object)null))
			{
				RefreshParticles();
				((Component)Animation).gameObject.SetActive(false);
				_curtain.SetActive(true);
				SetKeyframe(_prevKeyframe);
			}
		}

		protected virtual void OnDisable()
		{
			_postProcessCamera.SetActive(false);
			((Behaviour)((Component)MainCam.instance).gameObject.GetComponent<PostProcessLayer>()).enabled = true;
			if (!((Object)(object)Animation == (Object)null))
			{
				RefreshParticles();
				_curtain.SetActive(false);
				GameObject gameObject = ((Component)Animation).gameObject;
				AnimationKeyframe val = Animation.Keyframes[0];
				for (int i = 0; i < val.ComponentValues.Count; i++)
				{
					PropertyExtensions.WriteProperty<ILinearProperty>(gameObject, val.ComponentValues[i]);
				}
				gameObject.SetActive(true);
				_prevKeyframe = KeyframeIndex;
				SetKeyframe(-1);
			}
		}

		protected virtual void Update()
		{
			if (Object.op_Implicit((Object)(object)Editor) && !Editor.IsSimulating && Object.op_Implicit((Object)(object)Animation))
			{
				Refresh();
			}
		}

		public void Refresh()
		{
			if (Object.op_Implicit((Object)(object)Animation))
			{
				if (((Component)Animation).gameObject.activeSelf)
				{
					((Component)Animation).gameObject.SetActive(false);
				}
				if (KeyframeIndex >= Animation.Keyframes.Count)
				{
					SetKeyframe(Animation.Keyframes.Count - 1);
				}
				RefreshKeyframeValues();
				UpdateTraceLine();
			}
		}

		private void RefreshParticles()
		{
			//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)
			if (Object.op_Implicit((Object)(object)_particles))
			{
				GameObjectUtils.DestroyImmediateSafe(_particles);
			}
			GameObject val = GameObject.Find("/Game/Visual/Rendering /FrontParticles");
			_particles = Object.Instantiate<GameObject>(val, Vector3.zero, Quaternion.identity, ((Component)this).transform);
			ParticleSystem[] componentsInChildren = _particles.GetComponentsInChildren<ParticleSystem>();
			foreach (ParticleSystem val2 in componentsInChildren)
			{
				((Component)val2).gameObject.layer = 30;
				val2.Play();
			}
		}

		public void AddAnimation(GameObject go)
		{
			if ((Object)(object)go.GetComponent<MapObjectAnimation>() != (Object)null)
			{
				throw new ArgumentException("MapObjectAnimation already exists on " + ((Object)go).name);
			}
			go.SetActive(false);
			MapObjectAnimation val = go.AddComponent<MapObjectAnimation>();
			val.PlayOnAwake = false;
			go.SetActive(true);
			SetAnimation(val);
		}

		public void SetAnimation(MapObjectAnimation newAnimation)
		{
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			if ((Object)(object)newAnimation == (Object)(object)Animation)
			{
				return;
			}
			if ((Object)(object)newAnimation == (Object)null)
			{
				((Component)Animation).gameObject.SetActive(true);
				_curtain.SetActive(false);
				Editor.OverrideActiveMapObject(null);
				Editor.ClearSelected();
				Editor.AddSelected(((Component)Animation).gameObject);
				Animation = null;
				SetKeyframe(-1);
				RefreshParticles();
				return;
			}
			Animation = newAnimation;
			Editor.ClearSelected();
			((Component)Animation).gameObject.SetActive(false);
			_curtain.SetActive(true);
			RefreshParticles();
			ILinearProperty[] properties = MapObjectExtensions.ReadMapObject((Component)(object)Animation).GetProperties<ILinearProperty>();
			if (Animation.Keyframes.Count == 0)
			{
				Animation.Initialize(new AnimationKeyframe(properties));
			}
			Animation.Keyframes[0].ComponentValues = properties.ToList();
			SetKeyframe(0);
		}

		public void AddKeyframe()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			AnimationKeyframe item = new AnimationKeyframe(Animation.Keyframes.Last());
			int count = Animation.Keyframes.Count;
			if (Animation.Keyframes.Count == 0)
			{
				ILinearProperty[] properties = MapObjectExtensions.ReadMapObject((Component)(object)Animation).GetProperties<ILinearProperty>();
				Animation.PlayOnAwake = false;
				Animation.Initialize(new AnimationKeyframe(properties));
			}
			Animation.Keyframes.Insert(count, item);
			Editor.AnimationHandler.SetKeyframe(count);
			Editor.TakeSnaphot();
		}

		public void DeleteKeyframe(int index)
		{
			Animation.Keyframes.RemoveAt(index);
			if (Editor.AnimationHandler.KeyframeIndex >= Animation.Keyframes.Count)
			{
				Editor.AnimationHandler.SetKeyframe(Animation.Keyframes.Count - 1);
			}
			Editor.TakeSnaphot();
		}

		public void ToggleAnimation(GameObject target)
		{
			if (Object.op_Implicit((Object)(object)Animation))
			{
				SetAnimation(null);
			}
			else if (Object.op_Implicit((Object)(object)target.GetComponent<MapObjectAnimation>()))
			{
				SetAnimation(target.GetComponent<MapObjectAnimation>());
			}
			else
			{
				AddAnimation(target);
			}
		}

		public void SetKeyframe(int frameIndex)
		{
			if (Object.op_Implicit((Object)(object)KeyframeMapObject))
			{
				GameObjectUtils.DestroyImmediateSafe(KeyframeMapObject);
				KeyframeMapObject = null;
			}
			KeyframeIndex = frameIndex;
			if (Keyframe != null)
			{
				SpawnKeyframeMapObject(Keyframe, delegate(GameObject instance)
				{
					Renderer[] componentsInChildren = instance.GetComponentsInChildren<Renderer>();
					foreach (Renderer val in componentsInChildren)
					{
						((Component)val).gameObject.layer = 30;
					}
					instance.transform.SetAsLastSibling();
					KeyframeMapObject = instance;
					Editor.ClearSelected();
					Editor.AddSelected(instance);
					Editor.OverrideActiveMapObject(instance);
				});
			}
			UpdateTraceLine();
		}

		private void UpdateTraceLine()
		{
			//IL_0066: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			if ((Object)(object)Animation != (Object)null && KeyframeIndex > 0)
			{
				for (int i = 0; i <= KeyframeIndex; i++)
				{
					list.Add((i == KeyframeIndex) ? KeyframeMapObject.transform.position : PositionProperty.op_Implicit((PositionProperty)(((object)Animation.Keyframes[i].GetComponentValue<PositionProperty>()) ?? ((object)new PositionProperty()))));
				}
			}
			_lineRenderer.SetPositions(list);
		}

		private void SpawnKeyframeMapObject(AnimationKeyframe frame, Action<GameObject> cb)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			MapObjectData val = MapObjectExtensions.ReadMapObject((Component)(object)Animation);
			val.MapObjectId += ":keyframeMapObject";
			val.Active = true;
			val.SetProperty<AnimationProperty>(new AnimationProperty());
			((MapObjectManager)MapsExtendedEditor.MapObjectManager).Instantiate(val, ((Component)this).transform, (Action<GameObject>)delegate(GameObject instance)
			{
				Debug.Assert((Object)(object)instance.GetComponent<MapObjectAnimation>() == (Object)null, "Spawned object should not have a MapObjectAnimation component");
				for (int i = 0; i < Animation.Keyframes[0].ComponentValues.Count; i++)
				{
					PropertyExtensions.WriteProperty<ILinearProperty>(instance, frame.ComponentValues[i]);
				}
				cb(instance);
			});
		}

		private void RefreshKeyframeValues()
		{
			if (!((Object)(object)KeyframeMapObject == (Object)null) && Keyframe != null)
			{
				ILinearProperty[] properties = MapObjectExtensions.ReadMapObject(KeyframeMapObject).GetProperties<ILinearProperty>();
				Keyframe.ComponentValues = properties.ToList();
				if (KeyframeIndex == 0)
				{
					RefreshBaseMapObject();
				}
			}
		}

		private void RefreshBaseMapObject()
		{
			MapObjectAnimation animation = Animation;
			if (animation != null && !LinqExtensions.IsNullOrEmpty<AnimationKeyframe>((IList<AnimationKeyframe>)animation.Keyframes))
			{
				for (int i = 0; i < Animation.Keyframes[0].ComponentValues.Count; i++)
				{
					PropertyExtensions.WriteProperty<ILinearProperty>((Component)(object)Animation, Animation.Keyframes[0].ComponentValues[i]);
				}
			}
		}
	}
	public class MapEditorInputHandler : MonoBehaviour
	{
		private const float ClickTimeMsEpsilon = 500f;

		private const float ClickPositionEpsilon = 5f;

		private MapEditor _editor;

		private float _mouseDownSince;

		private Vector2 _mouseDownPosition;

		private Vector2 _originalViewportPosition;

		private bool _isSelecting;

		private bool _isMouseDown;

		private bool _isMiddleMouseDown;

		private Camera[] _cameras;

		protected virtual void Awake()
		{
			//IL_005d: 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)
			_editor = ((Component)this).gameObject.GetComponent<MapEditor>();
			_mouseDownSince = 0f;
			_isSelecting = false;
			KeyMonitor keyMonitor = ((Component)this).gameObject.AddComponent<KeyMonitor>();
			KeyCode[] array = new KeyCode[4];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			KeyCode[] array2 = (KeyCode[])(object)array;
			KeyCode[] array3 = array2;
			foreach (KeyCode key in array3)
			{
				keyMonitor.AddListener(key, delegate
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					HandleKeyDown(key);
				});
			}
		}

		protected virtual void Update()
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			if (!_editor.IsSimulating)
			{
				if (EditorInput.GetMouseButtonDown(0))
				{
					HandleMouseDown();
				}
				if (EditorInput.GetMouseButtonUp(0))
				{
					HandleMouseUp();
				}
				if (EditorInput.GetMouseButtonDown(2))
				{
					HandleMiddleMouseDown();
				}
				if (EditorInput.GetMouseButtonUp(2))
				{
					HandleMiddleMouseUp();
				}
				if (_isMiddleMouseDown)
				{
					MoveViewport();
				}
				if (EditorInput.GetKeyDown((KeyCode)304))
				{
					_editor.ToggleSnapToGrid(enabled: false);
				}
				if (EditorInput.GetKeyUp((KeyCode)304))
				{
					_editor.ToggleSnapToGrid(enabled: true);
				}
				if (EditorInput.GetKeyDown((KeyCode)127))
				{
					HandleDelete();
				}
				if (EditorInput.MouseScrollDelta.y > 0f || EditorInput.GetKeyDown((KeyCode)43) || EditorInput.GetKeyDown((KeyCode)270))
				{
					HandleZoom(1);
				}
				if (EditorInput.MouseScrollDelta.y < 0f || EditorInput.GetKeyDown((KeyCode)45) || EditorInput.GetKeyDown((KeyCode)269))
				{
					HandleZoom(-1);
				}
			}
		}

		private void HandleZoom(int direction)
		{
			if (!EventSystem.current.IsPointerOverGameObject())
			{
				if (direction > 0)
				{
					_editor.ZoomIn();
				}
				else
				{
					_editor.ZoomOut();
				}
			}
		}

		private void HandleDelete()
		{
			if (!((Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null))
			{
				_editor.DeleteSelectedMapObjects();
			}
		}

		private void HandleMouseDown()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!EventSystem.current.IsPointerOverGameObject())
			{
				_isMouseDown = true;
				_mouseDownSince = Time.time * 1000f;
				_mouseDownPosition = EditorInput.MousePosition;
				IEnumerable<GameObject> source = (from h in EditorUtils.GetMapObjectPartsAt(_mouseDownPosition)
					select ((Component)h).gameObject).Distinct();
				if (source.Any(_editor.SelectedMapObjectParts.Contains))
				{
					_editor.OnPointerDown();
					return;
				}
				_isSelecting = true;
				_editor.StartSelection();
			}
		}

		private void HandleMouseUp()
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if (_isMouseDown)
			{
				_isMouseDown = false;
				_editor.OnPointerUp();
				float num = Time.time * 1000f;
				Vector2 mousePosition = EditorInput.MousePosition;
				Vector2 val = _mouseDownPosition - mousePosition;
				if (((Vector2)(ref val)).magnitude <= 5f && num - _mouseDownSince <= 500f)
				{
					_editor.OnClickMapObjectParts(EditorUtils.GetMapObjectPartsAt(mousePosition));
				}
				if (_isSelecting)
				{
					_isSelecting = false;
					_editor.EndSelection();
				}
			}
		}

		private void HandleMiddleMouseDown()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!EventSystem.current.IsPointerOverGameObject())
			{
				_isMiddleMouseDown = true;
				_mouseDownPosition = EditorInput.MousePosition;
				_originalViewportPosition = Vector2.op_Implicit(((Component)MainCam.instance.cam).transform.position);
				_cameras = Object.FindObjectsOfType<Camera>();
			}
		}

		private void HandleMiddleMouseUp()
		{
			_isMiddleMouseDown = false;
		}

		private void MoveViewport()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Vector2.op_Implicit(MainCam.instance.cam.ScreenToWorldPoint(Vector2.op_Implicit(_mouseDownPosition)) - MainCam.instance.cam.ScreenToWorldPoint(Vector2.op_Implicit(EditorInput.MousePosition)));
			Vector2 val2 = _originalViewportPosition + val;
			Camera[] cameras = _cameras;
			foreach (Camera val3 in cameras)
			{
				((Component)val3).transform.position = new Vector3(val2.x, val2.y, ((Component)val3).transform.position.z);
			}
		}

		private void HandleKeyDown(KeyCode key)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null))
			{
				_editor.OnKeyDown(key);
			}
		}
	}
	public class MapEditorUI : MonoBehaviour
	{
		[SerializeField]
		private MapEditor _editor;

		[SerializeField]
		private Toolbar _toolbar;

		[SerializeField]
		private Window _mapObjectWindow;

		[SerializeField]
		private Window _inspectorWindow;

		[SerializeField]
		private Window _mapSettingsWindow;

		[SerializeField]
		private AnimationWindow _animationWindow;

		[SerializeField]
		private MapObjectInspector _inspector;

		private Texture2D _selectionTexture;

		private Window[] _windows;

		private bool[] _windowWasOpen;

		private Vector2 _resolution;

		private InspectorVector2Input _mapSizeInput;

		private InspectorSliderInput _viewportHeightInput;

		public MapEditor Editor
		{
			get
			{
				return _editor;
			}
			set
			{
				_editor = value;
			}
		}

		public Toolbar Toolbar
		{
			get
			{
				return _toolbar;
			}
			set
			{
				_toolbar = value;
			}
		}

		public Window MapObjectWindow
		{
			get
			{
				return _mapObjectWindow;
			}
			set
			{
				_mapObjectWindow = value;
			}
		}

		public Window InspectorWindow
		{
			get
			{
				return _inspectorWindow;
			}
			set
			{
				_inspectorWindow = value;
			}
		}

		public Window MapSettingsWindow
		{
			get
			{
				return _mapSettingsWindow;
			}
			set
			{
				_mapSettingsWindow = value;
			}
		}

		public AnimationWindow AnimationWindow
		{
			get
			{
				return _animationWindow;
			}
			set
			{
				_animationWindow = value;
			}
		}

		public MapObjectInspector Inspector
		{
			get
			{
				return _inspector;
			}
			set
			{
				_inspector = value;
			}
		}

		protected virtual void Awake()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Expected O, but got Unknown
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Expected O, but got Unknown
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Expected O, but got Unknown
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Expected O, but got Unknown
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Expected O, but got Unknown
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Expected O, but got Unknown
			//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0614: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_062b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_0653: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_0680: Unknown result type (might be due to invalid IL or missing references)
			//IL_0685: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0717: Unknown result type (might be due to invalid IL or missing references)
			//IL_0730: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d4: Unknown result type (might be due to invalid IL or missing references)
			_resolution = new Vector2((float)Screen.width, (float)Screen.height);
			Toolbar.FileMenu.AddItem(new MenuItemBuilder().Label("Open...").Action(new UnityAction(OnClickOpen)).KeyBinding(NamedKeyCode.O, NamedKeyCode.Ctrl));
			Toolbar.FileMenu.AddItem(new MenuItemBuilder().Label("Save").Action(new UnityAction(OnClickSave)).KeyBinding(NamedKeyCode.S, NamedKeyCode.Ctrl));
			Toolbar.FileMenu.AddItem(new MenuItemBuilder().Label("Save As...").Action(new UnityAction(OnClickSaveAs)).KeyBinding(NamedKeyCode.S, NamedKeyCode.Ctrl, NamedKeyCode.Shift));
			Toolbar.FileMenu.AddItem(new MenuItemBuilder().Label("Open Map Folder").Action(new UnityAction(OnClickOpenMapFolder)).Item());
			Toolbar.EditMenu.AddItem(new MenuItemBuilder().Label("Copy").Action(new UnityAction(OnClickCopy)).KeyBinding(NamedKeyCode.C, NamedKeyCode.Ctrl));
			Toolbar.EditMenu.AddItem(new MenuItemBuilder().Label("Paste").Action(new UnityAction(OnClickPaste)).KeyBinding(NamedKeyCode.V, NamedKeyCode.Ctrl));
			Toolbar.EditMenu.AddItem(new MenuItemBuilder().Label("Undo").Action(new UnityAction(OnClickUndo)).KeyBinding(NamedKeyCode.Z, NamedKeyCode.Ctrl));
			Toolbar.EditMenu.AddItem(new MenuItemBuilder().Label("Redo").Action(new UnityAction(OnClickRedo)).KeyBinding(NamedKeyCode.Z, NamedKeyCode.Ctrl, NamedKeyCode.Shift));
			Toolbar.EditMenu.AddItem(new MenuItemBuilder().Label("Reset Camera Position").Action(new UnityAction(OnClickResetCameraPosition)));
			Toolbar.WindowMenu.AddItem(new MenuItemBuilder().Label("Map Objects").Action(new UnityAction(OpenMapObjectWindow)));
			Toolbar.WindowMenu.AddItem(new MenuItemBuilder().Label("Inspector").Action(new UnityAction(OpenInspectorWindow)));
			Toolbar.WindowMenu.AddItem(new MenuItemBuilder().Label("Map Settings").Action(new UnityAction(OpenMapSettingsWindow)));
			Dictionary<string, List<(string, Type)>> dictionary = new Dictionary<string, List<(string, Type)>> { 
			{
				"",
				new List<(string, Type)>()
			} };
			foreach (var mapObjectAttribute in MapsExtendedEditor.MapObjectAttributes)
			{
				Type item2 = mapObjectAttribute.Item1;
				string item3 = mapObjectAttribute.Item2;
				string item4 = mapObjectAttribute.Item3;
				string key = item4 ?? "";
				if (!dictionary.ContainsKey(key))
				{
					dictionary.Add(key, new List<(string, Type)>());
				}
				dictionary[key].Add((item3, item2));
			}
			foreach (string item5 in dictionary.Keys.Where((string k) => k != ""))
			{
				MenuItemBuilder menuItemBuilder = new MenuItemBuilder().Label(item5);
				foreach (var item6 in dictionary[item5])
				{
					(string, Type) entry2 = item6;
					menuItemBuilder.SubItem(delegate(MenuItemBuilder b)
					{
						//IL_0018: Unknown result type (might be due to invalid IL or missing references)
						//IL_0022: Expected O, but got Unknown
						b.Label(entry2.Item1).Action(new UnityAction(Action));
					});
					void Action()
					{
						Editor.CreateMapObject(entry2.Item2);
					}
				}
				Toolbar.MapObjectMenu.AddItem(menuItemBuilder.Item());
			}
			foreach (var item7 in dictionary[""])
			{
				(string, Type) entry = item7;
				MenuItemBuilder menuItemBuilder2 = new MenuItemBuilder().Label(entry.Item1).Action(new UnityAction(Action));
				Toolbar.MapObjectMenu.AddItem(menuItemBuilder2.Item());
				void Action()
				{
					Editor.CreateMapObject(entry.Item2);
				}
			}
			Toolbar.GridSizeSlider.value = Editor.GridSize;
			((UnityEvent<float>)(object)Toolbar.GridSizeSlider.onValueChanged).AddListener((UnityAction<float>)delegate(float val)
			{
				Editor.GridSize = val;
			});
			Toolbar toolbar = Toolbar;
			toolbar.OnToggleSimulation = (Action<bool>)Delegate.Combine(toolbar.OnToggleSimulation, (Action<bool>)delegate(bool simulated)
			{
				if (simulated)
				{
					Editor.StartSimulation();
					for (int i = 0; i < _windows.Length; i++)
					{
						_windowWasOpen[i] = ((Component)_windows[i]).gameObject.activeSelf;
						((Component)_windows[i]).gameObject.SetActive(false);
					}
				}
				else
				{
					Editor.StopSimulation();
					for (int j = 0; j < _windows.Length; j++)
					{
						((Component)_windows[j]).gameObject.SetActive(_windowWasOpen[j]);
					}
				}
				Menu.MenuState state = (simulated ? Menu.MenuState.DISABLED : Menu.MenuState.INACTIVE);
				Toolbar.FileMenu.SetState(state);
				Toolbar.EditMenu.SetState(state);
				Toolbar.MapObjectMenu.SetState(state);
				Toolbar.WindowMenu.SetState(state);
				((Component)((Component)Toolbar.GridSizeSlider).transform.parent.parent).gameObject.SetActive(!simulated);
			});
			Vector2 sizeDelta = ((Component)MapObjectWindow).gameObject.GetComponent<RectTransform>().sizeDelta;
			((Component)MapObjectWindow).transform.position = new Vector3((float)Screen.width - sizeDelta.x / 2f - 5f, (float)Screen.height - sizeDelta.y / 2f - 35f, 0f);
			Vector2 sizeDelta2 = ((Component)InspectorWindow).gameObject.GetComponent<RectTransform>().sizeDelta;
			((Component)InspectorWindow).transform.position = new Vector3((float)Screen.width - sizeDelta2.x / 2f - 5f, ((Component)MapObjectWindow).transform.position.y - sizeDelta2.y - 5f, 0f);
			Vector2 sizeDelta3 = ((Component)MapSettingsWindow).gameObject.GetComponent<RectTransform>().sizeDelta;
			((Component)MapSettingsWindow).transform.position = new Vector3((float)Screen.width - sizeDelta3.x / 2f - 5f, ((Component)InspectorWindow).transform.position.y - sizeDelta3.y - 5f, 0f);
			Vector2 sizeDelta4 = ((Component)AnimationWindow).gameObject.GetComponent<RectTransform>().sizeDelta;
			((Component)AnimationWindow).transform.position = new Vector3(sizeDelta4.x / 2f + 5f, (float)Screen.height - sizeDelta4.y / 2f - 35f, 0f);
			foreach (MenuItem item8 in Toolbar.MapObjectMenu.Items)
			{
				if (item8.items == null)
				{
					GameObject val2 = CreateButton(item8);
					val2.transform.SetParent(MapObjectWindow.Content.transform);
					continue;
				}
				Foldout component = Object.Instantiate<GameObject>(Assets.FoldoutPrefab, MapObjectWindow.Content.transform).GetComponent<Foldout>();
				component.Label.text = item8.label;
				foreach (MenuItem item9 in item8.items)
				{
					GameObject val3 = CreateButton(item9);
					val3.transform.SetParent(component.Content.transform);
				}
			}
			GameObject val4 = Object.Instantiate<GameObject>(Assets.InspectorVector2InputPrefab, MapSettingsWindow.Content.transform);
			_mapSizeInput = val4.GetComponent<InspectorVector2Input>();
			_mapSizeInput.Label.text = "Map Size";
			_mapSizeInput.Input.MinX = 100f;
			_mapSizeInput.Input.MinY = 100f;
			_mapSizeInput.Input.Value = Editor.MapSettings.MapSize;
			Vector2Input input = _mapSizeInput.Input;
			input.OnChanged = (Action<Vector2, ChangeType>)Delegate.Combine(input.OnChanged, new Action<Vector2, ChangeType>(OnChangeMapSize));
			GameObject val5 = Object.Instantiate<GameObject>(Assets.InspectorSliderInputPrefab, MapSettingsWindow.Content.transform);
			_viewportHeightInput = val5.GetComponent<InspectorSliderInput>();
			_viewportHeightInput.Label.text = "Viewport Height";
			_viewportHeightInput.Input.Slider.minValue = 100f;
			_viewportHeightInput.Input.Slider.maxValue = 10000f;
			_viewportHeightInput.Input.Slider.wholeNumbers = true;
			_viewportHeightInput.Input.Value = Editor.MapSettings.ViewportHeight;
			TextSliderInput input2 = _viewportHeightInput.Input;
			input2.OnChanged = (Action<float, ChangeType>)Delegate.Combine(input2.OnChanged, new Action<float, ChangeType>(OnChangeViewportHeight));
			static GameObject CreateButton(MenuItem item)
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Expected O, but got Unknown
				//IL_0021: 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_004a: Expected O, but got Unknown
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: 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_00a3: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_012f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0139: Expected O, but got Unknown
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Expected O, but got Unknown
				//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
				GameObject val6 = new GameObject("Button");
				Image val7 = val6.AddComponent<Image>();
				((Graphic)val7).color = Color.white;
				Button val8 = val6.AddComponent<Button>();
				((UnityEvent)val8.onClick).AddListener((UnityAction)delegate
				{
					UnityEvent action = item.action;
					if (action != null)
					{
						action.Invoke();
					}
				});
				((Selectable)val8).targetGraphic = (Graphic)(object)val7;
				ColorBlock colors = default(ColorBlock);
				((ColorBlock)(ref colors)).normalColor = Color32.op_Implicit(new Color32((byte)40, (byte)40, (byte)40, byte.MaxValue));
				((ColorBlock)(ref colors)).highlightedColor = Color32.op_Implicit(new Color32((byte)50, (byte)50, (byte)50, byte.MaxValue));
				((ColorBlock)(ref colors)).pressedColor = Color32.op_Implicit(new Color32((byte)60, (byte)60, (byte)60, byte.MaxValue));
				((ColorBlock)(ref colors)).disabledColor = Color32.op_Implicit(new Color32((byte)40, (byte)40, (byte)40, byte.MaxValue));
				((ColorBlock)(ref colors)).fadeDuration = 0.1f;
				((ColorBlock)(ref colors)).colorMultiplier = 1f;
				((Selectable)val8).colors = colors;
				Navigation navigation = default(Navigation);
				((Navigation)(ref navigation)).mode = (Mode)0;
				((Selectable)val8).navigation = navigation;
				LayoutElement val9 = val6.AddComponent<LayoutElement>();
				val9.preferredHeight = 20f;
				HorizontalLayoutGroup val10 = val6.AddComponent<HorizontalLayoutGroup>();
				((LayoutGroup)val10).padding = new RectOffset(6, 0, 0, 0);
				((LayoutGroup)val10).childAlignment = (TextAnchor)3;
				((HorizontalOrVerticalLayoutGroup)val10).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)val10).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)val10).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)val10).childForceExpandHeight = false;
				GameObject val11 = new GameObject("Text");
				val11.transform.SetParent(val6.transform);
				Text val12 = val11.AddComponent<Text>();
				val12.fontSize = 12;
				val12.font = Font.CreateDynamicFontFromOSFont("Arial", 12);
				((Graphic)val12).color = Color32.op_Implicit(new Color32((byte)200, (byte)200, (byte)200, byte.MaxValue));
				val12.text = item.label;
				return val6;
			}
		}

		protected virtual void Start()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			_windows = new Window[4] { MapObjectWindow, InspectorWindow, MapSettingsWindow, AnimationWindow };
			_windowWasOpen = new bool[_windows.Length];
			_selectionTexture = UIUtils.GetTexture(2, 2, Color32.op_Implicit(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)20)));
		}

		protected virtual void Update()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			if (Editor.IsSimulating)
			{
				return;
			}
			Vector2 sizeDelta = ((Component)this).GetComponent<RectTransform>().sizeDelta;
			if (sizeDelta != _resolution)
			{
				float num = 35f;
				Window[] windows = _windows;
				foreach (Window window in windows)
				{
					Vector2 

plugins\NetTopologySuite.dll

Decompiled a year ago
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using NetTopologySuite.Algorithm;
using NetTopologySuite.Algorithm.Distance;
using NetTopologySuite.Algorithm.Locate;
using NetTopologySuite.EdgeGraph;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries.Implementation;
using NetTopologySuite.Geometries.Utilities;
using NetTopologySuite.GeometriesGraph;
using NetTopologySuite.GeometriesGraph.Index;
using NetTopologySuite.IO;
using NetTopologySuite.IO.GML2;
using NetTopologySuite.Index;
using NetTopologySuite.Index.Chain;
using NetTopologySuite.Index.IntervalRTree;
using NetTopologySuite.Index.KdTree;
using NetTopologySuite.Index.Quadtree;
using NetTopologySuite.Index.Strtree;
using NetTopologySuite.Mathematics;
using NetTopologySuite.Noding;
using NetTopologySuite.Noding.Snap;
using NetTopologySuite.Noding.Snapround;
using NetTopologySuite.Operation;
using NetTopologySuite.Operation.Buffer;
using NetTopologySuite.Operation.Distance;
using NetTopologySuite.Operation.Overlay;
using NetTopologySuite.Operation.Overlay.Snap;
using NetTopologySuite.Operation.OverlayNG;
using NetTopologySuite.Operation.Predicate;
using NetTopologySuite.Operation.Relate;
using NetTopologySuite.Operation.Union;
using NetTopologySuite.Operation.Valid;
using NetTopologySuite.Planargraph;
using NetTopologySuite.Planargraph.Algorithm;
using NetTopologySuite.Precision;
using NetTopologySuite.Shape.Fractal;
using NetTopologySuite.Triangulate.QuadEdge;
using NetTopologySuite.Utilities;
using RTools_NTS.Util;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDelaySign(false)]
[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]
[assembly: Guid("6B7EB658-792E-4178-B853-8AEB851513A9")]
[assembly: InternalsVisibleTo("NetTopologySuite.Tests.NUnit, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e5a9697e3d378de4bdd1607b9a6ea7884823d3909f8de55b573416d9adb0ae25eebc39007d71a7228c500d6e846d54dcc2cd839056c38c0a5e86b73096d90504f753ea67c9b5e61ecfdb8edf0f1dfaf0455e9a0f9e124e16777baefcda2af9a5a9e48f0c3502891c79444dc2d75aa50b75d148e16f1401dcb18bc1638cc764a9")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("NetTopologySuite - Team")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2006 - 2021 NetTopologySuite - Team, Diego Guidi, John Diss (www.newgrove.com), Felix Obermaier (www.ivv-aachen.de), Todd Jackson, Joe Amenta")]
[assembly: AssemblyDescription("The NTS Topology Suite is an API for modelling and manipulating 2-dimensional linear geometry. It provides numerous geometric predicates and functions. NTS conforms to the Simple Features Specification.")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.4.0 (compatible with JTS 1.18.2-SNAPSHOT)+79f535725d46783c032fa437b8635e117abf5b8a")]
[assembly: AssemblyProduct("NetTopologySuite")]
[assembly: AssemblyTitle("NetTopologySuite")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
}
internal static class Consts
{
	public const string PublicKeyToken = "0024000004800000940000000602000000240000525341310004000001000100e5a9697e3d378de4bdd1607b9a6ea7884823d3909f8de55b573416d9adb0ae25eebc39007d71a7228c500d6e846d54dcc2cd839056c38c0a5e86b73096d90504f753ea67c9b5e61ecfdb8edf0f1dfaf0455e9a0f9e124e16777baefcda2af9a5a9e48f0c3502891c79444dc2d75aa50b75d148e16f1401dcb18bc1638cc764a9";
}
namespace RTools_NTS.Util
{
	public class CharBuffer
	{
		private int capacity = 128;

		private char[] buffer;

		private int headIndex;

		private int tailIndex;

		public int Length
		{
			get
			{
				return tailIndex - headIndex;
			}
			set
			{
				tailIndex = headIndex + value;
				if (tailIndex >= capacity)
				{
					throw new IndexOutOfRangeException("Tail index greater than capacity");
				}
			}
		}

		public int Capacity => capacity;

		public char this[int index]
		{
			get
			{
				return buffer[index + headIndex];
			}
			set
			{
				buffer[index + headIndex] = value;
			}
		}

		public CharBuffer()
		{
			buffer = new char[capacity];
		}

		public CharBuffer(int capacity)
		{
			this.capacity = capacity;
			buffer = new char[capacity];
		}

		protected void Grow(int requestedLen)
		{
			int val = Math.Max(capacity * 2, requestedLen);
			val = Math.Max(val, 16);
			char[] destinationArray = new char[val];
			Array.Copy(buffer, 0, destinationArray, 0, capacity);
			buffer = destinationArray;
			capacity = val;
		}

		protected void CheckCapacity(int requestedLength)
		{
			if (requestedLength + headIndex >= capacity)
			{
				if (requestedLength + headIndex > capacity >> 1 && requestedLength < capacity - 1)
				{
					ShiftToZero();
				}
				else
				{
					Grow(0);
				}
			}
		}

		protected void ShiftToZero()
		{
			int length = Length;
			for (int i = 0; i < length; i++)
			{
				buffer[i] = buffer[i + headIndex];
			}
			headIndex = 0;
			tailIndex = length;
		}

		public void SetBuffer(char[] b, int len)
		{
			capacity = b.Length;
			buffer = b;
			headIndex = 0;
			tailIndex = len;
		}

		public void Append(char c)
		{
			if (tailIndex >= capacity)
			{
				CheckCapacity(Length + 1);
			}
			buffer[tailIndex++] = c;
		}

		public void Append(string s)
		{
			if (s.Length + tailIndex >= capacity)
			{
				CheckCapacity(Length + s.Length);
			}
			for (int i = 0; i < s.Length; i++)
			{
				buffer[tailIndex++] = s[i];
			}
		}

		public void Append(CharBuffer s)
		{
			if (s.Length + tailIndex >= capacity)
			{
				CheckCapacity(Length + s.Length);
			}
			for (int i = 0; i < s.Length; i++)
			{
				buffer[tailIndex++] = s[i];
			}
		}

		public void Remove(int i)
		{
			Remove(i, 1);
		}

		public void Remove(int i, int n)
		{
			n = Math.Min(n, Length);
			if (i == 0)
			{
				headIndex += n;
			}
			else
			{
				Array.Copy(buffer, i + headIndex + n, buffer, i + headIndex, tailIndex - (i + headIndex + n));
			}
		}

		public int IndexOf(char c)
		{
			for (int i = headIndex; i < tailIndex; i++)
			{
				if (buffer[i] == c)
				{
					return i - headIndex;
				}
			}
			return -1;
		}

		public void Clear()
		{
			headIndex = 0;
			tailIndex = 0;
		}

		public override string ToString()
		{
			return new string(buffer, headIndex, tailIndex - headIndex);
		}
	}
	public class StreamTokenizerUntermException : Exception
	{
		public StreamTokenizerUntermException(string msg)
			: base(msg)
		{
		}
	}
	public class StreamTokenizerUntermQuoteException : StreamTokenizerUntermException
	{
		public StreamTokenizerUntermQuoteException(string msg)
			: base(msg)
		{
		}
	}
	public class StreamTokenizerUntermCommentException : StreamTokenizerUntermException
	{
		public StreamTokenizerUntermCommentException(string msg)
			: base(msg)
		{
		}
	}
	[Flags]
	public enum CharTypeBits : byte
	{
		Word = 1,
		Comment = 2,
		Whitespace = 4,
		Quote = 8,
		Digit = 0x10,
		HexDigit = 0x20,
		Eof = 0x40
	}
	public class StreamTokenizerSettings
	{
		private byte[] charTypes;

		private bool grabWhitespace;

		private bool grabEol;

		private bool slashSlashComments;

		private bool slashStarComments;

		private bool grabComments;

		private bool doUntermCheck;

		private bool parseNumbers;

		private bool parseHexNumbers;

		public byte[] CharTypes => charTypes;

		public bool GrabWhitespace
		{
			get
			{
				return grabWhitespace;
			}
			set
			{
				grabWhitespace = value;
			}
		}

		public bool GrabEol
		{
			get
			{
				return grabEol;
			}
			set
			{
				grabEol = value;
			}
		}

		public bool SlashSlashComments
		{
			get
			{
				return slashSlashComments;
			}
			set
			{
				slashSlashComments = value;
			}
		}

		public bool SlashStarComments
		{
			get
			{
				return slashStarComments;
			}
			set
			{
				slashStarComments = value;
			}
		}

		public bool GrabComments
		{
			get
			{
				return grabComments;
			}
			set
			{
				grabComments = value;
			}
		}

		public bool DoUntermCheck
		{
			get
			{
				return doUntermCheck;
			}
			set
			{
				doUntermCheck = value;
			}
		}

		public bool ParseNumbers
		{
			get
			{
				return parseNumbers;
			}
			set
			{
				if (value)
				{
					for (int i = 48; i <= 57; i++)
					{
						charTypes[i] |= 16;
					}
				}
				else
				{
					byte b = 16;
					for (int j = 48; j <= 57; j++)
					{
						charTypes[j] &= (byte)(~b);
					}
				}
				parseNumbers = value;
			}
		}

		public bool ParseHexNumbers
		{
			get
			{
				return parseHexNumbers;
			}
			set
			{
				parseHexNumbers = value;
				if (parseHexNumbers)
				{
					for (int i = 48; i <= 57; i++)
					{
						charTypes[i] |= 32;
					}
					for (int j = 65; j <= 70; j++)
					{
						charTypes[j] |= 32;
					}
					for (int k = 97; k <= 102; k++)
					{
						charTypes[k] |= 32;
					}
					charTypes[120] |= 32;
				}
				else
				{
					byte b = 32;
					for (int l = 65; l <= 70; l++)
					{
						charTypes[l] &= (byte)(~b);
					}
					for (int m = 97; m <= 102; m++)
					{
						charTypes[m] &= (byte)(~b);
					}
					charTypes[120] &= (byte)(~b);
				}
			}
		}

		public StreamTokenizerSettings()
		{
			charTypes = new byte[StreamTokenizer.NChars + 1];
			SetDefaults();
		}

		public StreamTokenizerSettings(StreamTokenizerSettings other)
		{
			Copy(other);
		}

		public void Copy(StreamTokenizerSettings other)
		{
			charTypes = new byte[StreamTokenizer.NChars + 1];
			Array.Copy(other.charTypes, 0, charTypes, 0, charTypes.Length);
			grabWhitespace = other.grabWhitespace;
			grabEol = other.grabEol;
			slashSlashComments = other.slashSlashComments;
			slashStarComments = other.slashStarComments;
			grabComments = other.grabComments;
			doUntermCheck = other.doUntermCheck;
			parseHexNumbers = other.parseHexNumbers;
		}

		public bool SetDefaults()
		{
			slashStarComments = false;
			grabComments = false;
			slashSlashComments = false;
			grabWhitespace = false;
			doUntermCheck = true;
			grabEol = false;
			ResetCharTypeTable();
			ParseNumbers = true;
			ParseHexNumbers = true;
			WordChars(65, 90);
			WordChars(97, 122);
			WhitespaceChars(0, 32);
			QuoteChar(39);
			QuoteChar(34);
			WordChars(48, 57);
			return true;
		}

		public bool SetupForCodeParse()
		{
			GrabWhitespace = true;
			GrabComments = true;
			SlashSlashComments = true;
			DoUntermCheck = true;
			SlashStarComments = true;
			WordChar(95);
			ParseNumbers = true;
			ParseHexNumbers = true;
			return true;
		}

		public void ResetCharTypeTable()
		{
			Array.Clear(charTypes, 0, charTypes.Length);
			charTypes[StreamTokenizer.NChars] = 64;
		}

		public void WordChar(int c)
		{
			charTypes[c] |= 1;
		}

		public void WordChars(int startChar, int endChar)
		{
			for (int i = startChar; i <= endChar; i++)
			{
				charTypes[i] |= 1;
			}
		}

		public void WordChars(string s)
		{
			for (int i = 0; i < s.Length; i++)
			{
				charTypes[(uint)s[i]] |= 1;
			}
		}

		public void WhitespaceChar(int c)
		{
			charTypes[c] = 4;
		}

		public void WhitespaceChars(int startChar, int endChar)
		{
			for (int i = startChar; i <= endChar; i++)
			{
				charTypes[i] = 4;
			}
		}

		public void OrdinaryChars(int startChar, int endChar)
		{
			for (int i = startChar; i <= endChar; i++)
			{
				charTypes[i] = 0;
			}
		}

		public void OrdinaryChar(int c)
		{
			charTypes[c] = 0;
		}

		public void CommentChar(int c)
		{
			charTypes[c] = 2;
		}

		public void QuoteChar(int c)
		{
			charTypes[c] = 8;
		}

		public string CharTypeToString(byte ctype)
		{
			StringBuilder stringBuilder = new StringBuilder();
			if (IsCharType(ctype, CharTypeBits.Quote))
			{
				stringBuilder.Append('q');
			}
			if (IsCharType(ctype, CharTypeBits.Comment))
			{
				stringBuilder.Append('m');
			}
			if (IsCharType(ctype, CharTypeBits.Whitespace))
			{
				stringBuilder.Append('w');
			}
			if (IsCharType(ctype, CharTypeBits.Digit))
			{
				stringBuilder.Append('d');
			}
			if (IsCharType(ctype, CharTypeBits.Word))
			{
				stringBuilder.Append('a');
			}
			if (IsCharType(ctype, CharTypeBits.Eof))
			{
				stringBuilder.Append('e');
			}
			if (stringBuilder.Length == 0)
			{
				stringBuilder.Append('c');
			}
			return stringBuilder.ToString();
		}

		public bool IsCharType(byte ctype, CharTypeBits type)
		{
			return ((uint)ctype & (uint)type) != 0;
		}

		public bool IsCharType(char c, CharTypeBits type)
		{
			return ((uint)charTypes[(uint)c] & (uint)type) != 0;
		}

		public bool IsCharType(int c, CharTypeBits type)
		{
			return ((uint)charTypes[c] & (uint)type) != 0;
		}

		public void Display()
		{
			Display(string.Empty);
		}

		public void Display(string prefix)
		{
		}
	}
	public class StreamTokenizer : IEnumerable<Token>, IEnumerable
	{
		private enum NextTokenState
		{
			Start,
			Whitespace,
			Word,
			Quote,
			EndQuote,
			MaybeNumber,
			MaybeComment,
			MaybeHex,
			HexGot0x,
			HexNumber,
			LineComment,
			BlockComment,
			EndBlockComment,
			Char,
			Eol,
			Eof,
			Invalid
		}

		public static readonly int NChars = 128;

		private static readonly int Eof = NChars;

		private TextReader textReader;

		private int lineNumber;

		private CharBuffer backString;

		private CharBuffer nextTokenSb;

		private CharBuffer tmpSb;

		private CharBuffer expSb;

		private StreamTokenizerSettings settings;

		public TextReader TextReader
		{
			get
			{
				return textReader;
			}
			set
			{
				textReader = value;
			}
		}

		public StreamTokenizerSettings Settings => settings;

		public StreamTokenizer()
		{
			Initialize();
		}

		public StreamTokenizer(TextReader sr)
		{
			Initialize();
			textReader = sr;
		}

		public StreamTokenizer(TextReader sr, StreamTokenizerSettings tokenizerSettings)
		{
			settings = tokenizerSettings;
			Initialize();
			textReader = sr;
		}

		public StreamTokenizer(string str)
		{
			Initialize();
			textReader = new StringReader(str);
		}

		private void Initialize()
		{
			backString = new CharBuffer(32);
			nextTokenSb = new CharBuffer(1024);
			InitializeStream();
			if (settings == null)
			{
				settings = new StreamTokenizerSettings();
				settings.SetDefaults();
			}
			expSb = new CharBuffer();
			tmpSb = new CharBuffer();
		}

		private void InitializeStream()
		{
			lineNumber = 1;
			textReader = null;
		}

		public void Display()
		{
			Display(string.Empty);
		}

		public void Display(string prefix)
		{
			if (settings != null)
			{
				settings.Display(prefix + "    ");
			}
		}

		private NextTokenState PickNextState(byte ctype, int c)
		{
			return PickNextState(ctype, c, NextTokenState.Start);
		}

		private NextTokenState PickNextState(byte ctype, int c, NextTokenState excludeState)
		{
			if (c == 47)
			{
				return NextTokenState.MaybeComment;
			}
			if (excludeState != NextTokenState.MaybeHex && settings.ParseHexNumbers && c == 48)
			{
				return NextTokenState.MaybeHex;
			}
			if (excludeState != NextTokenState.MaybeNumber && settings.ParseNumbers && (settings.IsCharType(ctype, CharTypeBits.Digit) || c == 45 || c == 46))
			{
				return NextTokenState.MaybeNumber;
			}
			if (settings.IsCharType(ctype, CharTypeBits.Word))
			{
				return NextTokenState.Word;
			}
			if (settings.GrabEol && c == 10)
			{
				return NextTokenState.Eol;
			}
			if (settings.IsCharType(ctype, CharTypeBits.Whitespace))
			{
				return NextTokenState.Whitespace;
			}
			if (settings.IsCharType(ctype, CharTypeBits.Comment))
			{
				return NextTokenState.LineComment;
			}
			if (settings.IsCharType(ctype, CharTypeBits.Quote))
			{
				return NextTokenState.Quote;
			}
			if (c == Eof || settings.IsCharType(ctype, CharTypeBits.Eof))
			{
				return NextTokenState.Eof;
			}
			return NextTokenState.Char;
		}

		private int GetNextChar()
		{
			int result;
			if (backString.Length > 0)
			{
				result = backString[0];
				backString.Remove(0, 1);
				return result;
			}
			if (textReader == null)
			{
				return Eof;
			}
			try
			{
				while ((result = textReader.Read()) == 13)
				{
				}
			}
			catch (Exception)
			{
				return Eof;
			}
			if (result == 10)
			{
				lineNumber++;
			}
			else if (result < 0)
			{
				result = Eof;
			}
			return result;
		}

		public bool NextToken(out Token token)
		{
			token = null;
			int num = 0;
			NextTokenState nextTokenState = NextTokenState.Start;
			int num2 = 0;
			byte b = 64;
			if (nextTokenSb.Length > 0)
			{
				num2 = nextTokenSb[nextTokenSb.Length - 1];
				b = settings.CharTypes[num2];
				nextTokenState = PickNextState(b, num2);
			}
			int num3 = 0;
			int num4 = 0;
			bool flag = false;
			int num5 = lineNumber;
			num = num2;
			bool flag2 = false;
			while (!flag2)
			{
				num2 = num;
				num = GetNextChar();
				byte ctype = (byte)((num >= settings.CharTypes.Length) ? 1 : settings.CharTypes[num]);
				switch (nextTokenState)
				{
				case NextTokenState.Start:
					nextTokenState = PickNextState(ctype, num);
					num5 = lineNumber;
					break;
				case NextTokenState.Char:
					token = new CharToken((char)num2, num5);
					flag2 = true;
					nextTokenSb.Length = 0;
					break;
				case NextTokenState.Word:
					if (!settings.IsCharType(ctype, CharTypeBits.Word) && !settings.IsCharType(ctype, CharTypeBits.Digit))
					{
						token = new WordToken(nextTokenSb.ToString(), num5);
						flag2 = true;
						nextTokenSb.Length = 0;
					}
					break;
				case NextTokenState.Whitespace:
					if (!settings.IsCharType(ctype, CharTypeBits.Whitespace) || (settings.GrabEol && num == 10))
					{
						if (settings.GrabWhitespace)
						{
							token = new WhitespaceToken(nextTokenSb.ToString(), num5);
							flag2 = true;
							nextTokenSb.Length = 0;
						}
						else
						{
							nextTokenSb.Length = 0;
							num5 = lineNumber;
							nextTokenState = PickNextState(ctype, num);
						}
					}
					break;
				case NextTokenState.EndQuote:
					token = new QuoteToken(nextTokenSb.ToString(), num5);
					flag2 = true;
					nextTokenSb.Length = 0;
					break;
				case NextTokenState.Quote:
					if (num == nextTokenSb[0])
					{
						int num6 = 0;
						int num7 = nextTokenSb.Length - 1;
						while (num7 >= 0 && nextTokenSb[num7] == '\\')
						{
							num6++;
							num7--;
						}
						if (num6 % 2 == 0)
						{
							nextTokenState = NextTokenState.EndQuote;
						}
					}
					if (nextTokenState != NextTokenState.EndQuote && num == Eof)
					{
						if (settings.DoUntermCheck)
						{
							nextTokenSb.Length = 0;
							throw new StreamTokenizerUntermQuoteException("Unterminated quote");
						}
						token = new QuoteToken(nextTokenSb.ToString(), num5);
						flag2 = true;
						nextTokenSb.Length = 0;
					}
					break;
				case NextTokenState.MaybeComment:
					if (num == Eof)
					{
						token = new CharToken(nextTokenSb.ToString(), num5);
						flag2 = true;
						nextTokenSb.Length = 0;
					}
					else if (settings.SlashSlashComments && num == 47)
					{
						nextTokenState = NextTokenState.LineComment;
					}
					else if (settings.SlashStarComments && num == 42)
					{
						nextTokenState = NextTokenState.BlockComment;
					}
					else
					{
						token = new CharToken(nextTokenSb.ToString(), num5);
						flag2 = true;
						nextTokenSb.Length = 0;
					}
					break;
				case NextTokenState.LineComment:
					if (num == Eof)
					{
						if (settings.GrabComments)
						{
							token = new CommentToken(nextTokenSb.ToString(), num5);
							flag2 = true;
							nextTokenSb.Length = 0;
						}
						else
						{
							nextTokenSb.Length = 0;
							num5 = lineNumber;
							nextTokenState = PickNextState(ctype, num);
						}
					}
					else if (num == 10)
					{
						if (settings.GrabComments)
						{
							token = new CommentToken(nextTokenSb.ToString(), num5);
							flag2 = true;
							nextTokenSb.Length = 0;
						}
						else
						{
							nextTokenSb.Length = 0;
							num5 = lineNumber;
							nextTokenState = PickNextState(ctype, num);
						}
					}
					break;
				case NextTokenState.BlockComment:
					if (num == Eof)
					{
						if (settings.DoUntermCheck)
						{
							nextTokenSb.Length = 0;
							throw new StreamTokenizerUntermCommentException("Unterminated comment.");
						}
						if (settings.GrabComments)
						{
							token = new CommentToken(nextTokenSb.ToString(), num5);
							flag2 = true;
							nextTokenSb.Length = 0;
						}
						else
						{
							nextTokenSb.Length = 0;
							num5 = lineNumber;
							nextTokenState = PickNextState(ctype, num);
						}
					}
					else if (num == 47 && num2 == 42)
					{
						nextTokenState = NextTokenState.EndBlockComment;
					}
					break;
				case NextTokenState.EndBlockComment:
					if (settings.GrabComments)
					{
						token = new CommentToken(nextTokenSb.ToString(), num5);
						flag2 = true;
						nextTokenSb.Length = 0;
					}
					else
					{
						nextTokenSb.Length = 0;
						num5 = lineNumber;
						nextTokenState = PickNextState(ctype, num);
					}
					break;
				case NextTokenState.MaybeHex:
					if (num != 120)
					{
						nextTokenSb.Append((char)num);
						backString.Append(nextTokenSb);
						nextTokenSb.Length = 0;
						num = backString[0];
						backString.Remove(0, 1);
						nextTokenState = PickNextState(settings.CharTypes[num], num, NextTokenState.MaybeHex);
					}
					else
					{
						nextTokenState = NextTokenState.HexGot0x;
					}
					break;
				case NextTokenState.HexGot0x:
					if (!settings.IsCharType(ctype, CharTypeBits.HexDigit))
					{
						nextTokenSb.Append((char)num);
						backString.Append(nextTokenSb);
						nextTokenSb.Length = 0;
						num = backString[0];
						backString.Remove(0, 1);
						nextTokenState = PickNextState(settings.CharTypes[num], num, NextTokenState.MaybeHex);
					}
					else
					{
						nextTokenState = NextTokenState.HexNumber;
					}
					break;
				case NextTokenState.HexNumber:
					if (!settings.IsCharType(ctype, CharTypeBits.HexDigit))
					{
						token = IntToken.ParseHex(nextTokenSb.ToString(), num5);
						flag2 = true;
						nextTokenSb.Length = 0;
					}
					break;
				case NextTokenState.MaybeNumber:
				{
					bool flag3 = false;
					if (settings.IsCharType(ctype, CharTypeBits.Digit) || settings.IsCharType(num2, CharTypeBits.Digit))
					{
						flag = true;
					}
					switch (num)
					{
					case 46:
						num3++;
						if (num3 > 1)
						{
							flag3 = true;
						}
						break;
					case 69:
					case 101:
					{
						num4++;
						if (!flag)
						{
							flag3 = true;
							break;
						}
						if (num4 > 1)
						{
							flag3 = true;
							break;
						}
						flag3 = true;
						expSb.Clear();
						expSb.Append((char)num);
						if (GrabInt(expSb, allowPlus: true, out var thisChar))
						{
							nextTokenSb.Append(expSb);
							num = thisChar;
						}
						break;
					}
					default:
						if (num == Eof)
						{
							flag3 = true;
						}
						else if ((!settings.IsCharType(ctype, CharTypeBits.Digit) && num != 101 && num != 69 && num != 45 && num != 46) || (num == 43 && num4 == 0))
						{
							flag3 = true;
						}
						else if (num == 45 && num2 != 101 && num2 != 69)
						{
							flag3 = true;
						}
						break;
					}
					if (!flag3)
					{
						break;
					}
					if (flag)
					{
						if (nextTokenSb.IndexOf('.') >= 0 || nextTokenSb.IndexOf('e') >= 0 || nextTokenSb.IndexOf('E') >= 0 || nextTokenSb.Length >= 19)
						{
							token = new FloatToken(nextTokenSb.ToString(), num5);
						}
						else
						{
							token = new IntToken(nextTokenSb.ToString(), num5);
						}
						flag2 = true;
						nextTokenSb.Length = 0;
					}
					else
					{
						nextTokenSb.Append((char)num);
						backString.Append(nextTokenSb);
						nextTokenSb.Length = 0;
						num = backString[0];
						backString.Remove(0, 1);
						nextTokenState = PickNextState(settings.CharTypes[num], num, NextTokenState.MaybeNumber);
					}
					break;
				}
				case NextTokenState.Eol:
					token = new EolToken(num5 - 1);
					flag2 = true;
					nextTokenSb.Length = 0;
					break;
				case NextTokenState.Eof:
					token = new EofToken(num5);
					flag2 = true;
					nextTokenSb.Length = 0;
					return false;
				default:
					return false;
				}
				if (num != Eof)
				{
					nextTokenSb.Append((char)num);
				}
			}
			return true;
		}

		private bool GrabInt(CharBuffer sb, bool allowPlus, out char thisChar)
		{
			tmpSb.Clear();
			thisChar = (char)GetNextChar();
			if (thisChar == Eof)
			{
				return false;
			}
			if (thisChar == '+')
			{
				if (!allowPlus)
				{
					backString.Append(thisChar);
					return false;
				}
				tmpSb.Append(thisChar);
			}
			else if (thisChar == '-')
			{
				tmpSb.Append(thisChar);
			}
			else
			{
				if (!settings.IsCharType(thisChar, CharTypeBits.Digit))
				{
					backString.Append(thisChar);
					return false;
				}
				backString.Append(thisChar);
			}
			bool flag = false;
			while ((thisChar = (char)GetNextChar()) != Eof && settings.IsCharType(thisChar, CharTypeBits.Digit))
			{
				flag = true;
				tmpSb.Append(thisChar);
			}
			if (flag)
			{
				sb.Append(tmpSb);
				return true;
			}
			backString.Append(tmpSb);
			if (thisChar != Eof)
			{
				backString.Append(thisChar);
			}
			return false;
		}

		public bool Tokenize(IList<Token> tokens)
		{
			lineNumber = 1;
			Token token;
			while (NextToken(out token))
			{
				if (token == null)
				{
					throw new NullReferenceException("StreamTokenizer: Tokenize: Got a null token from NextToken.");
				}
				tokens.Add(token);
			}
			tokens.Add(token);
			return true;
		}

		public bool TokenizeReader(TextReader tr, IList<Token> tokens)
		{
			textReader = tr;
			return Tokenize(tokens);
		}

		public bool TokenizeFile(string fileName, IList<Token> tokens)
		{
			FileInfo fileInfo = new FileInfo(fileName);
			FileStream fileStream = null;
			try
			{
				fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.None);
				textReader = new StreamReader(fileStream);
			}
			catch (DirectoryNotFoundException)
			{
			}
			try
			{
				if (!Tokenize(tokens))
				{
					textReader.Dispose();
					fileStream?.Dispose();
					return false;
				}
			}
			catch (StreamTokenizerUntermException ex2)
			{
				textReader.Dispose();
				fileStream?.Dispose();
				throw ex2;
			}
			if (textReader != null)
			{
				textReader.Dispose();
			}
			fileStream?.Dispose();
			return true;
		}

		public Token[] TokenizeFile(string fileName)
		{
			List<Token> list = new List<Token>();
			if (!TokenizeFile(fileName, list))
			{
				return null;
			}
			if (list.Count > 0)
			{
				return list.ToArray();
			}
			return null;
		}

		public bool TokenizeString(string str, IList<Token> tokens)
		{
			textReader = new StringReader(str);
			return Tokenize(tokens);
		}

		public bool TokenizeStream(Stream s, IList<Token> tokens)
		{
			textReader = new StreamReader(s);
			return Tokenize(tokens);
		}

		public IEnumerator<Token> GetEnumerator()
		{
			lineNumber = 1;
			Token token;
			while (NextToken(out token))
			{
				if (token == null)
				{
					throw new NullReferenceException("StreamTokenizer: Tokenize: Got a null token from NextToken.");
				}
				yield return token;
			}
			yield return token;
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
	public abstract class Token
	{
		private readonly int _lineNumber;

		protected object obj;

		private bool untermError;

		private string untermErrorMsg;

		public int LineNumber => _lineNumber;

		public object Object => obj;

		public bool UntermError
		{
			get
			{
				return untermError;
			}
			set
			{
				untermError = value;
			}
		}

		public string UntermErrorMsg
		{
			get
			{
				return untermErrorMsg;
			}
			set
			{
				untermError = true;
				untermErrorMsg = value;
			}
		}

		public virtual string StringValue => "unset";

		public Token(int line)
		{
			obj = null;
			untermError = false;
			_lineNumber = line;
		}

		public override bool Equals(object other)
		{
			if (other == null)
			{
				return false;
			}
			if (!(other is Token))
			{
				return false;
			}
			return obj.Equals(((Token)other).obj);
		}

		public bool Equals(string s)
		{
			if (s == null)
			{
				return false;
			}
			return StringValue.Equals(s);
		}

		public bool Equals(char c)
		{
			if (!(this is CharToken))
			{
				return false;
			}
			return (this as CharToken).Object.Equals(c);
		}

		public static bool operator ==(Token t, object o)
		{
			if ((object)t == null)
			{
				if (o == null)
				{
					return true;
				}
				return false;
			}
			if (o == null)
			{
				return false;
			}
			return t.Equals(o);
		}

		public static bool operator !=(Token t, object o)
		{
			if ((object)t == null)
			{
				if (o == null)
				{
					return false;
				}
				return true;
			}
			return !t.Equals(o);
		}

		public static bool operator ==(Token t, char c)
		{
			return t?.Equals(c) ?? false;
		}

		public static bool operator !=(Token t, char c)
		{
			if ((object)t == null)
			{
				return false;
			}
			return !t.Equals(c);
		}

		public static bool operator ==(Token t, string s)
		{
			if ((object)t == null)
			{
				if (s == null)
				{
					return true;
				}
				return false;
			}
			return t.Equals(s);
		}

		public static bool operator !=(Token t, string s)
		{
			if ((object)t == null)
			{
				if (s == null)
				{
					return false;
				}
				return true;
			}
			return !t.Equals(s);
		}

		public override int GetHashCode()
		{
			return ToString().GetHashCode();
		}

		public string ToLineString()
		{
			return $"{ToDebugString()}: line {_lineNumber}";
		}

		public virtual string ToDebugString()
		{
			return $"{ToString()}: line {_lineNumber}";
		}

		public object ConvertToType(Type t)
		{
			return Convert.ChangeType(StringValue, t, CultureInfo.InvariantCulture);
		}
	}
	public class EolToken : Token
	{
		public override string StringValue => ToString();

		public EolToken()
			: base(0)
		{
		}

		public EolToken(int line)
			: base(line)
		{
		}

		public override string ToDebugString()
		{
			return "Eol";
		}

		public override string ToString()
		{
			return "\n";
		}

		public override bool Equals(object other)
		{
			if (!(other is EolToken))
			{
				return false;
			}
			return true;
		}

		public override int GetHashCode()
		{
			return ToString().GetHashCode();
		}
	}
	public class EofToken : Token
	{
		public override string StringValue => ToString();

		public EofToken()
			: base(0)
		{
		}

		public EofToken(int line)
			: base(line)
		{
		}

		public override string ToString()
		{
			return string.Empty;
		}

		public override string ToDebugString()
		{
			return "Eof";
		}

		public override bool Equals(object other)
		{
			if (!(other is EofToken))
			{
				return false;
			}
			return true;
		}

		public override int GetHashCode()
		{
			return ToString().GetHashCode();
		}
	}
	public abstract class StringToken : Token
	{
		public override string StringValue => (string)obj;

		public StringToken(string s)
			: base(0)
		{
			obj = s;
		}

		public StringToken(string s, int line)
			: base(line)
		{
			obj = s;
		}

		public override string ToDebugString()
		{
			return GetType().Name + ":'" + (string)obj + "'";
		}

		public override string ToString()
		{
			return (string)obj;
		}

		public override int GetHashCode()
		{
			return ToString().GetHashCode();
		}
	}
	public class WordToken : StringToken
	{
		public WordToken(string s)
			: base(s)
		{
		}

		public WordToken(string s, int line)
			: base(s, line)
		{
		}
	}
	public class QuoteToken : StringToken
	{
		public QuoteToken(string s)
			: base(s)
		{
		}

		public QuoteToken(string s, int line)
			: base(s, line)
		{
		}
	}
	public class CommentToken : StringToken
	{
		public CommentToken(string s)
			: base(s)
		{
		}

		public CommentToken(string s, int line)
			: base(s, line)
		{
		}
	}
	public class WhitespaceToken : StringToken
	{
		public WhitespaceToken(string s)
			: base(s)
		{
		}

		public WhitespaceToken(string s, int line)
			: base(s, line)
		{
		}
	}
	public class CharToken : Token
	{
		public override string StringValue => $"{(char)obj}";

		public CharToken(string s, int line)
			: base(line)
		{
			if (s.Length > 0)
			{
				obj = s[0];
			}
		}

		public CharToken(char c)
			: base(0)
		{
			obj = c;
		}

		public CharToken(char c, int line)
			: base(line)
		{
			obj = c;
		}

		public override string ToDebugString()
		{
			return $"CharToken: {(char)obj}";
		}

		public override string ToString()
		{
			return $"{(char)obj}";
		}

		public override int GetHashCode()
		{
			return ToString().GetHashCode();
		}

		public override bool Equals(object other)
		{
			if (other == null)
			{
				return false;
			}
			if (!GetType().Equals(other.GetType()))
			{
				return false;
			}
			if (obj == null || ((CharToken)other).obj == null)
			{
				return false;
			}
			if (((char)obj).Equals((char)((CharToken)other).Object))
			{
				return true;
			}
			return false;
		}
	}
	public class FloatToken : Token
	{
		private NumberFormatInfo numberFormatInfo;

		public override string StringValue
		{
			get
			{
				if (obj != null)
				{
					return string.Format(GetNumberFormatInfo(), "{0:R}", (double)obj);
				}
				return $"null";
			}
		}

		private NumberFormatInfo GetNumberFormatInfo()
		{
			if (numberFormatInfo == null)
			{
				numberFormatInfo = new NumberFormatInfo();
				numberFormatInfo.NumberDecimalSeparator = ".";
			}
			return numberFormatInfo;
		}

		public FloatToken(string s)
			: base(0)
		{
			try
			{
				obj = double.Parse(s, GetNumberFormatInfo());
			}
			catch (Exception)
			{
				obj = null;
			}
		}

		public FloatToken(float f)
			: base(0)
		{
			try
			{
				obj = (double)f;
			}
			catch (Exception)
			{
				obj = null;
			}
		}

		public FloatToken(double d)
			: base(0)
		{
			try
			{
				obj = d;
			}
			catch (Exception)
			{
				obj = null;
			}
		}

		public FloatToken(string s, int line)
			: base(line)
		{
			try
			{
				obj = double.Parse(s, GetNumberFormatInfo());
			}
			catch (Exception)
			{
				obj = null;
			}
		}

		public FloatToken(double f, int line)
			: base(line)
		{
			try
			{
				obj = f;
			}
			catch (Exception)
			{
				obj = null;
			}
		}

		public override string ToDebugString()
		{
			if (obj != null)
			{
				return $"FloatToken: {(double)obj:R}";
			}
			return $"FloatToken: null";
		}

		public override string ToString()
		{
			if (obj != null)
			{
				return $"{(double)obj:R}";
			}
			return $"null";
		}

		public override int GetHashCode()
		{
			return ToString().GetHashCode();
		}

		public override bool Equals(object other)
		{
			if (other == null)
			{
				return false;
			}
			if (!GetType().Equals(other.GetType()))
			{
				return false;
			}
			if (obj == null || ((FloatToken)other).obj == null)
			{
				return false;
			}
			if (((double)obj).Equals((double)((FloatToken)other).Object))
			{
				return true;
			}
			return false;
		}
	}
	public class IntToken : Token
	{
		public override string StringValue
		{
			get
			{
				if (obj != null)
				{
					return $"{obj}";
				}
				return $"null";
			}
		}

		public IntToken(int i)
			: base(0)
		{
			obj = i;
		}

		public IntToken(long i)
			: base(0)
		{
			obj = i;
		}

		public IntToken(string s)
			: base(0)
		{
			Parse(s);
		}

		public IntToken(string s, int line)
			: base(line)
		{
			Parse(s);
		}

		public IntToken(int i, int line)
			: base(line)
		{
			obj = i;
		}

		public IntToken(long l, int line)
			: base(line)
		{
			obj = l;
		}

		public static IntToken ParseHex(string s, int lineNumber)
		{
			IntToken intToken = null;
			try
			{
				return new IntToken(Convert.ToInt32(s, 16), lineNumber);
			}
			catch
			{
				return new IntToken(Convert.ToInt64(s, 16), lineNumber);
			}
		}

		private void Parse(string s)
		{
			if (int.TryParse(s, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out var result))
			{
				base.obj = result;
				return;
			}
			if (long.TryParse(s, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out var result2))
			{
				base.obj = result2;
				return;
			}
			int[] array = new int[3] { 16, 2, 8 };
			foreach (int fromBase in array)
			{
				try
				{
					base.obj = Convert.ToInt32(s, fromBase);
					return;
				}
				catch
				{
					try
					{
						base.obj = Convert.ToInt64(s, fromBase);
						return;
					}
					catch
					{
					}
				}
			}
			base.obj = null;
		}

		public override string ToDebugString()
		{
			if (obj != null)
			{
				return $"IntToken: {obj}";
			}
			return $"IntToken: null";
		}

		public override string ToString()
		{
			if (obj != null)
			{
				return $"{obj}";
			}
			return $"null";
		}

		public override int GetHashCode()
		{
			return ToString().GetHashCode();
		}

		public override bool Equals(object other)
		{
			if (other == null)
			{
				return false;
			}
			if (!GetType().Equals(other.GetType()))
			{
				return false;
			}
			if (obj == null || ((IntToken)other).obj == null)
			{
				return false;
			}
			if (!obj.GetType().Equals(((IntToken)other).obj.GetType()))
			{
				return false;
			}
			if (obj is int)
			{
				if (((int)obj).Equals((int)((IntToken)other).Object))
				{
					return true;
				}
			}
			else if (((long)obj).Equals((long)((IntToken)other).Object))
			{
				return true;
			}
			return false;
		}
	}
	public enum VerbosityLevel
	{
		Error,
		Warn,
		Info,
		Debug
	}
}
namespace NetTopologySuite
{
	public class NtsGeometryServices
	{
		private readonly struct GeometryFactoryKey : IEquatable<GeometryFactoryKey>
		{
			public PrecisionModel PrecisionModel { get; }

			public CoordinateSequenceFactory CoordinateSequenceFactory { get; }

			public int SRID { get; }

			public GeometryFactoryKey(PrecisionModel precisionModel, int srid, CoordinateSequenceFactory factory)
			{
				PrecisionModel = precisionModel;
				CoordinateSequenceFactory = factory;
				SRID = srid;
			}

			public override int GetHashCode()
			{
				return (PrecisionModel, CoordinateSequenceFactory, SRID).GetHashCode();
			}

			public override bool Equals(object obj)
			{
				if (obj is GeometryFactoryKey other)
				{
					return Equals(other);
				}
				return false;
			}

			public bool Equals(GeometryFactoryKey other)
			{
				if (SRID == other.SRID && object.Equals(CoordinateSequenceFactory, other.CoordinateSequenceFactory))
				{
					return object.Equals(PrecisionModel, other.PrecisionModel);
				}
				return false;
			}
		}

		private static volatile NtsGeometryServices s_instance = new NtsGeometryServices();

		[NonSerialized]
		private readonly ConcurrentDictionary<GeometryFactoryKey, GeometryFactory> m_factories = new ConcurrentDictionary<GeometryFactoryKey, GeometryFactory>();

		public static NtsGeometryServices Instance
		{
			get
			{
				return s_instance;
			}
			set
			{
				s_instance = value ?? throw new ArgumentNullException("value");
			}
		}

		public GeometryOverlay GeometryOverlay { get; }

		public CoordinateEqualityComparer CoordinateEqualityComparer { get; }

		public int DefaultSRID { get; }

		public CoordinateSequenceFactory DefaultCoordinateSequenceFactory { get; }

		public PrecisionModel DefaultPrecisionModel { get; }

		internal int NumFactories => m_factories.Count;

		public NtsGeometryServices()
			: this(GeometryOverlay.Legacy)
		{
		}

		public NtsGeometryServices(GeometryOverlay geometryOverlay)
			: this(CoordinateArraySequenceFactory.Instance, PrecisionModel.Floating.Value, -1, geometryOverlay, new CoordinateEqualityComparer())
		{
		}

		public NtsGeometryServices(PrecisionModel precisionModel)
			: this(CoordinateArraySequenceFactory.Instance, precisionModel, -1, GeometryOverlay.Legacy, new CoordinateEqualityComparer())
		{
		}

		public NtsGeometryServices(PrecisionModel precisionModel, int srid)
			: this(CoordinateArraySequenceFactory.Instance, precisionModel, srid, GeometryOverlay.Legacy, new CoordinateEqualityComparer())
		{
		}

		public NtsGeometryServices(CoordinateSequenceFactory coordinateSequenceFactory)
			: this(coordinateSequenceFactory, PrecisionModel.Floating.Value, -1, GeometryOverlay.Legacy, new CoordinateEqualityComparer())
		{
		}

		public NtsGeometryServices(CoordinateSequenceFactory coordinateSequenceFactory, PrecisionModel precisionModel, int srid)
			: this(coordinateSequenceFactory, precisionModel, srid, GeometryOverlay.Legacy, new CoordinateEqualityComparer())
		{
		}

		public NtsGeometryServices(CoordinateSequenceFactory coordinateSequenceFactory, PrecisionModel precisionModel, int srid, GeometryOverlay geometryOverlay, CoordinateEqualityComparer coordinateEqualityComparer)
		{
			DefaultCoordinateSequenceFactory = coordinateSequenceFactory ?? throw new ArgumentNullException("coordinateSequenceFactory");
			DefaultPrecisionModel = precisionModel ?? throw new ArgumentNullException("precisionModel");
			DefaultSRID = srid;
			GeometryOverlay = geometryOverlay ?? throw new ArgumentNullException("geometryOverlay");
			CoordinateEqualityComparer = coordinateEqualityComparer ?? throw new ArgumentNullException("coordinateEqualityComparer");
		}

		[Obsolete("Will be removed in a future version")]
		public PrecisionModel CreatePrecisionModel(PrecisionModels modelType)
		{
			return new PrecisionModel(modelType);
		}

		[Obsolete("Will be removed in a future version")]
		public PrecisionModel CreatePrecisionModel(PrecisionModel precisionModel)
		{
			return new PrecisionModel(precisionModel);
		}

		[Obsolete("Will be removed in a future version")]
		public PrecisionModel CreatePrecisionModel(double scale)
		{
			return new PrecisionModel(scale);
		}

		public GeometryFactory CreateGeometryFactory()
		{
			return CreateGeometryFactory(DefaultSRID);
		}

		public GeometryFactory CreateGeometryFactory(int srid)
		{
			return CreateGeometryFactory(DefaultPrecisionModel, srid, DefaultCoordinateSequenceFactory);
		}

		public GeometryFactory CreateGeometryFactory(CoordinateSequenceFactory coordinateSequenceFactory)
		{
			return CreateGeometryFactory(DefaultPrecisionModel, DefaultSRID, coordinateSequenceFactory);
		}

		public GeometryFactory CreateGeometryFactory(PrecisionModel precisionModel)
		{
			return CreateGeometryFactory(precisionModel, DefaultSRID, DefaultCoordinateSequenceFactory);
		}

		public GeometryFactory CreateGeometryFactory(PrecisionModel precisionModel, int srid)
		{
			return CreateGeometryFactory(precisionModel, srid, DefaultCoordinateSequenceFactory);
		}

		public GeometryFactory CreateGeometryFactory(PrecisionModel precisionModel, int srid, CoordinateSequenceFactory coordinateSequenceFactory)
		{
			if ((object)precisionModel == null)
			{
				throw new ArgumentNullException("precisionModel");
			}
			if (coordinateSequenceFactory == null)
			{
				throw new ArgumentNullException("coordinateSequenceFactory");
			}
			return m_factories.GetOrAdd(new GeometryFactoryKey(precisionModel, srid, coordinateSequenceFactory), (GeometryFactoryKey key) => CreateGeometryFactoryCore(key.PrecisionModel, key.SRID, key.CoordinateSequenceFactory));
		}

		protected virtual GeometryFactory CreateGeometryFactoryCore(PrecisionModel precisionModel, int srid, CoordinateSequenceFactory coordinateSequenceFactory)
		{
			return new GeometryFactory(precisionModel, srid, coordinateSequenceFactory, this);
		}
	}
}
namespace NetTopologySuite.Utilities
{
	public sealed class AlternativePriorityQueue<TPriority, TData> : IEnumerable<PriorityQueueNode<TPriority, TData>>, IEnumerable
	{
		private const int DefaultCapacity = 4;

		private readonly List<PriorityQueueNode<TPriority, TData>> nodes;

		private readonly IComparer<TPriority> priorityComparer;

		public int Count { get; private set; }

		public PriorityQueueNode<TPriority, TData> Head => nodes[1];

		public AlternativePriorityQueue()
			: this(4)
		{
		}

		public AlternativePriorityQueue(int capacity)
			: this(capacity, (IComparer<TPriority>)null)
		{
		}

		public AlternativePriorityQueue(IComparer<TPriority> priorityComparer)
			: this(4, priorityComparer)
		{
		}

		public AlternativePriorityQueue(int capacity, IComparer<TPriority> priorityComparer)
		{
			if (capacity < 1)
			{
				throw new ArgumentOutOfRangeException("capacity", "Capacity must be greater than zero.");
			}
			nodes = new List<PriorityQueueNode<TPriority, TData>>(capacity + 1);
			for (int i = 0; i <= capacity; i++)
			{
				nodes.Add(null);
			}
			Count = 0;
			this.priorityComparer = priorityComparer ?? Comparer<TPriority>.Default;
		}

		public AlternativePriorityQueue(AlternativePriorityQueue<TPriority, TData> copyFrom)
		{
			if (copyFrom == null)
			{
				throw new ArgumentNullException("copyFrom");
			}
			nodes = new List<PriorityQueueNode<TPriority, TData>>(copyFrom.nodes.Count);
			priorityComparer = copyFrom.priorityComparer;
			for (int i = 0; i < copyFrom.nodes.Count; i++)
			{
				PriorityQueueNode<TPriority, TData> priorityQueueNode = copyFrom.nodes[i];
				PriorityQueueNode<TPriority, TData> item = ((priorityQueueNode == null) ? null : new PriorityQueueNode<TPriority, TData>(priorityQueueNode));
				nodes.Add(item);
			}
		}

		public void Clear()
		{
			nodes.Clear();
			nodes.Add(null);
			nodes.Add(null);
			Count = 0;
		}

		public bool Contains(PriorityQueueNode<TPriority, TData> node)
		{
			if (node != null && node.QueueIndex < nodes.Count)
			{
				return nodes[node.QueueIndex] == node;
			}
			return false;
		}

		public void Enqueue(PriorityQueueNode<TPriority, TData> node, TPriority priority)
		{
			if (node == null)
			{
				throw new ArgumentNullException("node");
			}
			node.Priority = priority;
			node.QueueIndex = ++Count;
			if (nodes.Count <= Count)
			{
				nodes.Add(null);
			}
			nodes[Count] = node;
			HeapifyUp(nodes[Count]);
		}

		public PriorityQueueNode<TPriority, TData> Dequeue()
		{
			PriorityQueueNode<TPriority, TData> head = Head;
			Remove(head);
			return head;
		}

		public void ChangePriority(PriorityQueueNode<TPriority, TData> node, TPriority priority)
		{
			if (node == null)
			{
				throw new ArgumentNullException("node");
			}
			node.Priority = priority;
			OnNodeUpdated(node);
		}

		public bool Remove(PriorityQueueNode<TPriority, TData> node)
		{
			if (!Contains(node))
			{
				return false;
			}
			if (Count <= 1)
			{
				nodes[1] = null;
				Count = 0;
				return true;
			}
			bool flag = false;
			PriorityQueueNode<TPriority, TData> priorityQueueNode = nodes[Count];
			if (node.QueueIndex != Count)
			{
				Swap(node, priorityQueueNode);
				flag = true;
			}
			int count = Count - 1;
			Count = count;
			nodes[node.QueueIndex] = null;
			if (flag)
			{
				OnNodeUpdated(priorityQueueNode);
			}
			return true;
		}

		public IEnumerator<PriorityQueueNode<TPriority, TData>> GetEnumerator()
		{
			return nodes.Skip(1).Take(Count).GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		private void HeapifyUp(PriorityQueueNode<TPriority, TData> node)
		{
			int num = node.QueueIndex / 2;
			while (num >= 1)
			{
				PriorityQueueNode<TPriority, TData> priorityQueueNode = nodes[num];
				if (!HasHigherPriority(priorityQueueNode, node))
				{
					Swap(node, priorityQueueNode);
					num = node.QueueIndex / 2;
					continue;
				}
				break;
			}
		}

		private void HeapifyDown(PriorityQueueNode<TPriority, TData> node)
		{
			int num = node.QueueIndex;
			while (true)
			{
				PriorityQueueNode<TPriority, TData> priorityQueueNode = node;
				int num2 = 2 * num;
				if (num2 > Count)
				{
					node.QueueIndex = num;
					nodes[num] = node;
					return;
				}
				PriorityQueueNode<TPriority, TData> priorityQueueNode2 = nodes[num2];
				if (HasHigherPriority(priorityQueueNode2, priorityQueueNode))
				{
					priorityQueueNode = priorityQueueNode2;
				}
				int num3 = num2 + 1;
				if (num3 <= Count)
				{
					PriorityQueueNode<TPriority, TData> priorityQueueNode3 = nodes[num3];
					if (HasHigherPriority(priorityQueueNode3, priorityQueueNode))
					{
						priorityQueueNode = priorityQueueNode3;
					}
				}
				if (priorityQueueNode == node)
				{
					break;
				}
				nodes[num] = priorityQueueNode;
				int queueIndex = priorityQueueNode.QueueIndex;
				priorityQueueNode.QueueIndex = num;
				num = queueIndex;
			}
			node.QueueIndex = num;
			nodes[num] = node;
		}

		private void OnNodeUpdated(PriorityQueueNode<TPriority, TData> node)
		{
			int num = node.QueueIndex / 2;
			PriorityQueueNode<TPriority, TData> lower = nodes[num];
			if (num > 0 && HasHigherPriority(node, lower))
			{
				HeapifyUp(node);
			}
			else
			{
				HeapifyDown(node);
			}
		}

		private void Swap(PriorityQueueNode<TPriority, TData> node1, PriorityQueueNode<TPriority, TData> node2)
		{
			nodes[node1.QueueIndex] = node2;
			nodes[node2.QueueIndex] = node1;
			int queueIndex = node1.QueueIndex;
			node1.QueueIndex = node2.QueueIndex;
			node2.QueueIndex = queueIndex;
		}

		private bool HasHigherPriority(PriorityQueueNode<TPriority, TData> higher, PriorityQueueNode<TPriority, TData> lower)
		{
			return priorityComparer.Compare(higher.Priority, lower.Priority) < 0;
		}
	}
	public static class Assert
	{
		public static void IsTrue(bool assertion)
		{
			IsTrue(assertion, null);
		}

		public static void IsTrue(bool assertion, string message)
		{
			if (assertion)
			{
				return;
			}
			if (message == null)
			{
				throw new AssertionFailedException();
			}
			throw new AssertionFailedException(message);
		}

		public static void IsEquals(object expectedValue, object actualValue)
		{
			IsEquals(expectedValue, actualValue, null);
		}

		public static void IsEquals(object expectedValue, object actualValue, string message)
		{
			if (actualValue.Equals(expectedValue))
			{
				return;
			}
			string arg = ((message != null) ? (": " + message) : string.Empty);
			throw new AssertionFailedException(string.Format(CultureInfo.InvariantCulture, "Expected {0} but encountered {1}{2}", expectedValue, actualValue, arg));
		}

		public static void ShouldNeverReachHere()
		{
			ShouldNeverReachHere(null);
		}

		public static void ShouldNeverReachHere(string message)
		{
			string arg = ((message != null) ? (": " + message) : string.Empty);
			throw new AssertionFailedException($"Should never reach here{arg}");
		}
	}
	public class AssertionFailedException : ApplicationException
	{
		public AssertionFailedException()
		{
		}

		public AssertionFailedException(string message)
			: base(message)
		{
		}
	}
	internal static class BitTweaks
	{
		internal static short ReverseByteOrder(short value)
		{
			return (short)ReverseByteOrder((ushort)value);
		}

		internal static int ReverseByteOrder(int value)
		{
			return (int)ReverseByteOrder((uint)value);
		}

		internal static long ReverseByteOrder(long value)
		{
			return (long)ReverseByteOrder((ulong)value);
		}

		internal static float ReverseByteOrder(float value)
		{
			byte[] bytes = BitConverter.GetBytes(value);
			Array.Reverse((Array)bytes, 0, 4);
			return BitConverter.ToSingle(bytes, 0);
		}

		internal static double ReverseByteOrder(double value)
		{
			return BitConverter.Int64BitsToDouble(ReverseByteOrder(BitConverter.DoubleToInt64Bits(value)));
		}

		internal static ushort ReverseByteOrder(ushort value)
		{
			return (ushort)(((value & 0xFF) << 8) | ((value & 0xFF00) >> 8));
		}

		internal static uint ReverseByteOrder(uint value)
		{
			return ((value & 0xFF) << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | ((value & 0xFF000000u) >> 24);
		}

		internal static ulong ReverseByteOrder(ulong value)
		{
			return ((value & 0xFF) << 56) | ((value & 0xFF00) << 40) | ((value & 0xFF0000) << 24) | ((value & 0xFF000000u) << 8) | ((value & 0xFF00000000L) >> 8) | ((value & 0xFF0000000000L) >> 24) | ((value & 0xFF000000000000L) >> 40) | ((value & 0xFF00000000000000uL) >> 56);
		}
	}
	public class CoordinateArrayFilter : ICoordinateFilter
	{
		private readonly Coordinate[] _pts;

		private int _n;

		public Coordinate[] Coordinates => _pts;

		public CoordinateArrayFilter(int size)
		{
			_pts = new Coordinate[size];
		}

		public void Filter(Coordinate coord)
		{
			_pts[_n++] = coord;
		}
	}
	public class CoordinateCompare : IComparer
	{
		public int Compare(object x, object y)
		{
			if (x is Coordinate && y is Coordinate)
			{
				Coordinate coordinate = (Coordinate)x;
				Coordinate coordinate2 = (Coordinate)y;
				if (coordinate.X < coordinate2.X)
				{
					return -1;
				}
				if (coordinate.X > coordinate2.X)
				{
					return 1;
				}
				if (coordinate.Y < coordinate2.Y)
				{
					return -1;
				}
				if (coordinate.Y > coordinate2.Y)
				{
					return 1;
				}
				return 0;
			}
			throw new ArgumentException("Wrong arguments type: Coordinate expected");
		}
	}
	public class CoordinateCountFilter : ICoordinateFilter
	{
		private int _n;

		public int Count => _n;

		public void Filter(Coordinate coord)
		{
			_n++;
		}
	}
	public class Degrees
	{
		public static double ToRadians(double degrees)
		{
			return degrees * (Math.PI / 180.0);
		}
	}
	[Obsolete]
	public static class EnumUtility
	{
		public static object Parse(Type type, string value)
		{
			return Enum.Parse(type, value, ignoreCase: false);
		}

		public static string Format(Type type, object value, string formatString)
		{
			return Enum.Format(type, value, formatString);
		}
	}
	public class FunctionsUtil
	{
		public static readonly Envelope DefaultEnvelope = new Envelope(0.0, 100.0, 0.0, 100.0);

		private static readonly GeometryFactory Factory = new GeometryFactory();

		public static Envelope GetEnvelopeOrDefault(Geometry g)
		{
			if (!(g == null))
			{
				return g.EnvelopeInternal;
			}
			return DefaultEnvelope;
		}

		public static GeometryFactory GetFactoryOrDefault(Geometry g)
		{
			if (!(g == null))
			{
				return g.Factory;
			}
			return Factory;
		}

		public static GeometryFactory GetFactoryOrDefault(IEnumerable<Geometry> gs)
		{
			if (gs == null)
			{
				return Factory;
			}
			foreach (Geometry g in gs)
			{
				if (g != null)
				{
					return g.Factory ?? Factory;
				}
			}
			return Factory;
		}

		[Obsolete]
		public static Geometry BuildGeometry(List<Geometry> geoms, Geometry parentGeom)
		{
			return BuildGeometry((IList<Geometry>)geoms, parentGeom);
		}

		public static Geometry BuildGeometry(IList<Geometry> geoms, Geometry parentGeom)
		{
			if (geoms.Count <= 0)
			{
				return null;
			}
			if (geoms.Count == 1)
			{
				return geoms[0];
			}
			if (parentGeom != null && parentGeom.OgcGeometryType == OgcGeometryType.GeometryCollection)
			{
				return parentGeom.Factory.CreateGeometryCollection(GeometryFactory.ToGeometryArray(geoms));
			}
			return GetFactoryOrDefault(geoms).BuildGeometry(geoms);
		}

		public static Geometry BuildGeometry(params Geometry[] geoms)
		{
			return GetFactoryOrDefault(geoms).CreateGeometryCollection(geoms);
		}

		public static Geometry BuildGeometry(Geometry a, Geometry b)
		{
			int num = 0;
			if (a != null)
			{
				num++;
			}
			if (b != null)
			{
				num++;
			}
			Geometry[] array = new Geometry[num];
			num = 0;
			if (a != null)
			{
				array[num++] = a;
			}
			if (b != null)
			{
				array[num] = b;
			}
			return GetFactoryOrDefault(array).CreateGeometryCollection(array);
		}
	}
	public class GeometricShapeFactory
	{
		protected class Dimensions
		{
			private Coordinate _base;

			private Coordinate _centre;

			private double _width;

			private double _height;

			public Coordinate Base
			{
				get
				{
					return _base;
				}
				set
				{
					_base = value;
				}
			}

			public Coordinate Centre
			{
				get
				{
					if (_centre == null)
					{
						_centre = ((Base != null) ? new Coordinate(Base.X + Width * 0.5, Base.Y + Height * 0.5) : new Coordinate(0.0, 0.0));
					}
					return _centre;
				}
				set
				{
					_centre = value;
				}
			}

			public double Width
			{
				get
				{
					return _width;
				}
				set
				{
					_width = value;
				}
			}

			public double Height
			{
				get
				{
					return _height;
				}
				set
				{
					_height = value;
				}
			}

			public double Size
			{
				set
				{
					Height = value;
					Width = value;
				}
			}

			public double MinSize => Math.Min(Width, Height);

			public Envelope Envelope
			{
				get
				{
					if (Base != null)
					{
						return new Envelope(Base.X, Base.X + Width, Base.Y, Base.Y + Height);
					}
					if (Centre != null)
					{
						return new Envelope(Centre.X - Width / 2.0, Centre.X + Width / 2.0, Centre.Y - Height / 2.0, Centre.Y + Height / 2.0);
					}
					return new Envelope(0.0, Width, 0.0, Height);
				}
				set
				{
					_width = value.Width;
					_height = value.Height;
					_base = new Coordinate(value.MinX, value.MinY);
					_centre = value.Centre.Copy();
				}
			}
		}

		protected GeometryFactory GeomFact;

		protected PrecisionModel PrecModel;

		private readonly Dimensions _dim = new Dimensions();

		private int _nPts = 100;

		private double _rotationAngle;

		public Coordinate Base
		{
			set
			{
				_dim.Base = value;
			}
		}

		public Coordinate Centre
		{
			set
			{
				_dim.Centre = value;
			}
		}

		public Envelope Envelope
		{
			get
			{
				return _dim.Envelope;
			}
			set
			{
				_dim.Envelope = value;
			}
		}

		public int NumPoints
		{
			get
			{
				return _nPts;
			}
			set
			{
				_nPts = value;
			}
		}

		public double Size
		{
			set
			{
				_dim.Size = value;
			}
		}

		public double Width
		{
			get
			{
				return _dim.Width;
			}
			set
			{
				_dim.Width = value;
			}
		}

		public double Height
		{
			get
			{
				return _dim.Height;
			}
			set
			{
				_dim.Height = value;
			}
		}

		public double Rotation
		{
			get
			{
				return _rotationAngle;
			}
			set
			{
				_rotationAngle = value;
			}
		}

		public GeometricShapeFactory()
			: this(new GeometryFactory())
		{
		}

		public GeometricShapeFactory(GeometryFactory geomFact)
		{
			GeomFact = geomFact;
			PrecModel = geomFact.PrecisionModel;
		}

		protected Geometry Rotate(Geometry geom)
		{
			if (_rotationAngle != 0.0)
			{
				Coordinate centre = _dim.Centre;
				AffineTransformation filter = AffineTransformation.RotationInstance(_rotationAngle, centre.X, centre.Y);
				geom.Apply(filter);
			}
			return geom;
		}

		protected Coordinate CreateCoord(double x, double y)
		{
			Coordinate coordinate = new Coordinate(x, y);
			PrecModel.MakePrecise(coordinate);
			return coordinate;
		}

		protected Coordinate CreateCoordTrans(double x, double y, Coordinate trans)
		{
			return CreateCoord(x + trans.X, y + trans.Y);
		}

		public Polygon CreateRectangle()
		{
			int num = 0;
			int num2 = _nPts / 4;
			if (num2 < 1)
			{
				num2 = 1;
			}
			double num3 = _dim.Envelope.Width / (double)num2;
			double num4 = _dim.Envelope.Height / (double)num2;
			Coordinate[] array = new Coordinate[4 * num2 + 1];
			Envelope envelope = _dim.Envelope;
			for (int i = 0; i < num2; i++)
			{
				double x = envelope.MinX + (double)i * num3;
				double minY = envelope.MinY;
				array[num++] = CreateCoord(x, minY);
			}
			for (int i = 0; i < num2; i++)
			{
				double maxX = envelope.MaxX;
				double y = envelope.MinY + (double)i * num4;
				array[num++] = CreateCoord(maxX, y);
			}
			for (int i = 0; i < num2; i++)
			{
				double x2 = envelope.MaxX - (double)i * num3;
				double maxY = envelope.MaxY;
				array[num++] = CreateCoord(x2, maxY);
			}
			for (int i = 0; i < num2; i++)
			{
				double minX = envelope.MinX;
				double y2 = envelope.MaxY - (double)i * num4;
				array[num++] = CreateCoord(minX, y2);
			}
			array[num] = array[0].Copy();
			LinearRing shell = GeomFact.CreateLinearRing(array);
			Polygon geom = GeomFact.CreatePolygon(shell);
			return (Polygon)Rotate(geom);
		}

		public Polygon CreateCircle()
		{
			Envelope envelope = _dim.Envelope;
			double num = envelope.Width / 2.0;
			double num2 = envelope.Height / 2.0;
			double num3 = envelope.MinX + num;
			double num4 = envelope.MinY + num2;
			Coordinate[] array = new Coordinate[_nPts + 1];
			int num5 = 0;
			for (int i = 0; i < _nPts; i++)
			{
				double num6 = (double)i * (Math.PI * 2.0 / (double)_nPts);
				double x = num * Math.Cos(num6) + num3;
				double y = num2 * Math.Sin(num6) + num4;
				Coordinate coordinate = CreateCoord(x, y);
				array[num5++] = coordinate;
			}
			array[num5] = array[0];
			LinearRing shell = GeomFact.CreateLinearRing(array);
			Polygon geom = GeomFact.CreatePolygon(shell);
			return (Polygon)Rotate(geom);
		}

		public Polygon CreateEllipse()
		{
			Envelope envelope = _dim.Envelope;
			double num = envelope.Width / 2.0;
			double num2 = envelope.Height / 2.0;
			double num3 = envelope.MinX + num;
			double num4 = envelope.MinY + num2;
			Coordinate[] array = new Coordinate[_nPts + 1];
			int num5 = 0;
			for (int i = 0; i < _nPts; i++)
			{
				double num6 = (double)i * (Math.PI * 2.0 / (double)_nPts);
				double x = num * Math.Cos(num6) + num3;
				double y = num2 * Math.Sin(num6) + num4;
				array[num5++] = CreateCoord(x, y);
			}
			array[num5] = array[0].Copy();
			LinearRing shell = GeomFact.CreateLinearRing(array);
			Polygon geom = GeomFact.CreatePolygon(shell);
			return (Polygon)Rotate(geom);
		}

		public Polygon CreateSquircle()
		{
			return CreateSupercircle(4.0);
		}

		public Polygon CreateSupercircle(double power)
		{
			double y = 1.0 / power;
			double num = _dim.MinSize / 2.0;
			Coordinate centre = _dim.Centre;
			double num2 = Math.Pow(num, power);
			double num3 = num;
			double num4 = Math.Pow(num2 / 2.0, y);
			int num5 = _nPts / 8;
			Coordinate[] array = new Coordinate[num5 * 8 + 1];
			double num6 = num4 / (double)num5;
			for (int i = 0; i <= num5; i++)
			{
				double num7 = 0.0;
				double num8 = num3;
				if (i != 0)
				{
					num7 = num6 * (double)i;
					double num9 = Math.Pow(num7, power);
					num8 = Math.Pow(num2 - num9, y);
				}
				array[i] = CreateCoordTrans(num7, num8, centre);
				array[2 * num5 - i] = CreateCoordTrans(num8, num7, centre);
				array[2 * num5 + i] = CreateCoordTrans(num8, 0.0 - num7, centre);
				array[4 * num5 - i] = CreateCoordTrans(num7, 0.0 - num8, centre);
				array[4 * num5 + i] = CreateCoordTrans(0.0 - num7, 0.0 - num8, centre);
				array[6 * num5 - i] = CreateCoordTrans(0.0 - num8, 0.0 - num7, centre);
				array[6 * num5 + i] = CreateCoordTrans(0.0 - num8, num7, centre);
				array[8 * num5 - i] = CreateCoordTrans(0.0 - num7, num8, centre);
			}
			array[^1] = array[0].Copy();
			LinearRing shell = GeomFact.CreateLinearRing(array);
			Polygon geom = GeomFact.CreatePolygon(shell);
			return (Polygon)Rotate(geom);
		}

		public LineString CreateArc(double startAng, double angExtent)
		{
			Envelope envelope = _dim.Envelope;
			double num = envelope.Width / 2.0;
			double num2 = envelope.Height / 2.0;
			double num3 = envelope.MinX + num;
			double num4 = envelope.MinY + num2;
			double num5 = angExtent;
			if (num5 <= 0.0 || num5 > Math.PI * 2.0)
			{
				num5 = Math.PI * 2.0;
			}
			double num6 = num5 / (double)(_nPts - 1);
			Coordinate[] array = new Coordinate[_nPts];
			int num7 = 0;
			for (int i = 0; i < _nPts; i++)
			{
				double num8 = startAng + (double)i * num6;
				double x = num * Math.Cos(num8) + num3;
				double y = num2 * Math.Sin(num8) + num4;
				Coordinate coordinate = CreateCoord(x, y);
				array[num7++] = coordinate;
			}
			LineString geom = GeomFact.CreateLineString(array);
			return (LineString)Rotate(geom);
		}

		public Polygon CreateArcPolygon(double startAng, double angExtent)
		{
			Envelope envelope = _dim.Envelope;
			double num = envelope.Width / 2.0;
			double num2 = envelope.Height / 2.0;
			double num3 = envelope.MinX + num;
			double num4 = envelope.MinY + num2;
			double num5 = angExtent;
			if (num5 <= 0.0 || num5 > Math.PI * 2.0)
			{
				num5 = Math.PI * 2.0;
			}
			double num6 = num5 / (double)(_nPts - 1);
			Coordinate[] array = new Coordinate[_nPts + 2];
			int num7 = 0;
			array[num7++] = CreateCoord(num3, num4);
			for (int i = 0; i < _nPts; i++)
			{
				double num8 = startAng + num6 * (double)i;
				double x = num * Math.Cos(num8) + num3;
				double y = num2 * Math.Sin(num8) + num4;
				array[num7++] = CreateCoord(x, y);
			}
			array[num7] = CreateCoord(num3, num4);
			LinearRing shell = GeomFact.CreateLinearRing(array);
			Polygon geom = GeomFact.CreatePolygon(shell);
			return (Polygon)Rotate(geom);
		}
	}
	public sealed class Global
	{
		private readonly NumberFormatInfo _nfi;

		private static readonly Global global = new Global();

		private Global()
		{
			_nfi = new NumberFormatInfo();
			_nfi.NumberDecimalSeparator = ".";
		}

		public static NumberFormatInfo GetNfi()
		{
			return global._nfi;
		}
	}
	[Obsolete]
	public static class Guard
	{
		public static void IsNotNull(object candidate, string propertyName)
		{
			if (candidate == null)
			{
				throw new ArgumentNullException(propertyName);
			}
		}
	}
	public class HexConverter
	{
		private HexConverter()
		{
		}

		public static string ConvertAny2Any(string valueIn, int baseIn, int baseOut)
		{
			string result = "Error";
			valueIn = valueIn.ToUpper();
			if (baseIn < 2 || baseIn > 36 || baseOut < 2 || baseOut > 36)
			{
				return result;
			}
			if (valueIn.Trim().Length == 0)
			{
				return result;
			}
			if (baseIn == baseOut)
			{
				return valueIn;
			}
			double num = 0.0;
			try
			{
				if (baseIn == 10)
				{
					num = double.Parse(valueIn);
				}
				else
				{
					char[] array = valueIn.ToCharArray();
					int num2 = array.Length;
					for (int i = 0; i < array.Length; i++)
					{
						int num3 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf(array[i]);
						if (num3 < 0 || num3 > baseIn - 1)
						{
							return result;
						}
						num2--;
						num += (double)num3 * Math.Pow(baseIn, num2);
					}
				}
				if (baseOut == 10)
				{
					result = num.ToString();
				}
				else
				{
					result = string.Empty;
					while (num > 0.0)
					{
						int num4 = (int)(num % (double)baseOut);
						num = (num - (double)num4) / (double)baseOut;
						result = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".Substring(num4, 1) + result;
					}
				}
			}
			catch (Exception ex)
			{
				result = ex.Message;
			}
			return result;
		}
	}
	public class Memory
	{
		public const double KB = 1024.0;

		public const double MB = 1048576.0;

		public const double GB = 1073741824.0;

		public static long Total => GC.GetTotalMemory(forceFullCollection: true);

		public static string TotalString => Format(Total);

		public static string Format(long mem)
		{
			if ((double)mem < 2048.0)
			{
				return mem + " bytes";
			}
			if ((double)mem < 2097152.0)
			{
				return Round((double)mem / 1024.0) + " KB";
			}
			if ((double)mem < 2147483648.0)
			{
				return Round((double)mem / 1048576.0) + " MB";
			}
			return Round((double)mem / 1073741824.0) + " GB";
		}

		public static double Round(double d)
		{
			return Math.Ceiling(d * 100.0) / 100.0;
		}
	}
	public class PriorityQueue<T> : IEnumerable<T>, IEnumerable where T : IComparable<T>
	{
		private class DataEnumerator : IEnumerator<T>, IEnumerator, IDisposable
		{
			private readonly IEnumerator<PriorityQueueNode<T, T>> _pqnEnumerator;

			public T Current
			{
				get
				{
					PriorityQueueNode<T, T> current = _pqnEnumerator.Current;
					if (current == null)
					{
						return default(T);
					}
					return current.Data;
				}
			}

			object IEnumerator.Current => Current;

			public DataEnumerator(IEnumerator<PriorityQueueNode<T, T>> pqnEnumerator)
			{
				_pqnEnumerator = pqnEnumerator;
			}

			public void Dispose()
			{
				_pqnEnumerator.Dispose();
			}

			public bool MoveNext()
			{
				return _pqnEnumerator.MoveNext();
			}

			public void Reset()
			{
				_pqnEnumerator.Reset();
			}
		}

		private readonly AlternativePriorityQueue<T, T> _queue;

		public int Size => _queue.Count;

		public PriorityQueue()
		{
			_queue = new AlternativePriorityQueue<T, T>();
		}

		public PriorityQueue(int capacity, IComparer<T> comparer)
		{
			_queue = new AlternativePriorityQueue<T, T>(capacity, comparer);
		}

		public void Add(T x)
		{
			PriorityQueueNode<T, T> node = new PriorityQueueNode<T, T>(x);
			_queue.Enqueue(node, x);
		}

		public bool IsEmpty()
		{
			return _queue.Count == 0;
		}

		public void Clear()
		{
			_queue.Clear();
		}

		public T Poll()
		{
			PriorityQueueNode<T, T> priorityQueueNode = _queue.Dequeue();
			if (priorityQueueNode != null)
			{
				return priorityQueueNode.Data;
			}
			return default(T);
		}

		public T Peek()
		{
			PriorityQueueNode<T, T> head = _queue.Head;
			if (head != null)
			{
				return head.Data;
			}
			return default(T);
		}

		public IEnumerator<T> GetEnumerator()
		{
			return new DataEnumerator(_queue.GetEnumerator());
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
	public sealed class PriorityQueueNode<TPriority, TData>
	{
		private readonly TData data;

		public TData Data => data;

		public TPriority Priority { get; internal set; }

		internal int QueueIndex { get; set; }

		public PriorityQueueNode(TData data)
		{
			this.data = data;
		}

		internal PriorityQueueNode(PriorityQueueNode<TPriority, TData> copyFrom)
		{
			data = copyFrom.data;
			Priority = copyFrom.Priority;
			QueueIndex = copyFrom.QueueIndex;
		}
	}
	public class Radians
	{
		public static double ToDegrees(double radians)
		{
			return radians * (180.0 / Math.PI);
		}
	}
	internal class ReverseOrder : IComparer
	{
		public int Compare(object x, object y)
		{
			return Comparer<object>.Default.Compare(x, y) * -1;
		}
	}
	internal sealed class TokenStream
	{
		private bool? prevMoveNextResult;

		private Token nextToken;

		public IEnumerator<Token> Enumerator { get; }

		public TokenStream(IEnumerator<Token> enumerator)
		{
			Enumerator = enumerator;
		}

		public Token NextToken(bool advance)
		{
			if (!prevMoveNextResult.HasValue)
			{
				ReadNextToken();
			}
			Token result = nextToken;
			if (advance)
			{
				ReadNextToken();
			}
			return result;
		}

		private void ReadNextToken()
		{
			if (Enumerator.MoveNext())
			{
				prevMoveNextResult = true;
				nextToken = Enumerator.Current;
				if (nextToken == null)
				{
					throw new InvalidOperationException("Token list contains a null value.");
				}
			}
			else
			{
				prevMoveNextResult = false;
				nextToken = null;
			}
		}
	}
	public class UniqueCoordinateArrayFilter : ICoordinateFilter
	{
		private readonly ISet<Coordinate> _coordSet = new HashSet<Coordinate>();

		private readonly List<Coordinate> _list = new List<Coordinate>();

		public Coordinate[] Coordinates => _list.ToArray();

		public static Coordinate[] FilterCoordinates(Coordinate[] coords)
		{
			UniqueCoordinateArrayFilter uniqueCoordinateArrayFilter = new UniqueCoordinateArrayFilter();
			for (int i = 0; i < coords.Length; i++)
			{
				uniqueCoordinateArrayFilter.Filter(coords[i]);
			}
			return uniqueCoordinateArrayFilter.Coordinates;
		}

		public void Filter(Coordinate coord)
		{
			if (_coordSet.Add(coord))
			{
				_list.Add(coord);
			}
		}
	}
}
namespace NetTopologySuite.Triangulate
{
	public class ConformingDelaunayTriangulationBuilder
	{
		private ICollection<Coordinate> _siteCoords;

		private Geometry _constraintLines;

		private double _tolerance;

		private QuadEdgeSubdivision _subdiv;

		private readonly IDictionary<Coordinate, Vertex> _constraintVertexMap = new SortedDictionary<Coordinate, Vertex>();

		public Geometry Constraints
		{
			set
			{
				_constraintLines = value;
			}
		}

		public double Tolerance
		{
			get
			{
				return _tolerance;
			}
			set
			{
				_tolerance = value;
			}
		}

		public void SetSites(Geometry sites)
		{
			_siteCoords = DelaunayTriangulationBuilder.ExtractUniqueCoordinates(sites);
		}

		private void Create()
		{
			if (_subdiv == null)
			{
				Envelope envelope = DelaunayTriangulationBuilder.Envelope(_siteCoords);
				List<Segment> segments = new List<Segment>();
				if (_constraintLines != null)
				{
					envelope.ExpandToInclude(_constraintLines.EnvelopeInternal);
					CreateVertices(_constraintLines);
					segments = CreateConstraintSegments(_constraintLines);
				}
				ConformingDelaunayTriangulator conformingDelaunayTriangulator = new ConformingDelaunayTriangulator(CreateSiteVertices(_siteCoords), _tolerance);
				conformingDelaunayTriangulator.SetConstraints(segments, new List<Vertex>(_constraintVertexMap.Values));
				conformingDelaunayTriangulator.FormInitialDelaunay();
				conformingDelaunayTriangulator.EnforceConstraints();
				_subdiv = conformingDelaunayTriangulator.Subdivision;
			}
		}

		private IEnumerable<Vertex> CreateSiteVertices(IEnumerable<Coordinate> coords)
		{
			List<Vertex> list = new List<Vertex>();
			foreach (Coordinate coord in coords)
			{
				if (!_constraintVertexMap.ContainsKey(coord))
				{
					list.Add(new ConstraintVertex(coord));
				}
			}
			return list;
		}

		private void CreateVertices(Geometry geom)
		{
			Coordinate[] coordinates = geom.Coordinates;
			for (int i = 0; i < coordinates.Length; i++)
			{
				ConstraintVertex value = new ConstraintVertex(coordinates[i]);
				_constraintVertexMap[coordinates[i]] = value;
			}
		}

		private static List<Segment> CreateConstraintSegments(Geometry geom)
		{
			ReadOnlyCollection<Geometry> lines = LinearComponentExtracter.GetLines(geom);
			List<Segment> list = new List<Segment>();
			foreach (LineString item in lines)
			{
				CreateConstraintSegments(item, list);
			}
			return list;
		}

		private static void CreateConstraintSegments(LineString line, IList<Segment> constraintSegs)
		{
			Coordinate[] coordinates = line.Coordinates;
			for (int i = 1; i < coordinates.Length; i++)
			{
				constraintSegs.Add(new Segment(coordinates[i - 1], coordinates[i]));
			}
		}

		public QuadEdgeSubdivision GetSubdivision()
		{
			Create();
			return _subdiv;
		}

		public MultiLineString GetEdges(GeometryFactory geomFact)
		{
			Create();
			return _subdiv.GetEdges(geomFact);
		}

		public GeometryCollection GetTriangles(GeometryFactory geomFact)
		{
			Create();
			return _subdiv.GetTriangles(geomFact);
		}
	}
	public class ConformingDelaunayTriangulator
	{
		private readonly IList<Vertex> _initialVertices;

		private IList<Vertex> _segVertices;

		private IList<Segment> _segments = new List<Segment>();

		private QuadEdgeSubdivision _subdiv;

		private IncrementalDelaunayTriangulator _incDel;

		private Geometry _convexHull;

		private IConstraintSplitPointFinder _splitFinder = new NonEncroachingSplitPointFinder();

		private readonly KdTree<Vertex> _kdt;

		private ConstraintVertexFactory _vertexFactory;

		private Envelope _computeAreaEnv;

		private Coordinate _splitPt;

		private readonly double _tolerance;

		private const int MaxSplitIteration = 99;

		public IConstraintSplitPointFinder SplitPointFinder
		{
			get
			{
				return _splitFinder;
			}
			set
			{
				_splitFinder = value;
			}
		}

		public double Tolerance => _tolerance;

		public ConstraintVertexFactory VertexFactory
		{
			get
			{
				return _vertexFactory;
			}
			set
			{
				_vertexFactory = value;
			}
		}

		public QuadEdgeSubdivision Subdivision => _subdiv;

		public KdTree<Vertex> KDT => _kdt;

		public IList<Vertex> InitialVertices => _initialVertices;

		public ICollection<Segment> ConstraintSegments => _segments;

		public Geometry ConvexHull => _convexHull;

		private static Envelope ComputeVertexEnvelope(IEnumerable<Vertex> vertices)
		{
			Envelope envelope = new Envelope();
			foreach (Vertex vertex in vertices)
			{
				envelope.ExpandToInclude(vertex.Coordinate);
			}
			return envelope;
		}

		public ConformingDelaunayTriangulator(IEnumerable<Vertex> initialVertices, double tolerance)
		{
			_initialVertices = new List<Vertex>(initialVertices);
			_tolerance = tolerance;
			_kdt = new KdTree<Vertex>(tolerance);
		}

		public void SetConstraints(IList<Segment> segments, IList<Vertex> segVertices)
		{
			_segments = segments;
			_segVertices = segVertices;
		}

		private void ComputeBoundingBox()
		{
			Envelope env = ComputeVertexEnvelope(_initialVertices);
			Envelope other = ComputeVertexEnvelope(_segVertices);
			Envelope envelope = new Envelope(env);
			envelope.ExpandToInclude(other);
			double val = envelope.Width * 0.2;
			double val2 = envelope.Height * 0.2;
			double distance = Math.Max(val, val2);
			_computeAreaEnv = new Envelope(envelope);
			_computeAreaEnv.ExpandBy(distance);
		}

		private void ComputeConvexHull()
		{
			GeometryFactory geomFactory = new GeometryFactory();
			ConvexHull convexHull = new ConvexHull(GetPointArray(), geomFactory);
			_convexHull = convexHull.GetConvexHull();
		}

		private Coordinate[] GetPointArray()
		{
			Coordinate[] array = new Coordinate[_initialVertices.Count + _segVertices.Count];
			int num = 0;
			foreach (Vertex initialVertex in _initialVertices)
			{
				array[num++] = initialVertex.Coordinate;
			}
			foreach (Vertex segVertex in _segVertices)
			{
				array[num++] = segVertex.Coordinate;
			}
			return array;
		}

		private ConstraintVertex CreateVertex(Coordinate p)
		{
			ConstraintVertex constraintVertex = null;
			if (_vertexFactory != null)
			{
				return _vertexFactory.CreateVertex(p, null);
			}
			return new ConstraintVertex(p);
		}

		private ConstraintVertex CreateVertex(Coordinate p, Segment seg)
		{
			ConstraintVertex constraintVertex = ((_vertexFactory == null) ? new ConstraintVertex(p) : _vertexFactory.CreateVertex(p, seg));
			constraintVertex.IsOnConstraint = true;
			return constraintVertex;
		}

		private void InsertSites(ICollection<Vertex> vertices)
		{
			foreach (Vertex vertex in vertices)
			{
				InsertSite((ConstraintVertex)vertex);
			}
		}

		private ConstraintVertex InsertSite(ConstraintVertex v)
		{
			KdNode<Vertex> kdNode = _kdt.Insert(v.Coordinate, v);
			if (!kdNode.IsRepeated)
			{
				_incDel.InsertSite(v);
				return v;
			}
			ConstraintVertex obj = (ConstraintVertex)kdNode.Data;
			obj.Merge(v);
			return obj;
		}

		public void InsertSite(Coordinate p)
		{
			InsertSite(CreateVertex(p));
		}

		public void FormInitialDelaunay()
		{
			ComputeBoundingBox();
			_subdiv = new QuadEdgeSubdivision(_computeAreaEnv, _tolerance);
			_subdiv.SetLocator(new LastFoundQuadEdgeLocator(_subdiv));
			_incDel = new IncrementalDelaunayTriangulator(_subdiv);
			InsertSites(_initialVertices);
		}

		public void EnforceConstraints()
		{
			AddConstraintVertices();
			int num = 0;
			int num2;
			do
			{
				num2 = EnforceGabriel(_segments);
				num++;
			}
			while (num2 > 0 && num < 99);
			if (num == 99 && !Debugger.IsAttached)
			{
				throw new ConstraintEnforcementException("Too many splitting iterations while enforcing constraints.  Last split point was at: ", _splitPt);
			}
		}

		private void AddConstraintVertices()
		{
			ComputeConvexHull();
			InsertSites(_segVertices);
		}

		private int EnforceGabriel(ICollection<Segment> segsToInsert)
		{
			List<Segment> list = new List<Segment>();
			int num = 0;
			List<Segment> list2 = new List<Segment>();
			foreach (Segment item3 in segsToInsert)
			{
				Coordinate coordinate = FindNonGabrielPoint(item3);
				if (coordinate != null)
				{
					_splitPt = _splitFinder.FindSplitPoint(item3, coordinate);
					ConstraintVertex constraintVertex = CreateVertex(_splitPt, item3);
					InsertSite(constraintVertex).Coordinate.Equals2D(_splitPt);
					Segment item = new Segment(item3.StartX, item3.StartY, item3.StartZ, constraintVertex.X, constraintVertex.Y, constraintVertex.Z, item3.Data);
					Segment item2 = new Segment(constraintVertex.X, constraintVertex.Y, constraintVertex.Z, item3.EndX, item3.EndY, item3.EndZ, item3.Data);
					list.Add(item);
					list.Add(item2);
					list2.Add(item3);
					num++;
				}
			}
			foreach (Segment item4 in list2)
			{
				segsToInsert.Remove(item4);
			}
			foreach (Segment item5 in list)
			{
				segsToInsert.Add(item5);
			}
			return num;
		}

		private Coordinate FindNonGabrielPoint(Segment seg)
		{
			Coordinate start = seg.Start;
			Coordinate end = seg.End;
			Coordinate coordinate = new Coordinate((start.X + end.X) / 2.0, (start.Y + end.Y) / 2.0);
			double num = start.Distance(coordinate);
			Envelope envelope = new Envelope(coordinate);
			envelope.ExpandBy(num);
			IList<KdNode<Vertex>> list = _kdt.Query(envelope);
			Coordinate coordinate2 = null;
			double num2 = double.MaxValue;
			foreach (KdNode<Vertex> item in list)
			{
				Coordinate coordinate3 = item.Coordinate;
				if (coordinate3.Equals2D(start) || coordinate3.Equals2D(end))
				{
					continue;
				}
				double num3 = coordinate.Distance(coordinate3);
				if (num3 < num)
				{
					double num4 = num3;
					if (coordinate2 == null || num4 < num2)
					{
						coordinate2 = coordinate3;
						num2 = num4;
					}
				}
			}
			return coordinate2;
		}
	}
	public class ConstraintEnforcementException : Exception
	{
		private readonly Coordinate _pt;

		public Coordinate Coordinate => _pt;

		private static string MsgWithCoord(string msg, Coordinate pt)
		{
			if (pt != null)
			{
				return msg + " [ " + WKTWriter.ToPoint(pt) + " ]";
			}
			return msg;
		}

		public ConstraintEnforcementException(string msg)
			: base(msg)
		{
		}

		public ConstraintEnforcementException(string msg, Coordinate pt)
			: base(MsgWithCoord(msg, pt))
		{
			_pt = pt.Copy();
		}
	}
	public class ConstraintVertex : Vertex
	{
		private bool isOnConstraint;

		private object constraint;

		public bool IsOnConstraint
		{
			get
			{
				return isOnConstraint;
			}
			set
			{
				isOnConstraint = value;
			}
		}

		public object Constraint
		{
			get
			{
				return constraint;
			}
			set
			{
				isOnConstraint = true;
				constraint = value;
			}
		}

		public ConstraintVertex(Coordinate p)
			: base(p)
		{
		}

		protected internal void Merge(ConstraintVertex other)
		{
			if (other.isOnConstraint)
			{
				isOnConstraint = true;
				constraint = other.constraint;
			}
		}
	}
	public interface ConstraintVertexFactory
	{
		ConstraintVertex CreateVertex(Coordinate p, Segment constraintSeg);
	}
	public class DelaunayTriangulationBuilder
	{
		private ICollection<Coordinate> _siteCoords;

		private double _tolerance;

		private QuadEdgeSubdivision _subdiv;

		public double Tolerance
		{
			set
			{
				_tolerance = value;
			}
		}

		public static CoordinateList ExtractUniqueCoordinates(Geometry geom)
		{
			if (geom == null)
			{
				return new CoordinateList();
			}
			return Unique(geom.Coordinates);
		}

		public static CoordinateList Unique(Coordinate[] coords)
		{
			Coordinate[] array = CoordinateArrays.CopyDeep(coords);
			Array.Sort(array);
			return new CoordinateList(array, allowRepeated: false);
		}

		public static IList<Vertex> ToVertices(ICollection<Coordinate> coords)
		{
			List<Vertex> list = new List<Vertex>();
			foreach (Coordinate coord in coords)
			{
				list.Add(new Vertex(coord));
			}
			return list;
		}

		public static Envelope Envelope(ICollection<Coordinate> coords)
		{
			Envelope envelope = new Envelope();
			foreach (Coordinate coord in coords)
			{
				envelope.ExpandToInclude(coord);
			}
			return envelope;
		}

		public void SetSites(Geometry geom)
		{
			_siteCoords = ExtractUniqueCoordinates(geom);
		}

		public void SetSites(ICollection<Coordinate> coords)
		{
			_siteCoords = Unique(CoordinateArrays.ToCoordinateArray(coords));
		}

		private void Create()
		{
			if (_subdiv == null)
			{
				Envelope env = Envelope(_siteCoords);
				IList<Vertex> vertices = ToVertices(_siteCoords);
				_subdiv = new QuadEdgeSubdivision(env, _tolerance);
				new IncrementalDelaunayTriangulator(_subdiv).InsertSites(vertices);
			}
		}

		public QuadEdgeSubdivision GetSubdivision()
		{
			Create();
			return _subdiv;
		}

		public MultiLineString GetEdges(GeometryFactory geomFact)
		{
			Create();
			return _subdiv.GetEdges(geomFact);
		}

		public GeometryCollection GetTriangles(GeometryFactory geomFact)
		{
			Create();
			return _subdiv.GetTriangles(geomFact);
		}
	}
	public interface IConstraintSplitPointFinder
	{
		Coordinate FindSplitPoint(Segment seg, Coordinate encroachPt);
	}
	public class IncrementalDelaunayTriangulator
	{
		private readonly QuadEdgeSubdivision _subdiv;

		private bool _isUsingTolerance;

		public IncrementalDelaunayTriangulator(QuadEdgeSubdivision subdiv)
		{
			_subdiv = subdiv;
			_isUsingTolerance = subdiv.Tolerance > 0.0;
		}

		public void InsertSites(ICollection<Vertex> vertices)
		{
			foreach (Vertex vertex in vertices)
			{
				InsertSite(vertex);
			}
		}

		public NetTopologySuite.Triangulate.QuadEdge.QuadEdge InsertSite(Vertex v)
		{
			NetTopologySuite.Triangulate.QuadEdge.QuadEdge quadEdge = _subdiv.Locate(v);
			if (_subdiv.IsVertexOfEdge(quadEdge, v))
			{
				return quadEdge;
			}
			if (_subdiv.IsOnEdge(quadEdge, v.Coordinate))
			{
				quadEdge = quadEdge.OPrev;
				_subdiv.Delete(quadEdge.ONext);
			}
			NetTopologySuite.Triangulate.QuadEdge.QuadEdge quadEdge2 = _subdiv.MakeEdge(quadEdge.Orig, v);
			NetTopologySuite.Triangulate.QuadEdge.QuadEdge.Splice(quadEdge2, quadEdge);
			NetTopologySuite.Triangulate.QuadEdge.QuadEdge quadEdge3 = quadEdge2;
			do
			{
				quadEdge2 = _subdiv.Connect(quadEdge, quadEdge2.Sym);
				quadEdge = quadEdge2.OPrev;
			}
			while (quadEdge.LNext != quadEdge3);
			while (true)
			{
				NetTopologySuite.Triangulate.QuadEdge.QuadEdge oPrev = quadEdge.OPrev;
				if (oPrev.Dest.RightOf(quadEdge) && v.IsInCircle(quadEdge.Orig, oPrev.Dest, quadEdge.Dest))
				{
					NetTopologySuite.Triangulate.QuadEdge.QuadEdge.Swap(quadEdge);
					quadEdge = quadEdge.OPrev;
					continue;
				}
				if (quadEdge.ONext == quadEdge3)
				{
					break;
				}
				quadEdge = quadEdge.ONext.LPrev;
			}
			return quadEdge2;
		}
	}
	public class MidpointSplitPointFinder : IConstraintSplitPointFinder
	{
		public Coordinate FindSplitPoint(Segment seg, Coordinate encroachPt)
		{
			Coordinate start = seg.Start;
			Coordinate end = seg.End;
			return new Coordinate((start.X + end.X) / 2.0, (start.Y + end.Y) / 2.0);
		}
	}
	public class NonEncroachingSplitPointFinder : IConstraintSplitPointFinder
	{
		public Coordinate FindSplitPoint(Segment seg, Coordinate encroachPt)
		{
			LineSegment lineSegment = seg.LineSegment;
			double num = lineSegment.Length / 2.0;
			SplitSegment splitSegment = new SplitSegment(lineSegment);
			Coordinate coordinate = ProjectedSplitPoint(seg, encroachPt);
			double num2 = coordinate.Distance(encroachPt) * 2.0 * 0.8;
			if (num2 > num)
			{
				num2 = num;
			}
			splitSegment.MinimumLength = num2;
			splitSegment.SplitAt(coordinate);
			return splitSegment.SplitPoint;
		}

		public static Coordinate ProjectedSplitPoint(Segment seg, Coordinate encroachPt)
		{
			return seg.LineSegment.Project(encroachPt);
		}
	}
	public class Segment
	{
		private readonly LineSegment _ls;

		public Coordinate Start => _ls.GetCoordinate(0);

		public Coordinate End => _ls.GetCoordinate(1);

		public double StartX => _ls.GetCoordinate(0).X;

		public double StartY => _ls.GetCoordinate(0).Y;

		public double StartZ => _ls.GetCoordinate(0).Z;

		public double EndX => _ls.GetCoordinate(1).X;

		public double EndY => _ls.GetCoordinate(1).Y;

		public double EndZ => _ls.GetCoordinate(1).Z;

		public LineSegment LineSegment => _ls;

		public object Data { get; set; }

		public Segment(double x1, double y1, double z1, double x2, double y2, double z2)
			: this(new CoordinateZ(x1, y1, z1), new CoordinateZ(x2, y2, z2))
		{
		}

		public Segment(double x1, double y1, double z1, double x2, double y2, double z2, object data)
			: this(new CoordinateZ(x1, y1, z1), new CoordinateZ(x2, y2, z2), data)
		{
		}

		public Segment(Coordinate p0, Coordinate p1, object data)
		{
			_ls = new LineSegment(p0, p1);
			Data = data;
		}

		public Segment(Coordinate p0, Coordinate p1)
		{
			_ls = new LineSegment(p0, p1);
		}

		public bool EqualsTopologically(Segment s)
		{
			return _ls.EqualsTopologically(s.LineSegment);
		}

		public Coordinate Intersection(Segment s)
		{
			return _ls.Intersection(s.LineSegment);
		}

		public override string ToString()
		{
			return _ls.ToString();
		}
	}
	public class SplitSegment
	{
		private readonly LineSegment _seg;

		private readonly double _segLen;

		private Coordinate _splitPt;

		private double _minimumLen;

		public double MinimumLength
		{
			get
			{
				return _minimumLen;
			}
			set
			{
				_minimumLen = value;
			}
		}

		public Coordinate SplitPoint => _splitPt;

		private static Coordinate PointAlongReverse(LineSegment seg, double segmentLengthFraction)
		{
			return new Coordinate
			{
				X = seg.P1.X - segmentLengthFraction * (seg.P1.X - seg.P0.X),
				Y = seg.P1.Y - segmentLengthFraction * (seg.P1.Y - seg.P0.Y)
			};
		}

		public SplitSegment(LineSegment seg)
		{
			_seg = seg;
			_segLen = seg.Length;
		}

		public void SplitAt(double length, Coordinate endPt)
		{
			double segmentLengthFraction = GetConstrainedLength(length) / _segLen;
			if (endPt.Equals2D(_seg.P0))
			{
				_splitPt = _seg.PointAlong(segmentLengthFraction);
			}
			else
			{
				_splitPt = PointAlongReverse(_seg, segmentLengthFraction);
			}
		}

		public void SplitAt(Coordinate pt)
		{
			double segmentLengthFraction = _minimumLen / _segLen;
			if (pt.Distance(_seg.P0) < _minimumLen)
			{
				_splitPt = _seg.PointAlong(segmentLengthFraction);
			}
			else if (pt.Distance(_seg.P1) < _minimumLen)
			{
				_splitPt = PointAlongReverse(_seg, segmentLengthFraction);
			}
			else
			{
				_splitPt = pt;
			}
		}

		private double GetConstrainedLength(double len)
		{
			if (len < _minimumLen)
			{
				return _minimumLen;
			}
			return len;
		}
	}
	public class VertexTaggedGeometryDataMapper
	{
		private readonly IDictionary<Coordinate, object> _coordDataMap = new SortedDictionary<Coordinate, object>();

		public IList<Coordinate> Coordinates => new List<Coordinate>(_coordDataMap.Keys);

		public void LoadSourceGeometries(Geometry geoms)
		{
			for (int i = 0; i < geoms.NumGeometries; i++)
			{
				Geometry geometryN = geoms.GetGeometryN(i);
				LoadVertices(geometryN.Coordinates, geometryN.UserData);
			}
		}

		public void LoadSourceGeometries(ICollection<Geometry> geoms)
		{
			foreach (Geometry geom in geoms)
			{
				LoadVertices(geom.Coordinates, geom.UserData);
			}
		}

		public void LoadSourceGeometries(GeometryCollection geomColl)
		{
			for (int i = 0; i < geomColl.NumGeometries; i++)
			{
				Geometry geometryN = geomColl.GetGeometryN(i);
				LoadVertices(geometryN.Coordinates, geometryN.UserData);
			}
		}

		private void LoadVertices(Coordinate[] pts, object data)
		{
			for (int i = 0; i < pts.Length; i++)
			{
				_coordDataMap.Add(pts[i], data);
			}
		}

		public void TransferData(Geometry targetGeom)
		{
			for (int i = 0; i < targetGeom.NumGeometries; i++)
			{
				Geometry geometryN = targetGeom.GetGeometryN(i);
				Coordinate coordinate = (Coordinate)geometryN.UserData;
				if (coordinate != null)
				{
					geometryN.UserData = _coordDataMap[coordinate];
				}
			}
		}
	}
	public class VoronoiDiagramBuilder
	{
		private ICollection<Coordinate> _siteCoords;

		private double _tolerance;

		private QuadEdgeSubdivision _subdiv;

		private Envelope _clipEnv;

		private Envelope _diagramEnv;

		public Envelope ClipEnvelope
		{
			set
			{
				_clipEnv = value;
			}
		}

		public double Tolerance
		{
			set
			{
				_tolerance = value;
			}
		}

		public void SetSites(Geometry geom)
		{
			_siteCoords = DelaunayTriangulationBuilder.ExtractUniqueCoordinates(geom);
		}

		public void SetSites(ICollection<Coordinate> coords)
		{
			_siteCoords = DelaunayTriangulationBuilder.Unique(CoordinateArrays.ToCoordinateArray(coords));
		}

		private void Create()
		{
			if (_subdiv == null)
			{
				DelaunayTriangulationBuilder.Envelope(_siteCoords);
				_diagramEnv = _clipEnv;
				if (_diagramEnv == null)
				{
					_diagramEnv = DelaunayTriangulationBuilder.Envelope(_siteCoords);
					double diameter = _diagramEnv.Diameter;
					_diagramEnv.ExpandBy(diameter);
				}
				IList<Vertex> vertices = DelaunayTriangulationBuilder.ToVertices(_siteCoords);
				_subdiv = new QuadEdgeSubdivision(_diagramEnv, _tolerance);
				new IncrementalDelaunayTriangulator(_subdiv).InsertSites(vertices);
			}
		}

		public QuadEdgeSubdivision GetSubdivision()
		{
			Create();
			return _subdiv;
		}

		public GeometryCollection GetDiagram(GeometryFactory geomFact)
		{
			Create();
			return ClipGeometryCollection(_subdiv.GetVoronoiDiagram(geomFact), _diagramEnv);
		}

		private static GeometryCollection ClipGeometryCollection(GeometryCollection geom, Envelope clipEnv)
		{
			Geometry geometry = geom.Factory.ToGeometry(clipEnv);
			List<Geometry> list = new List<Geometry>();
			for (int i = 0; i < geom.NumGeometries; i++)
			{
				Geometry geometryN = geom.GetGeometryN(i);
				Geometry geometry2 = null;
				if (clipEnv.Contains(geometryN.EnvelopeInternal))
				{
					geometry2 = geometryN;
				}
				else if (clipEnv.Intersects(geometryN.EnvelopeInternal))
				{
					geometry2 = geometry.Intersection(geometryN);
					geometry2.UserData = geometryN.UserData;
				}
				if (geometry2 != null && !geometry2.IsEmpty)
				{
					list.Add(geometry2);
				}
			}
			return geom.Factory.CreateGeometryCollection(GeometryFactory.ToGeometryArray(list));
		}
	}
}
namespace NetTopologySuite.Triangulate.QuadEdge
{
	public class EdgeConnectedTriangleTraversal
	{
		private readonly LinkedList<QuadEdgeTriangle> _triQueue = new LinkedList<QuadEdgeTriangle>();

		public void Init(QuadEdgeTriangle tri)
		{
			_triQueue.AddLast(tri);
		}

		public void Init(IEnumerable<QuadEdgeTriangle> tris)
		{
			foreach (QuadEdgeTriangle tri in tris)
			{
				_triQueue.AddLast(tri);
			}
		}

		public void VisitAll(ITraversalVisitor visitor)
		{
			while (_triQueue.Count > 0)
			{
				QuadEdgeTriangle value = _triQueue.First.Value;
				_triQueue.RemoveFirst();
				Process(value, visitor);
			}
		}

		private void Process(QuadEdgeTriangle currTri, ITraversalVisitor visitor)
		{
			currTri.GetNeighbours();
			for (int i = 0; i < 3; i++)
			{
				QuadEdgeTriangle quadEdgeTriangle = (QuadEdgeTriangle)currTri.GetEdge(i).Sym.Data;
				if (quadEdgeTriangle != null && visitor.Visit(currTri, i, quadEdgeTriangle))
				{
					_triQueue.AddLast(quadEdgeTriangle);
				}
			}
		}
	}
	public interface IQuadEdgeLocator
	{
		QuadEdge Locate(Vertex v);
	}
	public interface ITraversalVisitor
	{
		bool Visit(QuadEdgeTriangle currTri, int edgeIndex, QuadEdgeTriangle neighbTri);
	}
	public interface ITriangleVisitor
	{
		void Visit(QuadEdge[] triEdges);
	}
	public class LastFoundQuadEdgeLocator : IQuadEdgeLocator
	{
		private readonly QuadEdgeSubdivision _subdiv;

		private QuadEdge _lastEdge;

		public LastFoundQuadEdgeLocator(QuadEdgeSubdivision subdiv)
		{
			_subdiv = subdiv;
			Init();
		}

		private void Init()
		{
			_lastEdge = FindEdge();
		}

		private QuadEdge FindEdge()
		{
			IEnumerator<QuadEdge> enumerator = _subdiv.GetEdges().GetEnumerator();
			if (enumerator.MoveNext())
			{
				return enumerator.Current;
			}
			throw new IndexOutOfRangeException();
		}

		public QuadEdge Locate(Vertex v)
		{
			if (!_lastEdge.IsLive)
			{
				Init();
			}
			return _lastEdge = _subdiv.LocateFromEdge(v, _lastEdge);
		}
	}
	public class LocateFailureException : Exception
	{
		public LineSegment Segment { get; private set; }

		private static string MsgWithSpatial(string msg, LineSegment seg)
		{
			if (seg != null)
			{
				return msg + " [ " + seg?.ToString() + " ]";
			}
			return msg;
		}

		public LocateFailureException(string msg)
			: base(msg)
		{
		}

		public LocateFailureException(string msg, LineSegment seg)
			: base(MsgWithSpatial(msg, seg))
		{
			Segment = new LineSegment(seg);
		}

		public LocateFailureException(LineSegment seg)
			: base("Locate failed to converge (at edge: " + seg?.ToString() + ").  Possible causes include invalid Subdivision topology or very close sites")
		{
			Segment = new LineSegment(seg);
		}
	}
	public class QuadEdge
	{
		private Vertex _vertex;

		private QuadEdge _next;

		public object Data { get; set; }

		public bool IsLive => Rot != null;

		public QuadEdge Rot { get; private set; }

		public QuadEdge InvRot => Rot.Sym;

		public QuadEdge Sym => Rot.Rot;

		public QuadEdge ONext => _next;

		public QuadEdge OPrev => Rot._next.Rot;

		public QuadEdge DNext => Sym.ONext.Sym;

		public QuadEdge DPrev => InvRot.ONext.InvRot;

		public QuadEdge LNext => InvRot.ONext.Rot;

		public QuadEdge LPrev => _next.Sym;

		public QuadEdge RNext => Rot._next.InvRot;

		public QuadEdge RPrev => Sym.ONext;

		public Vertex Orig
		{
			get
			{
				return _vertex;
			}
			internal set
			{
				_vertex = value;
			}
		}

		public Vertex Dest
		{
			get
			{
				return Sym.Orig;
			}
			internal set
			{
				Sym.Orig = value;
			}
		}

		public double Length => Orig.Coordinate.Distance(Dest.Coordinate);

		public static QuadEdge MakeEdge(Vertex o, Vertex d)
		{
			QuadEdge quadEdge = new QuadEdge();
			QuadEdge quadEdge2 = new QuadEdge();
			QuadEdge quadEdge3 = new QuadEdge();
			QuadEdge quadEdge4 = new QuadEdge();
			quadEdge.Rot = quadEdge2;
			quadEdge2.Rot = quadEdge3;
			quadEdge3.Rot = quadEdge4;
			quadEdge4.Rot = quadEdge;
			quadEdge.SetNext(quadEdge);
			quadEdge2.SetNext(quadEdge4);
			quadEdge3.SetNext(quadEdge3);
			quadEdge4.SetNext(quadEdge2);
			quadEdge.Orig = o;
			quadEdge.Dest = d;
			return quadEdge;
		}

		public static QuadEdge Connect(QuadEdge a, QuadEdge b)
		{
			QuadEdge quadEdge = MakeEdge(a.Dest, b.Orig);
			Splice(quadEdge, a.LNext);
			Splice(quadEdge.Sym, b);
			return quadEdge;
		}

		public static void Splice(QuadEdge a, QuadEdge b)
		{
			QuadEdge rot = a.ONext.Rot;
			QuadEdge rot2 = b.ONext.Rot;
			QuadEdge oNext = b.ONext;
			QuadEdge oNext2 = a.ONext;
			QuadEdge oNext3 = rot2.ONext;
			QuadEdge oNext4 = rot.ONext;
			a.SetNext(oNext);
			b.SetNext(oNext2);
			rot.SetNext(oNext3);
			rot2.SetNext(oNext4);
		}

		public static void Swap(QuadEdge e)
		{
			QuadEdge oPrev = e.OPrev;
			QuadEdge oPrev2 = e.Sym.OPrev;
			Splice(e, oPrev);
			Splice(e.Sym, oPrev2);
			Splice(e, oPrev.LNext);
			Splice(e.Sym, oPrev2.LNext);
			e.Orig = oPrev.Dest;
			e.Dest = oPrev2.Dest;
		}

		private QuadEdge()
		{
		}

		public QuadEdge GetPrimary()
		{
			if (Orig.Coordinate.CompareTo(Dest.Coordinate) <= 0)
			{
				return this;
			}
			return Sym;
		}

		public void Delete()
		{
			Rot = null;
		}

		public void SetNext(QuadEdge next)
		{
			_next = next;
		}

		public bool EqualsNonOriented(QuadEdge qe)
		{
			if (EqualsOriented(qe))
			{
				return true;
			}
			if (EqualsOriented(qe.Sym))
			{
				return true;
			}
			return false;
		}

		public bool EqualsOriented(QuadEdge qe)
		{
			if (Orig.Coordinate.Equals2D(qe.Orig.Coordinate) && Dest.Coordinate.Equals2D(qe.Dest.Coordinate))
			{
				return true;
			}
			return false;
		}

		public LineSegment ToLineSegment()
		{
			return new LineSegment(_vertex.Coordinate, Dest.Coordinate);
		}

		public override string ToString()
		{
			Coordinate coordinate = _vertex.Coordinate;
			Coordinate coordinate2 = Dest.Coordinate;
			return WKTWriter.ToLineString(coordinate, coordinate2);
		}
	}
	public class QuadEdgeSubdivision
	{
		private class TriangleCircumcentreVisitor : ITriangleVisitor
		{
			public void Visit(QuadEdge[] triEdges)
			{
				Coordinate coordinate = triEdges[0].Orig.Coordinate;
				Coordinate coordinate2 = triEdges[1].Orig.Coordinate;
				Coordinate coordinate3 = triEdges[2].Orig.Coordinate;
				Vertex orig = new Vertex(Triangle.CircumcentreDD(coordinate, coordinate2, coordinate3));
				for (int i = 0; i < 3; i++)
				{
					triEdges[i].Rot.Orig = orig;
				}
			}
		}

		private class TriangleEdgesListVisitor : ITriangleVisitor
		{
			private readonly IList<QuadEdge[]> _triList = new List<QuadEdge[]>();

			public void Visit(QuadEdge[] triEdges)
			{
				_triList.Add(triEdges);
			}

			public IList<QuadEdge[]> GetTriangleEdges()
			{
				return _triList;
			}
		}

		private class TriangleVertexListVisitor : ITriangleVisitor
		{
			private readonly IList<Vertex[]> _triList = new List<Vertex[]>();

			public void Visit(QuadEdge[] triEdges)
			{
				_triList.Add(new Vertex[3]
				{
					triEdges[0].Orig,
					triEdges[1].Orig,
					triEdges[2].Orig
				});
			}

			public IList<Vertex[]> GetTriangleVertices()
			{
				return _triList;
			}
		}

		private class TriangleCoordinatesVisitor : ITriangleVisitor
		{
			private readonly CoordinateList _coordList = new CoordinateList();

			private readonly List<Coordinate[]> _triCoords = new List<Coordinate[]>();

			public void Visit(QuadEdge[] triEdges)
			{
				_coordList.Clear();
				for (int i = 0; i < 3; i++)
				{
					Vertex orig = triEdges[i].Orig;
					_coordList.Add(orig.Coordinate);
				}
				if (_coordList.Count > 0)
				{
					_coordList.CloseRing();
					Coordinate[] array = _coordList.ToCoordinateArray();
					if (array.Length == 4)
					{
						_triCoords.Add(array);
					}
				}
			}

			private static void CheckTriangleSize(Coordinate[] pts)
			{
				string text = "";
				if (pts.Length >= 2)
				{
					text = WKTWriter.ToLineString(pts[0], pts[1]);
				}
				else if (pts.Length >= 1)
				{
					text = WKTWriter.ToPoint(pts[0]);
				}
				Assert.IsTrue(pts.Length == 4, "Too few points for visited triangle at " + text);
			}

			public IList<Coordinate[]> GetTriangles()
			{
				return _triCoords;
			}
		}

		private 

plugins\System.Buffers.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using FxResources.System.Buffers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyTitle("System.Buffers")]
[assembly: AssemblyDescription("System.Buffers")]
[assembly: AssemblyDefaultAlias("System.Buffers")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyCopyright("© Microsoft Corporation.  All rights reserved.")]
[assembly: AssemblyFileVersion("4.6.25519.03")]
[assembly: AssemblyInformationalVersion("4.6.25519.03 built by: dlab-DDVSOWINAGE013. Commit Hash: 8321c729934c0f8be754953439b88e6e1c120c24")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.2.0")]
[module: UnverifiableCode]
namespace FxResources.System.Buffers
{
	internal static class SR
	{
	}
}
namespace System
{
	internal static class SR
	{
		private static ResourceManager s_resourceManager;

		private const string s_resourcesName = "FxResources.System.Buffers.SR";

		private static ResourceManager ResourceManager => s_resourceManager ?? (s_resourceManager = new ResourceManager(ResourceType));

		internal static string ArgumentException_BufferNotFromPool => GetResourceString("ArgumentException_BufferNotFromPool", null);

		internal static Type ResourceType => typeof(SR);

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool UsingResourceKeys()
		{
			return false;
		}

		internal static string GetResourceString(string resourceKey, string defaultString)
		{
			string text = null;
			try
			{
				text = ResourceManager.GetString(resourceKey);
			}
			catch (MissingManifestResourceException)
			{
			}
			if (defaultString != null && resourceKey.Equals(text, StringComparison.Ordinal))
			{
				return defaultString;
			}
			return text;
		}

		internal static string Format(string resourceFormat, params object[] args)
		{
			if (args != null)
			{
				if (UsingResourceKeys())
				{
					return resourceFormat + string.Join(", ", args);
				}
				return string.Format(resourceFormat, args);
			}
			return resourceFormat;
		}

		internal static string Format(string resourceFormat, object p1)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1);
			}
			return string.Format(resourceFormat, p1);
		}

		internal static string Format(string resourceFormat, object p1, object p2)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2);
			}
			return string.Format(resourceFormat, p1, p2);
		}

		internal static string Format(string resourceFormat, object p1, object p2, object p3)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2, p3);
			}
			return string.Format(resourceFormat, p1, p2, p3);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.All)]
	internal class __BlockReflectionAttribute : Attribute
	{
	}
}
namespace System.Buffers
{
	public abstract class ArrayPool<T>
	{
		private static ArrayPool<T> s_sharedInstance;

		public static ArrayPool<T> Shared
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				return Volatile.Read(ref s_sharedInstance) ?? EnsureSharedCreated();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static ArrayPool<T> EnsureSharedCreated()
		{
			Interlocked.CompareExchange(ref s_sharedInstance, Create(), null);
			return s_sharedInstance;
		}

		public static ArrayPool<T> Create()
		{
			return new DefaultArrayPool<T>();
		}

		public static ArrayPool<T> Create(int maxArrayLength, int maxArraysPerBucket)
		{
			return new DefaultArrayPool<T>(maxArrayLength, maxArraysPerBucket);
		}

		public abstract T[] Rent(int minimumLength);

		public abstract void Return(T[] array, bool clearArray = false);
	}
	[EventSource(Name = "System.Buffers.ArrayPoolEventSource")]
	internal sealed class ArrayPoolEventSource : EventSource
	{
		internal enum BufferAllocatedReason
		{
			Pooled,
			OverMaximumSize,
			PoolExhausted
		}

		internal static readonly System.Buffers.ArrayPoolEventSource Log = new System.Buffers.ArrayPoolEventSource();

		[Event(1, Level = EventLevel.Verbose)]
		internal unsafe void BufferRented(int bufferId, int bufferSize, int poolId, int bucketId)
		{
			EventData* ptr = stackalloc EventData[4];
			ptr->Size = 4;
			ptr->DataPointer = (IntPtr)(&bufferId);
			ptr[1].Size = 4;
			ptr[1].DataPointer = (IntPtr)(&bufferSize);
			ptr[2].Size = 4;
			ptr[2].DataPointer = (IntPtr)(&poolId);
			ptr[3].Size = 4;
			ptr[3].DataPointer = (IntPtr)(&bucketId);
			WriteEventCore(1, 4, ptr);
		}

		[Event(2, Level = EventLevel.Informational)]
		internal unsafe void BufferAllocated(int bufferId, int bufferSize, int poolId, int bucketId, BufferAllocatedReason reason)
		{
			EventData* ptr = stackalloc EventData[5];
			ptr->Size = 4;
			ptr->DataPointer = (IntPtr)(&bufferId);
			ptr[1].Size = 4;
			ptr[1].DataPointer = (IntPtr)(&bufferSize);
			ptr[2].Size = 4;
			ptr[2].DataPointer = (IntPtr)(&poolId);
			ptr[3].Size = 4;
			ptr[3].DataPointer = (IntPtr)(&bucketId);
			ptr[4].Size = 4;
			ptr[4].DataPointer = (IntPtr)(&reason);
			WriteEventCore(2, 5, ptr);
		}

		[Event(3, Level = EventLevel.Verbose)]
		internal void BufferReturned(int bufferId, int bufferSize, int poolId)
		{
			WriteEvent(3, bufferId, bufferSize, poolId);
		}
	}
	internal sealed class DefaultArrayPool<T> : ArrayPool<T>
	{
		private sealed class Bucket
		{
			internal readonly int _bufferLength;

			private readonly T[][] _buffers;

			private readonly int _poolId;

			private SpinLock _lock;

			private int _index;

			internal int Id => GetHashCode();

			internal Bucket(int bufferLength, int numberOfBuffers, int poolId)
			{
				_lock = new SpinLock(Debugger.IsAttached);
				_buffers = new T[numberOfBuffers][];
				_bufferLength = bufferLength;
				_poolId = poolId;
			}

			internal T[] Rent()
			{
				T[][] buffers = _buffers;
				T[] array = null;
				bool lockTaken = false;
				bool flag = false;
				try
				{
					_lock.Enter(ref lockTaken);
					if (_index < buffers.Length)
					{
						array = buffers[_index];
						buffers[_index++] = null;
						flag = array == null;
					}
				}
				finally
				{
					if (lockTaken)
					{
						_lock.Exit(useMemoryBarrier: false);
					}
				}
				if (flag)
				{
					array = new T[_bufferLength];
					System.Buffers.ArrayPoolEventSource log = System.Buffers.ArrayPoolEventSource.Log;
					if (log.IsEnabled())
					{
						log.BufferAllocated(array.GetHashCode(), _bufferLength, _poolId, Id, System.Buffers.ArrayPoolEventSource.BufferAllocatedReason.Pooled);
					}
				}
				return array;
			}

			internal void Return(T[] array)
			{
				if (array.Length != _bufferLength)
				{
					throw new ArgumentException(System.SR.ArgumentException_BufferNotFromPool, "array");
				}
				bool lockTaken = false;
				try
				{
					_lock.Enter(ref lockTaken);
					if (_index != 0)
					{
						_buffers[--_index] = array;
					}
				}
				finally
				{
					if (lockTaken)
					{
						_lock.Exit(useMemoryBarrier: false);
					}
				}
			}
		}

		private const int DefaultMaxArrayLength = 1048576;

		private const int DefaultMaxNumberOfArraysPerBucket = 50;

		private static T[] s_emptyArray;

		private readonly Bucket[] _buckets;

		private int Id => GetHashCode();

		internal DefaultArrayPool()
			: this(1048576, 50)
		{
		}

		internal DefaultArrayPool(int maxArrayLength, int maxArraysPerBucket)
		{
			if (maxArrayLength <= 0)
			{
				throw new ArgumentOutOfRangeException("maxArrayLength");
			}
			if (maxArraysPerBucket <= 0)
			{
				throw new ArgumentOutOfRangeException("maxArraysPerBucket");
			}
			if (maxArrayLength > 1073741824)
			{
				maxArrayLength = 1073741824;
			}
			else if (maxArrayLength < 16)
			{
				maxArrayLength = 16;
			}
			int id = Id;
			int num = System.Buffers.Utilities.SelectBucketIndex(maxArrayLength);
			Bucket[] array = new Bucket[num + 1];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = new Bucket(System.Buffers.Utilities.GetMaxSizeForBucket(i), maxArraysPerBucket, id);
			}
			_buckets = array;
		}

		public override T[] Rent(int minimumLength)
		{
			if (minimumLength < 0)
			{
				throw new ArgumentOutOfRangeException("minimumLength");
			}
			if (minimumLength == 0)
			{
				return s_emptyArray ?? (s_emptyArray = new T[0]);
			}
			System.Buffers.ArrayPoolEventSource log = System.Buffers.ArrayPoolEventSource.Log;
			T[] array = null;
			int num = System.Buffers.Utilities.SelectBucketIndex(minimumLength);
			if (num < _buckets.Length)
			{
				int num2 = num;
				do
				{
					array = _buckets[num2].Rent();
					if (array != null)
					{
						if (log.IsEnabled())
						{
							log.BufferRented(array.GetHashCode(), array.Length, Id, _buckets[num2].Id);
						}
						return array;
					}
				}
				while (++num2 < _buckets.Length && num2 != num + 2);
				array = new T[_buckets[num]._bufferLength];
			}
			else
			{
				array = new T[minimumLength];
			}
			if (log.IsEnabled())
			{
				int hashCode = array.GetHashCode();
				int bucketId = -1;
				log.BufferRented(hashCode, array.Length, Id, bucketId);
				log.BufferAllocated(hashCode, array.Length, Id, bucketId, (num >= _buckets.Length) ? System.Buffers.ArrayPoolEventSource.BufferAllocatedReason.OverMaximumSize : System.Buffers.ArrayPoolEventSource.BufferAllocatedReason.PoolExhausted);
			}
			return array;
		}

		public override void Return(T[] array, bool clearArray = false)
		{
			if (array == null)
			{
				throw new ArgumentNullException("array");
			}
			if (array.Length == 0)
			{
				return;
			}
			int num = System.Buffers.Utilities.SelectBucketIndex(array.Length);
			if (num < _buckets.Length)
			{
				if (clearArray)
				{
					Array.Clear(array, 0, array.Length);
				}
				_buckets[num].Return(array);
			}
			System.Buffers.ArrayPoolEventSource log = System.Buffers.ArrayPoolEventSource.Log;
			if (log.IsEnabled())
			{
				log.BufferReturned(array.GetHashCode(), array.Length, Id);
			}
		}
	}
	internal static class Utilities
	{
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static int SelectBucketIndex(int bufferSize)
		{
			uint num = (uint)(bufferSize - 1) >> 4;
			int num2 = 0;
			if (num > 65535)
			{
				num >>= 16;
				num2 = 16;
			}
			if (num > 255)
			{
				num >>= 8;
				num2 += 8;
			}
			if (num > 15)
			{
				num >>= 4;
				num2 += 4;
			}
			if (num > 3)
			{
				num >>= 2;
				num2 += 2;
			}
			if (num > 1)
			{
				num >>= 1;
				num2++;
			}
			return num2 + (int)num;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static int GetMaxSizeForBucket(int binIndex)
		{
			return 16 << binIndex;
		}
	}
}

plugins\System.Memory.dll

Decompiled a year ago
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Buffers.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Numerics;
using System.Numerics.Hashing;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using FxResources.System.Memory;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyTitle("System.Memory")]
[assembly: AssemblyDescription("System.Memory")]
[assembly: AssemblyDefaultAlias("System.Memory")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyFileVersion("4.6.27617.02")]
[assembly: AssemblyInformationalVersion("4.6.27617.02 @BuiltBy: dlab14-DDVSOWINAGE071 @Branch: release/2.1-MSRC @SrcCode: https://github.com/dotnet/corefx/tree/c6cf790234e063b855fcdb50f3fb1b3cfac73275")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.System32 | DllImportSearchPath.AssemblyDirectory)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.1.1")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsByRefLikeAttribute : Attribute
	{
	}
}
namespace FxResources.System.Memory
{
	internal static class SR
	{
	}
}
namespace System
{
	public readonly struct SequencePosition : IEquatable<SequencePosition>
	{
		private readonly object _object;

		private readonly int _integer;

		public SequencePosition(object @object, int integer)
		{
			_object = @object;
			_integer = integer;
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public object GetObject()
		{
			return _object;
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public int GetInteger()
		{
			return _integer;
		}

		public bool Equals(SequencePosition other)
		{
			if (_integer == other._integer)
			{
				return object.Equals(_object, other._object);
			}
			return false;
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public override bool Equals(object obj)
		{
			if (obj is SequencePosition other)
			{
				return Equals(other);
			}
			return false;
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public override int GetHashCode()
		{
			return HashHelpers.Combine(_object?.GetHashCode() ?? 0, _integer);
		}
	}
	internal static class ThrowHelper
	{
		internal static void ThrowArgumentNullException(System.ExceptionArgument argument)
		{
			throw CreateArgumentNullException(argument);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentNullException(System.ExceptionArgument argument)
		{
			return new ArgumentNullException(argument.ToString());
		}

		internal static void ThrowArrayTypeMismatchException()
		{
			throw CreateArrayTypeMismatchException();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArrayTypeMismatchException()
		{
			return new ArrayTypeMismatchException();
		}

		internal static void ThrowArgumentException_InvalidTypeWithPointersNotSupported(Type type)
		{
			throw CreateArgumentException_InvalidTypeWithPointersNotSupported(type);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentException_InvalidTypeWithPointersNotSupported(Type type)
		{
			return new ArgumentException(System.SR.Format(System.SR.Argument_InvalidTypeWithPointersNotSupported, type));
		}

		internal static void ThrowArgumentException_DestinationTooShort()
		{
			throw CreateArgumentException_DestinationTooShort();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentException_DestinationTooShort()
		{
			return new ArgumentException(System.SR.Argument_DestinationTooShort);
		}

		internal static void ThrowIndexOutOfRangeException()
		{
			throw CreateIndexOutOfRangeException();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateIndexOutOfRangeException()
		{
			return new IndexOutOfRangeException();
		}

		internal static void ThrowArgumentOutOfRangeException()
		{
			throw CreateArgumentOutOfRangeException();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentOutOfRangeException()
		{
			return new ArgumentOutOfRangeException();
		}

		internal static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
		{
			throw CreateArgumentOutOfRangeException(argument);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentOutOfRangeException(System.ExceptionArgument argument)
		{
			return new ArgumentOutOfRangeException(argument.ToString());
		}

		internal static void ThrowArgumentOutOfRangeException_PrecisionTooLarge()
		{
			throw CreateArgumentOutOfRangeException_PrecisionTooLarge();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentOutOfRangeException_PrecisionTooLarge()
		{
			return new ArgumentOutOfRangeException("precision", System.SR.Format(System.SR.Argument_PrecisionTooLarge, (byte)99));
		}

		internal static void ThrowArgumentOutOfRangeException_SymbolDoesNotFit()
		{
			throw CreateArgumentOutOfRangeException_SymbolDoesNotFit();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentOutOfRangeException_SymbolDoesNotFit()
		{
			return new ArgumentOutOfRangeException("symbol", System.SR.Argument_BadFormatSpecifier);
		}

		internal static void ThrowInvalidOperationException()
		{
			throw CreateInvalidOperationException();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateInvalidOperationException()
		{
			return new InvalidOperationException();
		}

		internal static void ThrowInvalidOperationException_OutstandingReferences()
		{
			throw CreateInvalidOperationException_OutstandingReferences();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateInvalidOperationException_OutstandingReferences()
		{
			return new InvalidOperationException(System.SR.OutstandingReferences);
		}

		internal static void ThrowInvalidOperationException_UnexpectedSegmentType()
		{
			throw CreateInvalidOperationException_UnexpectedSegmentType();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateInvalidOperationException_UnexpectedSegmentType()
		{
			return new InvalidOperationException(System.SR.UnexpectedSegmentType);
		}

		internal static void ThrowInvalidOperationException_EndPositionNotReached()
		{
			throw CreateInvalidOperationException_EndPositionNotReached();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateInvalidOperationException_EndPositionNotReached()
		{
			return new InvalidOperationException(System.SR.EndPositionNotReached);
		}

		internal static void ThrowArgumentOutOfRangeException_PositionOutOfRange()
		{
			throw CreateArgumentOutOfRangeException_PositionOutOfRange();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentOutOfRangeException_PositionOutOfRange()
		{
			return new ArgumentOutOfRangeException("position");
		}

		internal static void ThrowArgumentOutOfRangeException_OffsetOutOfRange()
		{
			throw CreateArgumentOutOfRangeException_OffsetOutOfRange();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentOutOfRangeException_OffsetOutOfRange()
		{
			return new ArgumentOutOfRangeException("offset");
		}

		internal static void ThrowObjectDisposedException_ArrayMemoryPoolBuffer()
		{
			throw CreateObjectDisposedException_ArrayMemoryPoolBuffer();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateObjectDisposedException_ArrayMemoryPoolBuffer()
		{
			return new ObjectDisposedException("ArrayMemoryPoolBuffer");
		}

		internal static void ThrowFormatException_BadFormatSpecifier()
		{
			throw CreateFormatException_BadFormatSpecifier();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateFormatException_BadFormatSpecifier()
		{
			return new FormatException(System.SR.Argument_BadFormatSpecifier);
		}

		internal static void ThrowArgumentException_OverlapAlignmentMismatch()
		{
			throw CreateArgumentException_OverlapAlignmentMismatch();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateArgumentException_OverlapAlignmentMismatch()
		{
			return new ArgumentException(System.SR.Argument_OverlapAlignmentMismatch);
		}

		internal static void ThrowNotSupportedException()
		{
			throw CreateThrowNotSupportedException();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception CreateThrowNotSupportedException()
		{
			return new NotSupportedException();
		}

		public static bool TryFormatThrowFormatException(out int bytesWritten)
		{
			bytesWritten = 0;
			ThrowFormatException_BadFormatSpecifier();
			return false;
		}

		public static bool TryParseThrowFormatException<T>(out T value, out int bytesConsumed)
		{
			value = default(T);
			bytesConsumed = 0;
			ThrowFormatException_BadFormatSpecifier();
			return false;
		}

		public static void ThrowArgumentValidationException<T>(ReadOnlySequenceSegment<T> startSegment, int startIndex, ReadOnlySequenceSegment<T> endSegment)
		{
			throw CreateArgumentValidationException(startSegment, startIndex, endSegment);
		}

		private static Exception CreateArgumentValidationException<T>(ReadOnlySequenceSegment<T> startSegment, int startIndex, ReadOnlySequenceSegment<T> endSegment)
		{
			if (startSegment == null)
			{
				return CreateArgumentNullException(System.ExceptionArgument.startSegment);
			}
			if (endSegment == null)
			{
				return CreateArgumentNullException(System.ExceptionArgument.endSegment);
			}
			if (startSegment != endSegment && startSegment.RunningIndex > endSegment.RunningIndex)
			{
				return CreateArgumentOutOfRangeException(System.ExceptionArgument.endSegment);
			}
			if ((uint)startSegment.Memory.Length < (uint)startIndex)
			{
				return CreateArgumentOutOfRangeException(System.ExceptionArgument.startIndex);
			}
			return CreateArgumentOutOfRangeException(System.ExceptionArgument.endIndex);
		}

		public static void ThrowArgumentValidationException(Array array, int start)
		{
			throw CreateArgumentValidationException(array, start);
		}

		private static Exception CreateArgumentValidationException(Array array, int start)
		{
			if (array == null)
			{
				return CreateArgumentNullException(System.ExceptionArgument.array);
			}
			if ((uint)start > (uint)array.Length)
			{
				return CreateArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return CreateArgumentOutOfRangeException(System.ExceptionArgument.length);
		}

		public static void ThrowStartOrEndArgumentValidationException(long start)
		{
			throw CreateStartOrEndArgumentValidationException(start);
		}

		private static Exception CreateStartOrEndArgumentValidationException(long start)
		{
			if (start < 0)
			{
				return CreateArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return CreateArgumentOutOfRangeException(System.ExceptionArgument.length);
		}
	}
	internal enum ExceptionArgument
	{
		length,
		start,
		minimumBufferSize,
		elementIndex,
		comparable,
		comparer,
		destination,
		offset,
		startSegment,
		endSegment,
		startIndex,
		endIndex,
		array,
		culture,
		manager
	}
	internal static class DecimalDecCalc
	{
		private static uint D32DivMod1E9(uint hi32, ref uint lo32)
		{
			ulong num = ((ulong)hi32 << 32) | lo32;
			lo32 = (uint)(num / 1000000000);
			return (uint)(num % 1000000000);
		}

		internal static uint DecDivMod1E9(ref MutableDecimal value)
		{
			return D32DivMod1E9(D32DivMod1E9(D32DivMod1E9(0u, ref value.High), ref value.Mid), ref value.Low);
		}

		internal static void DecAddInt32(ref MutableDecimal value, uint i)
		{
			if (D32AddCarry(ref value.Low, i) && D32AddCarry(ref value.Mid, 1u))
			{
				D32AddCarry(ref value.High, 1u);
			}
		}

		private static bool D32AddCarry(ref uint value, uint i)
		{
			uint num = value;
			uint num2 = (value = num + i);
			if (num2 >= num)
			{
				return num2 < i;
			}
			return true;
		}

		internal static void DecMul10(ref MutableDecimal value)
		{
			MutableDecimal d = value;
			DecShiftLeft(ref value);
			DecShiftLeft(ref value);
			DecAdd(ref value, d);
			DecShiftLeft(ref value);
		}

		private static void DecShiftLeft(ref MutableDecimal value)
		{
			uint num = (((value.Low & 0x80000000u) != 0) ? 1u : 0u);
			uint num2 = (((value.Mid & 0x80000000u) != 0) ? 1u : 0u);
			value.Low <<= 1;
			value.Mid = (value.Mid << 1) | num;
			value.High = (value.High << 1) | num2;
		}

		private static void DecAdd(ref MutableDecimal value, MutableDecimal d)
		{
			if (D32AddCarry(ref value.Low, d.Low) && D32AddCarry(ref value.Mid, 1u))
			{
				D32AddCarry(ref value.High, 1u);
			}
			if (D32AddCarry(ref value.Mid, d.Mid))
			{
				D32AddCarry(ref value.High, 1u);
			}
			D32AddCarry(ref value.High, d.High);
		}
	}
	internal static class Number
	{
		private static class DoubleHelper
		{
			public unsafe static uint Exponent(double d)
			{
				return (*(uint*)((byte*)(&d) + 4) >> 20) & 0x7FFu;
			}

			public unsafe static ulong Mantissa(double d)
			{
				return *(uint*)(&d) | ((ulong)(uint)(*(int*)((byte*)(&d) + 4) & 0xFFFFF) << 32);
			}

			public unsafe static bool Sign(double d)
			{
				return *(uint*)((byte*)(&d) + 4) >> 31 != 0;
			}
		}

		internal const int DECIMAL_PRECISION = 29;

		private static readonly ulong[] s_rgval64Power10 = new ulong[30]
		{
			11529215046068469760uL, 14411518807585587200uL, 18014398509481984000uL, 11258999068426240000uL, 14073748835532800000uL, 17592186044416000000uL, 10995116277760000000uL, 13743895347200000000uL, 17179869184000000000uL, 10737418240000000000uL,
			13421772800000000000uL, 16777216000000000000uL, 10485760000000000000uL, 13107200000000000000uL, 16384000000000000000uL, 14757395258967641293uL, 11805916207174113035uL, 9444732965739290428uL, 15111572745182864686uL, 12089258196146291749uL,
			9671406556917033399uL, 15474250491067253438uL, 12379400392853802751uL, 9903520314283042201uL, 15845632502852867522uL, 12676506002282294018uL, 10141204801825835215uL, 16225927682921336344uL, 12980742146337069075uL, 10384593717069655260uL
		};

		private static readonly sbyte[] s_rgexp64Power10 = new sbyte[15]
		{
			4, 7, 10, 14, 17, 20, 24, 27, 30, 34,
			37, 40, 44, 47, 50
		};

		private static readonly ulong[] s_rgval64Power10By16 = new ulong[42]
		{
			10240000000000000000uL, 11368683772161602974uL, 12621774483536188886uL, 14012984643248170708uL, 15557538194652854266uL, 17272337110188889248uL, 9588073174409622172uL, 10644899600020376798uL, 11818212630765741798uL, 13120851772591970216uL,
			14567071740625403792uL, 16172698447808779622uL, 17955302187076837696uL, 9967194951097567532uL, 11065809325636130658uL, 12285516299433008778uL, 13639663065038175358uL, 15143067982934716296uL, 16812182738118149112uL, 9332636185032188787uL,
			10361307573072618722uL, 16615349947311448416uL, 14965776766268445891uL, 13479973333575319909uL, 12141680576410806707uL, 10936253623915059637uL, 9850501549098619819uL, 17745086042373215136uL, 15983352577617880260uL, 14396524142538228461uL,
			12967236152753103031uL, 11679847981112819795uL, 10520271803096747049uL, 9475818434452569218uL, 17070116948172427008uL, 15375394465392026135uL, 13848924157002783096uL, 12474001934591998882uL, 11235582092889474480uL, 10120112665365530972uL,
			18230774251475056952uL, 16420821625123739930uL
		};

		private static readonly short[] s_rgexp64Power10By16 = new short[21]
		{
			54, 107, 160, 213, 266, 319, 373, 426, 479, 532,
			585, 638, 691, 745, 798, 851, 904, 957, 1010, 1064,
			1117
		};

		public static void RoundNumber(ref NumberBuffer number, int pos)
		{
			Span<byte> digits = number.Digits;
			int i;
			for (i = 0; i < pos && digits[i] != 0; i++)
			{
			}
			if (i == pos && digits[i] >= 53)
			{
				while (i > 0 && digits[i - 1] == 57)
				{
					i--;
				}
				if (i > 0)
				{
					digits[i - 1]++;
				}
				else
				{
					number.Scale++;
					digits[0] = 49;
					i = 1;
				}
			}
			else
			{
				while (i > 0 && digits[i - 1] == 48)
				{
					i--;
				}
			}
			if (i == 0)
			{
				number.Scale = 0;
				number.IsNegative = false;
			}
			digits[i] = 0;
		}

		internal static bool NumberBufferToDouble(ref NumberBuffer number, out double value)
		{
			double num = NumberToDouble(ref number);
			uint num2 = DoubleHelper.Exponent(num);
			ulong num3 = DoubleHelper.Mantissa(num);
			switch (num2)
			{
			case 2047u:
				value = 0.0;
				return false;
			case 0u:
				if (num3 == 0L)
				{
					num = 0.0;
				}
				break;
			}
			value = num;
			return true;
		}

		public unsafe static bool NumberBufferToDecimal(ref NumberBuffer number, ref decimal value)
		{
			MutableDecimal source = default(MutableDecimal);
			byte* ptr = number.UnsafeDigits;
			int num = number.Scale;
			if (*ptr == 0)
			{
				if (num > 0)
				{
					num = 0;
				}
			}
			else
			{
				if (num > 29)
				{
					return false;
				}
				while ((num > 0 || (*ptr != 0 && num > -28)) && (source.High < 429496729 || (source.High == 429496729 && (source.Mid < 2576980377u || (source.Mid == 2576980377u && (source.Low < 2576980377u || (source.Low == 2576980377u && *ptr <= 53)))))))
				{
					DecimalDecCalc.DecMul10(ref source);
					if (*ptr != 0)
					{
						DecimalDecCalc.DecAddInt32(ref source, (uint)(*(ptr++) - 48));
					}
					num--;
				}
				if (*(ptr++) >= 53)
				{
					bool flag = true;
					if (*(ptr - 1) == 53 && *(ptr - 2) % 2 == 0)
					{
						int num2 = 20;
						while (*ptr == 48 && num2 != 0)
						{
							ptr++;
							num2--;
						}
						if (*ptr == 0 || num2 == 0)
						{
							flag = false;
						}
					}
					if (flag)
					{
						DecimalDecCalc.DecAddInt32(ref source, 1u);
						if ((source.High | source.Mid | source.Low) == 0)
						{
							source.High = 429496729u;
							source.Mid = 2576980377u;
							source.Low = 2576980378u;
							num++;
						}
					}
				}
			}
			if (num > 0)
			{
				return false;
			}
			if (num <= -29)
			{
				source.High = 0u;
				source.Low = 0u;
				source.Mid = 0u;
				source.Scale = 28;
			}
			else
			{
				source.Scale = -num;
			}
			source.IsNegative = number.IsNegative;
			value = Unsafe.As<MutableDecimal, decimal>(ref source);
			return true;
		}

		public static void DecimalToNumber(decimal value, ref NumberBuffer number)
		{
			ref MutableDecimal reference = ref Unsafe.As<decimal, MutableDecimal>(ref value);
			Span<byte> digits = number.Digits;
			number.IsNegative = reference.IsNegative;
			int num = 29;
			while ((reference.Mid != 0) | (reference.High != 0))
			{
				uint num2 = DecimalDecCalc.DecDivMod1E9(ref reference);
				for (int i = 0; i < 9; i++)
				{
					digits[--num] = (byte)(num2 % 10 + 48);
					num2 /= 10;
				}
			}
			for (uint num3 = reference.Low; num3 != 0; num3 /= 10)
			{
				digits[--num] = (byte)(num3 % 10 + 48);
			}
			int num4 = 29 - num;
			number.Scale = num4 - reference.Scale;
			Span<byte> digits2 = number.Digits;
			int index = 0;
			while (--num4 >= 0)
			{
				digits2[index++] = digits[num++];
			}
			digits2[index] = 0;
		}

		private static uint DigitsToInt(ReadOnlySpan<byte> digits, int count)
		{
			uint value;
			int bytesConsumed;
			bool flag = Utf8Parser.TryParse(digits.Slice(0, count), out value, out bytesConsumed, 'D');
			return value;
		}

		private static ulong Mul32x32To64(uint a, uint b)
		{
			return (ulong)a * (ulong)b;
		}

		private static ulong Mul64Lossy(ulong a, ulong b, ref int pexp)
		{
			ulong num = Mul32x32To64((uint)(a >> 32), (uint)(b >> 32)) + (Mul32x32To64((uint)(a >> 32), (uint)b) >> 32) + (Mul32x32To64((uint)a, (uint)(b >> 32)) >> 32);
			if ((num & 0x8000000000000000uL) == 0L)
			{
				num <<= 1;
				pexp--;
			}
			return num;
		}

		private static int abs(int value)
		{
			if (value < 0)
			{
				return -value;
			}
			return value;
		}

		private unsafe static double NumberToDouble(ref NumberBuffer number)
		{
			ReadOnlySpan<byte> digits = number.Digits;
			int i = 0;
			int numDigits = number.NumDigits;
			int num = numDigits;
			for (; digits[i] == 48; i++)
			{
				num--;
			}
			if (num == 0)
			{
				return 0.0;
			}
			int num2 = Math.Min(num, 9);
			num -= num2;
			ulong num3 = DigitsToInt(digits, num2);
			if (num > 0)
			{
				num2 = Math.Min(num, 9);
				num -= num2;
				uint b = (uint)(s_rgval64Power10[num2 - 1] >> 64 - s_rgexp64Power10[num2 - 1]);
				num3 = Mul32x32To64((uint)num3, b) + DigitsToInt(digits.Slice(9), num2);
			}
			int num4 = number.Scale - (numDigits - num);
			int num5 = abs(num4);
			if (num5 >= 352)
			{
				ulong num6 = ((num4 > 0) ? 9218868437227405312uL : 0);
				if (number.IsNegative)
				{
					num6 |= 0x8000000000000000uL;
				}
				return *(double*)(&num6);
			}
			int pexp = 64;
			if ((num3 & 0xFFFFFFFF00000000uL) == 0L)
			{
				num3 <<= 32;
				pexp -= 32;
			}
			if ((num3 & 0xFFFF000000000000uL) == 0L)
			{
				num3 <<= 16;
				pexp -= 16;
			}
			if ((num3 & 0xFF00000000000000uL) == 0L)
			{
				num3 <<= 8;
				pexp -= 8;
			}
			if ((num3 & 0xF000000000000000uL) == 0L)
			{
				num3 <<= 4;
				pexp -= 4;
			}
			if ((num3 & 0xC000000000000000uL) == 0L)
			{
				num3 <<= 2;
				pexp -= 2;
			}
			if ((num3 & 0x8000000000000000uL) == 0L)
			{
				num3 <<= 1;
				pexp--;
			}
			int num7 = num5 & 0xF;
			if (num7 != 0)
			{
				int num8 = s_rgexp64Power10[num7 - 1];
				pexp += ((num4 < 0) ? (-num8 + 1) : num8);
				ulong b2 = s_rgval64Power10[num7 + ((num4 < 0) ? 15 : 0) - 1];
				num3 = Mul64Lossy(num3, b2, ref pexp);
			}
			num7 = num5 >> 4;
			if (num7 != 0)
			{
				int num9 = s_rgexp64Power10By16[num7 - 1];
				pexp += ((num4 < 0) ? (-num9 + 1) : num9);
				ulong b3 = s_rgval64Power10By16[num7 + ((num4 < 0) ? 21 : 0) - 1];
				num3 = Mul64Lossy(num3, b3, ref pexp);
			}
			if (((uint)(int)num3 & 0x400u) != 0)
			{
				ulong num10 = num3 + 1023 + (ulong)(((int)num3 >> 11) & 1);
				if (num10 < num3)
				{
					num10 = (num10 >> 1) | 0x8000000000000000uL;
					pexp++;
				}
				num3 = num10;
			}
			pexp += 1022;
			num3 = ((pexp <= 0) ? ((pexp == -52 && num3 >= 9223372036854775896uL) ? 1 : ((pexp > -52) ? (num3 >> -pexp + 11 + 1) : 0)) : ((pexp < 2047) ? ((ulong)((long)pexp << 52) + ((num3 >> 11) & 0xFFFFFFFFFFFFFL)) : 9218868437227405312uL));
			if (number.IsNegative)
			{
				num3 |= 0x8000000000000000uL;
			}
			return *(double*)(&num3);
		}
	}
	internal ref struct NumberBuffer
	{
		public int Scale;

		public bool IsNegative;

		public const int BufferSize = 51;

		private byte _b0;

		private byte _b1;

		private byte _b2;

		private byte _b3;

		private byte _b4;

		private byte _b5;

		private byte _b6;

		private byte _b7;

		private byte _b8;

		private byte _b9;

		private byte _b10;

		private byte _b11;

		private byte _b12;

		private byte _b13;

		private byte _b14;

		private byte _b15;

		private byte _b16;

		private byte _b17;

		private byte _b18;

		private byte _b19;

		private byte _b20;

		private byte _b21;

		private byte _b22;

		private byte _b23;

		private byte _b24;

		private byte _b25;

		private byte _b26;

		private byte _b27;

		private byte _b28;

		private byte _b29;

		private byte _b30;

		private byte _b31;

		private byte _b32;

		private byte _b33;

		private byte _b34;

		private byte _b35;

		private byte _b36;

		private byte _b37;

		private byte _b38;

		private byte _b39;

		private byte _b40;

		private byte _b41;

		private byte _b42;

		private byte _b43;

		private byte _b44;

		private byte _b45;

		private byte _b46;

		private byte _b47;

		private byte _b48;

		private byte _b49;

		private byte _b50;

		public unsafe Span<byte> Digits => new Span<byte>(Unsafe.AsPointer(ref _b0), 51);

		public unsafe byte* UnsafeDigits => (byte*)Unsafe.AsPointer(ref _b0);

		public int NumDigits => Digits.IndexOf<byte>(0);

		[Conditional("DEBUG")]
		public void CheckConsistency()
		{
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append('[');
			stringBuilder.Append('"');
			Span<byte> digits = Digits;
			for (int i = 0; i < 51; i++)
			{
				byte b = digits[i];
				if (b == 0)
				{
					break;
				}
				stringBuilder.Append((char)b);
			}
			stringBuilder.Append('"');
			stringBuilder.Append(", Scale = " + Scale);
			stringBuilder.Append(", IsNegative   = " + IsNegative);
			stringBuilder.Append(']');
			return stringBuilder.ToString();
		}
	}
	[DebuggerTypeProxy(typeof(System.MemoryDebugView<>))]
	[DebuggerDisplay("{ToString(),raw}")]
	public readonly struct Memory<T>
	{
		private readonly object _object;

		private readonly int _index;

		private readonly int _length;

		private const int RemoveFlagsBitMask = int.MaxValue;

		public static Memory<T> Empty => default(Memory<T>);

		public int Length => _length & 0x7FFFFFFF;

		public bool IsEmpty => (_length & 0x7FFFFFFF) == 0;

		public Span<T> Span
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				Span<T> result;
				if (_index < 0)
				{
					result = ((MemoryManager<T>)_object).GetSpan();
					return result.Slice(_index & 0x7FFFFFFF, _length);
				}
				if (typeof(T) == typeof(char) && _object is string text)
				{
					result = new Span<T>(Unsafe.As<Pinnable<T>>(text), MemoryExtensions.StringAdjustment, text.Length);
					return result.Slice(_index, _length);
				}
				if (_object != null)
				{
					return new Span<T>((T[])_object, _index, _length & 0x7FFFFFFF);
				}
				result = default(Span<T>);
				return result;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Memory(T[] array)
		{
			if (array == null)
			{
				this = default(Memory<T>);
				return;
			}
			if (default(T) == null && array.GetType() != typeof(T[]))
			{
				System.ThrowHelper.ThrowArrayTypeMismatchException();
			}
			_object = array;
			_index = 0;
			_length = array.Length;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal Memory(T[] array, int start)
		{
			if (array == null)
			{
				if (start != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException();
				}
				this = default(Memory<T>);
				return;
			}
			if (default(T) == null && array.GetType() != typeof(T[]))
			{
				System.ThrowHelper.ThrowArrayTypeMismatchException();
			}
			if ((uint)start > (uint)array.Length)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException();
			}
			_object = array;
			_index = start;
			_length = array.Length - start;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Memory(T[] array, int start, int length)
		{
			if (array == null)
			{
				if (start != 0 || length != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException();
				}
				this = default(Memory<T>);
				return;
			}
			if (default(T) == null && array.GetType() != typeof(T[]))
			{
				System.ThrowHelper.ThrowArrayTypeMismatchException();
			}
			if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException();
			}
			_object = array;
			_index = start;
			_length = length;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal Memory(MemoryManager<T> manager, int length)
		{
			if (length < 0)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException();
			}
			_object = manager;
			_index = int.MinValue;
			_length = length;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal Memory(MemoryManager<T> manager, int start, int length)
		{
			if (length < 0 || start < 0)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException();
			}
			_object = manager;
			_index = start | int.MinValue;
			_length = length;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal Memory(object obj, int start, int length)
		{
			_object = obj;
			_index = start;
			_length = length;
		}

		public static implicit operator Memory<T>(T[] array)
		{
			return new Memory<T>(array);
		}

		public static implicit operator Memory<T>(ArraySegment<T> segment)
		{
			return new Memory<T>(segment.Array, segment.Offset, segment.Count);
		}

		public static implicit operator ReadOnlyMemory<T>(Memory<T> memory)
		{
			return Unsafe.As<Memory<T>, ReadOnlyMemory<T>>(ref memory);
		}

		public override string ToString()
		{
			if (typeof(T) == typeof(char))
			{
				if (!(_object is string text))
				{
					return Span.ToString();
				}
				return text.Substring(_index, _length & 0x7FFFFFFF);
			}
			return $"System.Memory<{typeof(T).Name}>[{_length & 0x7FFFFFFF}]";
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Memory<T> Slice(int start)
		{
			int length = _length;
			int num = length & 0x7FFFFFFF;
			if ((uint)start > (uint)num)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new Memory<T>(_object, _index + start, length - start);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Memory<T> Slice(int start, int length)
		{
			int length2 = _length;
			int num = length2 & 0x7FFFFFFF;
			if ((uint)start > (uint)num || (uint)length > (uint)(num - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException();
			}
			return new Memory<T>(_object, _index + start, length | (length2 & int.MinValue));
		}

		public void CopyTo(Memory<T> destination)
		{
			Span.CopyTo(destination.Span);
		}

		public bool TryCopyTo(Memory<T> destination)
		{
			return Span.TryCopyTo(destination.Span);
		}

		public unsafe MemoryHandle Pin()
		{
			if (_index < 0)
			{
				return ((MemoryManager<T>)_object).Pin(_index & 0x7FFFFFFF);
			}
			if (typeof(T) == typeof(char) && _object is string value)
			{
				GCHandle handle = GCHandle.Alloc(value, GCHandleType.Pinned);
				void* pointer = Unsafe.Add<T>((void*)handle.AddrOfPinnedObject(), _index);
				return new MemoryHandle(pointer, handle);
			}
			if (_object is T[] array)
			{
				if (_length < 0)
				{
					void* pointer2 = Unsafe.Add<T>(Unsafe.AsPointer(ref MemoryMarshal.GetReference<T>(array)), _index);
					return new MemoryHandle(pointer2);
				}
				GCHandle handle2 = GCHandle.Alloc(array, GCHandleType.Pinned);
				void* pointer3 = Unsafe.Add<T>((void*)handle2.AddrOfPinnedObject(), _index);
				return new MemoryHandle(pointer3, handle2);
			}
			return default(MemoryHandle);
		}

		public T[] ToArray()
		{
			return Span.ToArray();
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public override bool Equals(object obj)
		{
			if (obj is ReadOnlyMemory<T> readOnlyMemory)
			{
				return readOnlyMemory.Equals(this);
			}
			if (obj is Memory<T> other)
			{
				return Equals(other);
			}
			return false;
		}

		public bool Equals(Memory<T> other)
		{
			if (_object == other._object && _index == other._index)
			{
				return _length == other._length;
			}
			return false;
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public override int GetHashCode()
		{
			if (_object == null)
			{
				return 0;
			}
			int hashCode = _object.GetHashCode();
			int index = _index;
			int hashCode2 = index.GetHashCode();
			index = _length;
			return CombineHashCodes(hashCode, hashCode2, index.GetHashCode());
		}

		private static int CombineHashCodes(int left, int right)
		{
			return ((left << 5) + left) ^ right;
		}

		private static int CombineHashCodes(int h1, int h2, int h3)
		{
			return CombineHashCodes(CombineHashCodes(h1, h2), h3);
		}
	}
	internal sealed class MemoryDebugView<T>
	{
		private readonly ReadOnlyMemory<T> _memory;

		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
		public T[] Items => _memory.ToArray();

		public MemoryDebugView(Memory<T> memory)
		{
			_memory = memory;
		}

		public MemoryDebugView(ReadOnlyMemory<T> memory)
		{
			_memory = memory;
		}
	}
	public static class MemoryExtensions
	{
		internal static readonly IntPtr StringAdjustment = MeasureStringAdjustment();

		public static ReadOnlySpan<char> Trim(this ReadOnlySpan<char> span)
		{
			return span.TrimStart().TrimEnd();
		}

		public static ReadOnlySpan<char> TrimStart(this ReadOnlySpan<char> span)
		{
			int i;
			for (i = 0; i < span.Length && char.IsWhiteSpace(span[i]); i++)
			{
			}
			return span.Slice(i);
		}

		public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> span)
		{
			int num = span.Length - 1;
			while (num >= 0 && char.IsWhiteSpace(span[num]))
			{
				num--;
			}
			return span.Slice(0, num + 1);
		}

		public static ReadOnlySpan<char> Trim(this ReadOnlySpan<char> span, char trimChar)
		{
			return span.TrimStart(trimChar).TrimEnd(trimChar);
		}

		public static ReadOnlySpan<char> TrimStart(this ReadOnlySpan<char> span, char trimChar)
		{
			int i;
			for (i = 0; i < span.Length && span[i] == trimChar; i++)
			{
			}
			return span.Slice(i);
		}

		public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> span, char trimChar)
		{
			int num = span.Length - 1;
			while (num >= 0 && span[num] == trimChar)
			{
				num--;
			}
			return span.Slice(0, num + 1);
		}

		public static ReadOnlySpan<char> Trim(this ReadOnlySpan<char> span, ReadOnlySpan<char> trimChars)
		{
			return span.TrimStart(trimChars).TrimEnd(trimChars);
		}

		public static ReadOnlySpan<char> TrimStart(this ReadOnlySpan<char> span, ReadOnlySpan<char> trimChars)
		{
			if (trimChars.IsEmpty)
			{
				return span.TrimStart();
			}
			int i;
			for (i = 0; i < span.Length; i++)
			{
				int num = 0;
				while (num < trimChars.Length)
				{
					if (span[i] != trimChars[num])
					{
						num++;
						continue;
					}
					goto IL_003c;
				}
				break;
				IL_003c:;
			}
			return span.Slice(i);
		}

		public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> span, ReadOnlySpan<char> trimChars)
		{
			if (trimChars.IsEmpty)
			{
				return span.TrimEnd();
			}
			int num;
			for (num = span.Length - 1; num >= 0; num--)
			{
				int num2 = 0;
				while (num2 < trimChars.Length)
				{
					if (span[num] != trimChars[num2])
					{
						num2++;
						continue;
					}
					goto IL_0044;
				}
				break;
				IL_0044:;
			}
			return span.Slice(0, num + 1);
		}

		public static bool IsWhiteSpace(this ReadOnlySpan<char> span)
		{
			for (int i = 0; i < span.Length; i++)
			{
				if (!char.IsWhiteSpace(span[i]))
				{
					return false;
				}
			}
			return true;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOf<T>(this Span<T> span, T value) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOf(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value), span.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.IndexOf(ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, char>(ref value), span.Length);
			}
			return System.SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), value, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOf<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOf(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), value.Length);
			}
			return System.SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOf<T>(this Span<T> span, T value) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOf(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value), span.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.LastIndexOf(ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, char>(ref value), span.Length);
			}
			return System.SpanHelpers.LastIndexOf(ref MemoryMarshal.GetReference(span), value, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOf<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOf(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), value.Length);
			}
			return System.SpanHelpers.LastIndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool SequenceEqual<T>(this Span<T> span, ReadOnlySpan<T> other) where T : IEquatable<T>
		{
			int length = span.Length;
			if (default(T) != null && IsTypeComparableAsBytes<T>(out var size))
			{
				if (length == other.Length)
				{
					return System.SpanHelpers.SequenceEqual(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)), (NUInt)length * size);
				}
				return false;
			}
			if (length == other.Length)
			{
				return System.SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other), length);
			}
			return false;
		}

		public static int SequenceCompareTo<T>(this Span<T> span, ReadOnlySpan<T> other) where T : IComparable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.SequenceCompareTo(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)), other.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.SequenceCompareTo(ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(other)), other.Length);
			}
			return System.SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(other), other.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOf<T>(this ReadOnlySpan<T> span, T value) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOf(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value), span.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.IndexOf(ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, char>(ref value), span.Length);
			}
			return System.SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), value, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOf<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOf(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), value.Length);
			}
			return System.SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOf<T>(this ReadOnlySpan<T> span, T value) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOf(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value), span.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.LastIndexOf(ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, char>(ref value), span.Length);
			}
			return System.SpanHelpers.LastIndexOf(ref MemoryMarshal.GetReference(span), value, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOf<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOf(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), value.Length);
			}
			return System.SpanHelpers.LastIndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOfAny<T>(this Span<T> span, T value0, T value1) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value0), Unsafe.As<T, byte>(ref value1), span.Length);
			}
			return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOfAny<T>(this Span<T> span, T value0, T value1, T value2) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value0), Unsafe.As<T, byte>(ref value1), Unsafe.As<T, byte>(ref value2), span.Length);
			}
			return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOfAny<T>(this Span<T> span, ReadOnlySpan<T> values) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)), values.Length);
			}
			return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value0), Unsafe.As<T, byte>(ref value1), span.Length);
			}
			return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1, T value2) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value0), Unsafe.As<T, byte>(ref value1), Unsafe.As<T, byte>(ref value2), span.Length);
			}
			return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int IndexOfAny<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> values) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.IndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)), values.Length);
			}
			return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOfAny<T>(this Span<T> span, T value0, T value1) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value0), Unsafe.As<T, byte>(ref value1), span.Length);
			}
			return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOfAny<T>(this Span<T> span, T value0, T value1, T value2) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value0), Unsafe.As<T, byte>(ref value1), Unsafe.As<T, byte>(ref value2), span.Length);
			}
			return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOfAny<T>(this Span<T> span, ReadOnlySpan<T> values) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)), values.Length);
			}
			return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value0), Unsafe.As<T, byte>(ref value1), span.Length);
			}
			return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1, T value2) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), Unsafe.As<T, byte>(ref value0), Unsafe.As<T, byte>(ref value1), Unsafe.As<T, byte>(ref value2), span.Length);
			}
			return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> values) where T : IEquatable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)), values.Length);
			}
			return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool SequenceEqual<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other) where T : IEquatable<T>
		{
			int length = span.Length;
			if (default(T) != null && IsTypeComparableAsBytes<T>(out var size))
			{
				if (length == other.Length)
				{
					return System.SpanHelpers.SequenceEqual(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)), (NUInt)length * size);
				}
				return false;
			}
			if (length == other.Length)
			{
				return System.SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other), length);
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int SequenceCompareTo<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other) where T : IComparable<T>
		{
			if (typeof(T) == typeof(byte))
			{
				return System.SpanHelpers.SequenceCompareTo(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)), other.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.SequenceCompareTo(ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(other)), other.Length);
			}
			return System.SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(other), other.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool StartsWith<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
		{
			int length = value.Length;
			if (default(T) != null && IsTypeComparableAsBytes<T>(out var size))
			{
				if (length <= span.Length)
				{
					return System.SpanHelpers.SequenceEqual(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), (NUInt)length * size);
				}
				return false;
			}
			if (length <= span.Length)
			{
				return System.SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), length);
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool StartsWith<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
		{
			int length = value.Length;
			if (default(T) != null && IsTypeComparableAsBytes<T>(out var size))
			{
				if (length <= span.Length)
				{
					return System.SpanHelpers.SequenceEqual(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), (NUInt)length * size);
				}
				return false;
			}
			if (length <= span.Length)
			{
				return System.SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), length);
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool EndsWith<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
		{
			int length = span.Length;
			int length2 = value.Length;
			if (default(T) != null && IsTypeComparableAsBytes<T>(out var size))
			{
				if (length2 <= length)
				{
					return System.SpanHelpers.SequenceEqual(ref Unsafe.As<T, byte>(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), length - length2)), ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), (NUInt)length2 * size);
				}
				return false;
			}
			if (length2 <= length)
			{
				return System.SpanHelpers.SequenceEqual(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), length - length2), ref MemoryMarshal.GetReference(value), length2);
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool EndsWith<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
		{
			int length = span.Length;
			int length2 = value.Length;
			if (default(T) != null && IsTypeComparableAsBytes<T>(out var size))
			{
				if (length2 <= length)
				{
					return System.SpanHelpers.SequenceEqual(ref Unsafe.As<T, byte>(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), length - length2)), ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), (NUInt)length2 * size);
				}
				return false;
			}
			if (length2 <= length)
			{
				return System.SpanHelpers.SequenceEqual(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), length - length2), ref MemoryMarshal.GetReference(value), length2);
			}
			return false;
		}

		public static void Reverse<T>(this Span<T> span)
		{
			ref T reference = ref MemoryMarshal.GetReference(span);
			int num = 0;
			int num2 = span.Length - 1;
			while (num < num2)
			{
				T val = Unsafe.Add(ref reference, num);
				Unsafe.Add(ref reference, num) = Unsafe.Add(ref reference, num2);
				Unsafe.Add(ref reference, num2) = val;
				num++;
				num2--;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Span<T> AsSpan<T>(this T[] array)
		{
			return new Span<T>(array);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Span<T> AsSpan<T>(this T[] array, int start, int length)
		{
			return new Span<T>(array, start, length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Span<T> AsSpan<T>(this ArraySegment<T> segment)
		{
			return new Span<T>(segment.Array, segment.Offset, segment.Count);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Span<T> AsSpan<T>(this ArraySegment<T> segment, int start)
		{
			if ((uint)start > segment.Count)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new Span<T>(segment.Array, segment.Offset + start, segment.Count - start);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Span<T> AsSpan<T>(this ArraySegment<T> segment, int start, int length)
		{
			if ((uint)start > segment.Count)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			if ((uint)length > segment.Count - start)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.length);
			}
			return new Span<T>(segment.Array, segment.Offset + start, length);
		}

		public static Memory<T> AsMemory<T>(this T[] array)
		{
			return new Memory<T>(array);
		}

		public static Memory<T> AsMemory<T>(this T[] array, int start)
		{
			return new Memory<T>(array, start);
		}

		public static Memory<T> AsMemory<T>(this T[] array, int start, int length)
		{
			return new Memory<T>(array, start, length);
		}

		public static Memory<T> AsMemory<T>(this ArraySegment<T> segment)
		{
			return new Memory<T>(segment.Array, segment.Offset, segment.Count);
		}

		public static Memory<T> AsMemory<T>(this ArraySegment<T> segment, int start)
		{
			if ((uint)start > segment.Count)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new Memory<T>(segment.Array, segment.Offset + start, segment.Count - start);
		}

		public static Memory<T> AsMemory<T>(this ArraySegment<T> segment, int start, int length)
		{
			if ((uint)start > segment.Count)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			if ((uint)length > segment.Count - start)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.length);
			}
			return new Memory<T>(segment.Array, segment.Offset + start, length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void CopyTo<T>(this T[] source, Span<T> destination)
		{
			new ReadOnlySpan<T>(source).CopyTo(destination);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void CopyTo<T>(this T[] source, Memory<T> destination)
		{
			source.CopyTo(destination.Span);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool Overlaps<T>(this Span<T> span, ReadOnlySpan<T> other)
		{
			return ((ReadOnlySpan<T>)span).Overlaps(other);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool Overlaps<T>(this Span<T> span, ReadOnlySpan<T> other, out int elementOffset)
		{
			return ((ReadOnlySpan<T>)span).Overlaps(other, out elementOffset);
		}

		public static bool Overlaps<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other)
		{
			if (span.IsEmpty || other.IsEmpty)
			{
				return false;
			}
			IntPtr intPtr = Unsafe.ByteOffset(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other));
			if (Unsafe.SizeOf<IntPtr>() == 4)
			{
				if ((uint)(int)intPtr >= (uint)(span.Length * Unsafe.SizeOf<T>()))
				{
					return (uint)(int)intPtr > (uint)(-(other.Length * Unsafe.SizeOf<T>()));
				}
				return true;
			}
			if ((ulong)(long)intPtr >= (ulong)((long)span.Length * (long)Unsafe.SizeOf<T>()))
			{
				return (ulong)(long)intPtr > (ulong)(-((long)other.Length * (long)Unsafe.SizeOf<T>()));
			}
			return true;
		}

		public static bool Overlaps<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other, out int elementOffset)
		{
			if (span.IsEmpty || other.IsEmpty)
			{
				elementOffset = 0;
				return false;
			}
			IntPtr intPtr = Unsafe.ByteOffset(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other));
			if (Unsafe.SizeOf<IntPtr>() == 4)
			{
				if ((uint)(int)intPtr < (uint)(span.Length * Unsafe.SizeOf<T>()) || (uint)(int)intPtr > (uint)(-(other.Length * Unsafe.SizeOf<T>())))
				{
					if ((int)intPtr % Unsafe.SizeOf<T>() != 0)
					{
						System.ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch();
					}
					elementOffset = (int)intPtr / Unsafe.SizeOf<T>();
					return true;
				}
				elementOffset = 0;
				return false;
			}
			if ((ulong)(long)intPtr < (ulong)((long)span.Length * (long)Unsafe.SizeOf<T>()) || (ulong)(long)intPtr > (ulong)(-((long)other.Length * (long)Unsafe.SizeOf<T>())))
			{
				if ((long)intPtr % Unsafe.SizeOf<T>() != 0L)
				{
					System.ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch();
				}
				elementOffset = (int)((long)intPtr / Unsafe.SizeOf<T>());
				return true;
			}
			elementOffset = 0;
			return false;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int BinarySearch<T>(this Span<T> span, IComparable<T> comparable)
		{
			return span.BinarySearch<T, IComparable<T>>(comparable);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int BinarySearch<T, TComparable>(this Span<T> span, TComparable comparable) where TComparable : IComparable<T>
		{
			return BinarySearch((ReadOnlySpan<T>)span, comparable);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int BinarySearch<T, TComparer>(this Span<T> span, T value, TComparer comparer) where TComparer : IComparer<T>
		{
			return ((ReadOnlySpan<T>)span).BinarySearch(value, comparer);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int BinarySearch<T>(this ReadOnlySpan<T> span, IComparable<T> comparable)
		{
			return MemoryExtensions.BinarySearch<T, IComparable<T>>(span, comparable);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int BinarySearch<T, TComparable>(this ReadOnlySpan<T> span, TComparable comparable) where TComparable : IComparable<T>
		{
			return System.SpanHelpers.BinarySearch(span, comparable);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int BinarySearch<T, TComparer>(this ReadOnlySpan<T> span, T value, TComparer comparer) where TComparer : IComparer<T>
		{
			if (comparer == null)
			{
				System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.comparer);
			}
			System.SpanHelpers.ComparerComparable<T, TComparer> comparable = new System.SpanHelpers.ComparerComparable<T, TComparer>(value, comparer);
			return BinarySearch(span, comparable);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static bool IsTypeComparableAsBytes<T>(out NUInt size)
		{
			if (typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte))
			{
				size = (NUInt)1;
				return true;
			}
			if (typeof(T) == typeof(char) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort))
			{
				size = (NUInt)2;
				return true;
			}
			if (typeof(T) == typeof(int) || typeof(T) == typeof(uint))
			{
				size = (NUInt)4;
				return true;
			}
			if (typeof(T) == typeof(long) || typeof(T) == typeof(ulong))
			{
				size = (NUInt)8;
				return true;
			}
			size = default(NUInt);
			return false;
		}

		public static Span<T> AsSpan<T>(this T[] array, int start)
		{
			return Span<T>.Create(array, start);
		}

		public static bool Contains(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
		{
			return span.IndexOf(value, comparisonType) >= 0;
		}

		public static bool Equals(this ReadOnlySpan<char> span, ReadOnlySpan<char> other, StringComparison comparisonType)
		{
			switch (comparisonType)
			{
			case StringComparison.Ordinal:
				return span.SequenceEqual(other);
			case StringComparison.OrdinalIgnoreCase:
				if (span.Length != other.Length)
				{
					return false;
				}
				return EqualsOrdinalIgnoreCase(span, other);
			default:
				return span.ToString().Equals(other.ToString(), comparisonType);
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static bool EqualsOrdinalIgnoreCase(ReadOnlySpan<char> span, ReadOnlySpan<char> other)
		{
			if (other.Length == 0)
			{
				return true;
			}
			return CompareToOrdinalIgnoreCase(span, other) == 0;
		}

		public static int CompareTo(this ReadOnlySpan<char> span, ReadOnlySpan<char> other, StringComparison comparisonType)
		{
			return comparisonType switch
			{
				StringComparison.Ordinal => span.SequenceCompareTo(other), 
				StringComparison.OrdinalIgnoreCase => CompareToOrdinalIgnoreCase(span, other), 
				_ => string.Compare(span.ToString(), other.ToString(), comparisonType), 
			};
		}

		private unsafe static int CompareToOrdinalIgnoreCase(ReadOnlySpan<char> strA, ReadOnlySpan<char> strB)
		{
			int num = Math.Min(strA.Length, strB.Length);
			int num2 = num;
			fixed (char* ptr = &MemoryMarshal.GetReference(strA))
			{
				fixed (char* ptr3 = &MemoryMarshal.GetReference(strB))
				{
					char* ptr2 = ptr;
					char* ptr4 = ptr3;
					while (num != 0 && *ptr2 <= '\u007f' && *ptr4 <= '\u007f')
					{
						int num3 = *ptr2;
						int num4 = *ptr4;
						if (num3 == num4)
						{
							ptr2++;
							ptr4++;
							num--;
							continue;
						}
						if ((uint)(num3 - 97) <= 25u)
						{
							num3 -= 32;
						}
						if ((uint)(num4 - 97) <= 25u)
						{
							num4 -= 32;
						}
						if (num3 != num4)
						{
							return num3 - num4;
						}
						ptr2++;
						ptr4++;
						num--;
					}
					if (num == 0)
					{
						return strA.Length - strB.Length;
					}
					num2 -= num;
					return string.Compare(strA.Slice(num2).ToString(), strB.Slice(num2).ToString(), StringComparison.OrdinalIgnoreCase);
				}
			}
		}

		public static int IndexOf(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
		{
			if (comparisonType == StringComparison.Ordinal)
			{
				return span.IndexOf(value);
			}
			return span.ToString().IndexOf(value.ToString(), comparisonType);
		}

		public static int ToLower(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo culture)
		{
			if (culture == null)
			{
				System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.culture);
			}
			if (destination.Length < source.Length)
			{
				return -1;
			}
			string text = source.ToString();
			string text2 = text.ToLower(culture);
			AsSpan(text2).CopyTo(destination);
			return source.Length;
		}

		public static int ToLowerInvariant(this ReadOnlySpan<char> source, Span<char> destination)
		{
			return source.ToLower(destination, CultureInfo.InvariantCulture);
		}

		public static int ToUpper(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo culture)
		{
			if (culture == null)
			{
				System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.culture);
			}
			if (destination.Length < source.Length)
			{
				return -1;
			}
			string text = source.ToString();
			string text2 = text.ToUpper(culture);
			AsSpan(text2).CopyTo(destination);
			return source.Length;
		}

		public static int ToUpperInvariant(this ReadOnlySpan<char> source, Span<char> destination)
		{
			return source.ToUpper(destination, CultureInfo.InvariantCulture);
		}

		public static bool EndsWith(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
		{
			switch (comparisonType)
			{
			case StringComparison.Ordinal:
				return span.EndsWith(value);
			case StringComparison.OrdinalIgnoreCase:
				if (value.Length <= span.Length)
				{
					return EqualsOrdinalIgnoreCase(span.Slice(span.Length - value.Length), value);
				}
				return false;
			default:
			{
				string text = span.ToString();
				string value2 = value.ToString();
				return text.EndsWith(value2, comparisonType);
			}
			}
		}

		public static bool StartsWith(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
		{
			switch (comparisonType)
			{
			case StringComparison.Ordinal:
				return span.StartsWith(value);
			case StringComparison.OrdinalIgnoreCase:
				if (value.Length <= span.Length)
				{
					return EqualsOrdinalIgnoreCase(span.Slice(0, value.Length), value);
				}
				return false;
			default:
			{
				string text = span.ToString();
				string value2 = value.ToString();
				return text.StartsWith(value2, comparisonType);
			}
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ReadOnlySpan<char> AsSpan(this string text)
		{
			if (text == null)
			{
				return default(ReadOnlySpan<char>);
			}
			return new ReadOnlySpan<char>(Unsafe.As<Pinnable<char>>(text), StringAdjustment, text.Length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ReadOnlySpan<char> AsSpan(this string text, int start)
		{
			if (text == null)
			{
				if (start != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
				}
				return default(ReadOnlySpan<char>);
			}
			if ((uint)start > (uint)text.Length)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new ReadOnlySpan<char>(Unsafe.As<Pinnable<char>>(text), StringAdjustment + start * 2, text.Length - start);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ReadOnlySpan<char> AsSpan(this string text, int start, int length)
		{
			if (text == null)
			{
				if (start != 0 || length != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
				}
				return default(ReadOnlySpan<char>);
			}
			if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new ReadOnlySpan<char>(Unsafe.As<Pinnable<char>>(text), StringAdjustment + start * 2, length);
		}

		public static ReadOnlyMemory<char> AsMemory(this string text)
		{
			if (text == null)
			{
				return default(ReadOnlyMemory<char>);
			}
			return new ReadOnlyMemory<char>(text, 0, text.Length);
		}

		public static ReadOnlyMemory<char> AsMemory(this string text, int start)
		{
			if (text == null)
			{
				if (start != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
				}
				return default(ReadOnlyMemory<char>);
			}
			if ((uint)start > (uint)text.Length)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new ReadOnlyMemory<char>(text, start, text.Length - start);
		}

		public static ReadOnlyMemory<char> AsMemory(this string text, int start, int length)
		{
			if (text == null)
			{
				if (start != 0 || length != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
				}
				return default(ReadOnlyMemory<char>);
			}
			if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new ReadOnlyMemory<char>(text, start, length);
		}

		private unsafe static IntPtr MeasureStringAdjustment()
		{
			string text = "a";
			fixed (char* source = text)
			{
				return Unsafe.ByteOffset(ref Unsafe.As<Pinnable<char>>(text).Data, ref Unsafe.AsRef<char>(source));
			}
		}
	}
	[DebuggerTypeProxy(typeof(System.MemoryDebugView<>))]
	[DebuggerDisplay("{ToString(),raw}")]
	public readonly struct ReadOnlyMemory<T>
	{
		private readonly object _object;

		private readonly int _index;

		private readonly int _length;

		internal const int RemoveFlagsBitMask = int.MaxValue;

		public static ReadOnlyMemory<T> Empty => default(ReadOnlyMemory<T>);

		public int Length => _length & 0x7FFFFFFF;

		public bool IsEmpty => (_length & 0x7FFFFFFF) == 0;

		public ReadOnlySpan<T> Span
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				if (_index < 0)
				{
					return ((MemoryManager<T>)_object).GetSpan().Slice(_index & 0x7FFFFFFF, _length);
				}
				ReadOnlySpan<T> result;
				if (typeof(T) == typeof(char) && _object is string text)
				{
					result = new ReadOnlySpan<T>(Unsafe.As<Pinnable<T>>(text), MemoryExtensions.StringAdjustment, text.Length);
					return result.Slice(_index, _length);
				}
				if (_object != null)
				{
					return new ReadOnlySpan<T>((T[])_object, _index, _length & 0x7FFFFFFF);
				}
				result = default(ReadOnlySpan<T>);
				return result;
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ReadOnlyMemory(T[] array)
		{
			if (array == null)
			{
				this = default(ReadOnlyMemory<T>);
				return;
			}
			_object = array;
			_index = 0;
			_length = array.Length;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ReadOnlyMemory(T[] array, int start, int length)
		{
			if (array == null)
			{
				if (start != 0 || length != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException();
				}
				this = default(ReadOnlyMemory<T>);
				return;
			}
			if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException();
			}
			_object = array;
			_index = start;
			_length = length;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal ReadOnlyMemory(object obj, int start, int length)
		{
			_object = obj;
			_index = start;
			_length = length;
		}

		public static implicit operator ReadOnlyMemory<T>(T[] array)
		{
			return new ReadOnlyMemory<T>(array);
		}

		public static implicit operator ReadOnlyMemory<T>(ArraySegment<T> segment)
		{
			return new ReadOnlyMemory<T>(segment.Array, segment.Offset, segment.Count);
		}

		public override string ToString()
		{
			if (typeof(T) == typeof(char))
			{
				if (!(_object is string text))
				{
					return Span.ToString();
				}
				return text.Substring(_index, _length & 0x7FFFFFFF);
			}
			return $"System.ReadOnlyMemory<{typeof(T).Name}>[{_length & 0x7FFFFFFF}]";
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ReadOnlyMemory<T> Slice(int start)
		{
			int length = _length;
			int num = length & 0x7FFFFFFF;
			if ((uint)start > (uint)num)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new ReadOnlyMemory<T>(_object, _index + start, length - start);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ReadOnlyMemory<T> Slice(int start, int length)
		{
			int length2 = _length;
			int num = _length & 0x7FFFFFFF;
			if ((uint)start > (uint)num || (uint)length > (uint)(num - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			return new ReadOnlyMemory<T>(_object, _index + start, length | (length2 & int.MinValue));
		}

		public void CopyTo(Memory<T> destination)
		{
			Span.CopyTo(destination.Span);
		}

		public bool TryCopyTo(Memory<T> destination)
		{
			return Span.TryCopyTo(destination.Span);
		}

		public unsafe MemoryHandle Pin()
		{
			if (_index < 0)
			{
				return ((MemoryManager<T>)_object).Pin(_index & 0x7FFFFFFF);
			}
			if (typeof(T) == typeof(char) && _object is string value)
			{
				GCHandle handle = GCHandle.Alloc(value, GCHandleType.Pinned);
				void* pointer = Unsafe.Add<T>((void*)handle.AddrOfPinnedObject(), _index);
				return new MemoryHandle(pointer, handle);
			}
			if (_object is T[] array)
			{
				if (_length < 0)
				{
					void* pointer2 = Unsafe.Add<T>(Unsafe.AsPointer(ref MemoryMarshal.GetReference<T>(array)), _index);
					return new MemoryHandle(pointer2);
				}
				GCHandle handle2 = GCHandle.Alloc(array, GCHandleType.Pinned);
				void* pointer3 = Unsafe.Add<T>((void*)handle2.AddrOfPinnedObject(), _index);
				return new MemoryHandle(pointer3, handle2);
			}
			return default(MemoryHandle);
		}

		public T[] ToArray()
		{
			return Span.ToArray();
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public override bool Equals(object obj)
		{
			if (obj is ReadOnlyMemory<T> other)
			{
				return Equals(other);
			}
			if (obj is Memory<T> memory)
			{
				return Equals(memory);
			}
			return false;
		}

		public bool Equals(ReadOnlyMemory<T> other)
		{
			if (_object == other._object && _index == other._index)
			{
				return _length == other._length;
			}
			return false;
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public override int GetHashCode()
		{
			if (_object == null)
			{
				return 0;
			}
			int hashCode = _object.GetHashCode();
			int index = _index;
			int hashCode2 = index.GetHashCode();
			index = _length;
			return CombineHashCodes(hashCode, hashCode2, index.GetHashCode());
		}

		private static int CombineHashCodes(int left, int right)
		{
			return ((left << 5) + left) ^ right;
		}

		private static int CombineHashCodes(int h1, int h2, int h3)
		{
			return CombineHashCodes(CombineHashCodes(h1, h2), h3);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal object GetObjectStartLength(out int start, out int length)
		{
			start = _index;
			length = _length;
			return _object;
		}
	}
	[DebuggerTypeProxy(typeof(System.SpanDebugView<>))]
	[DebuggerDisplay("{ToString(),raw}")]
	[DebuggerTypeProxy(typeof(System.SpanDebugView<>))]
	[DebuggerDisplay("{ToString(),raw}")]
	public readonly ref struct ReadOnlySpan<T>
	{
		public ref struct Enumerator
		{
			private readonly ReadOnlySpan<T> _span;

			private int _index;

			public ref readonly T Current
			{
				[MethodImpl(MethodImplOptions.AggressiveInlining)]
				get
				{
					return ref _span[_index];
				}
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			internal Enumerator(ReadOnlySpan<T> span)
			{
				_span = span;
				_index = -1;
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			public bool MoveNext()
			{
				int num = _index + 1;
				if (num < _span.Length)
				{
					_index = num;
					return true;
				}
				return false;
			}
		}

		private readonly Pinnable<T> _pinnable;

		private readonly IntPtr _byteOffset;

		private readonly int _length;

		public int Length => _length;

		public bool IsEmpty => _length == 0;

		public static ReadOnlySpan<T> Empty => default(ReadOnlySpan<T>);

		public unsafe ref readonly T this[int index]
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				if ((uint)index >= (uint)_length)
				{
					System.ThrowHelper.ThrowIndexOutOfRangeException();
				}
				if (_pinnable == null)
				{
					IntPtr byteOffset = _byteOffset;
					return ref Unsafe.Add(ref Unsafe.AsRef<T>(byteOffset.ToPointer()), index);
				}
				return ref Unsafe.Add(ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset), index);
			}
		}

		internal Pinnable<T> Pinnable => _pinnable;

		internal IntPtr ByteOffset => _byteOffset;

		public static bool operator !=(ReadOnlySpan<T> left, ReadOnlySpan<T> right)
		{
			return !(left == right);
		}

		[Obsolete("Equals() on ReadOnlySpan will always throw an exception. Use == instead.")]
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override bool Equals(object obj)
		{
			throw new NotSupportedException(System.SR.NotSupported_CannotCallEqualsOnSpan);
		}

		[Obsolete("GetHashCode() on ReadOnlySpan will always throw an exception.")]
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override int GetHashCode()
		{
			throw new NotSupportedException(System.SR.NotSupported_CannotCallGetHashCodeOnSpan);
		}

		public static implicit operator ReadOnlySpan<T>(T[] array)
		{
			return new ReadOnlySpan<T>(array);
		}

		public static implicit operator ReadOnlySpan<T>(ArraySegment<T> segment)
		{
			return new ReadOnlySpan<T>(segment.Array, segment.Offset, segment.Count);
		}

		public Enumerator GetEnumerator()
		{
			return new Enumerator(this);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ReadOnlySpan(T[] array)
		{
			if (array == null)
			{
				this = default(ReadOnlySpan<T>);
				return;
			}
			_length = array.Length;
			_pinnable = Unsafe.As<Pinnable<T>>(array);
			_byteOffset = System.SpanHelpers.PerTypeValues<T>.ArrayAdjustment;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ReadOnlySpan(T[] array, int start, int length)
		{
			if (array == null)
			{
				if (start != 0 || length != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
				}
				this = default(ReadOnlySpan<T>);
				return;
			}
			if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			_length = length;
			_pinnable = Unsafe.As<Pinnable<T>>(array);
			_byteOffset = System.SpanHelpers.PerTypeValues<T>.ArrayAdjustment.Add<T>(start);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[CLSCompliant(false)]
		public unsafe ReadOnlySpan(void* pointer, int length)
		{
			if (System.SpanHelpers.IsReferenceOrContainsReferences<T>())
			{
				System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
			}
			if (length < 0)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			_length = length;
			_pinnable = null;
			_byteOffset = new IntPtr(pointer);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal ReadOnlySpan(Pinnable<T> pinnable, IntPtr byteOffset, int length)
		{
			_length = length;
			_pinnable = pinnable;
			_byteOffset = byteOffset;
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public unsafe ref readonly T GetPinnableReference()
		{
			if (_length != 0)
			{
				if (_pinnable == null)
				{
					IntPtr byteOffset = _byteOffset;
					return ref Unsafe.AsRef<T>(byteOffset.ToPointer());
				}
				return ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset);
			}
			return ref Unsafe.AsRef<T>(null);
		}

		public void CopyTo(Span<T> destination)
		{
			if (!TryCopyTo(destination))
			{
				System.ThrowHelper.ThrowArgumentException_DestinationTooShort();
			}
		}

		public bool TryCopyTo(Span<T> destination)
		{
			int length = _length;
			int length2 = destination.Length;
			if (length == 0)
			{
				return true;
			}
			if ((uint)length > (uint)length2)
			{
				return false;
			}
			ref T src = ref DangerousGetPinnableReference();
			System.SpanHelpers.CopyTo(ref destination.DangerousGetPinnableReference(), length2, ref src, length);
			return true;
		}

		public static bool operator ==(ReadOnlySpan<T> left, ReadOnlySpan<T> right)
		{
			if (left._length == right._length)
			{
				return Unsafe.AreSame(ref left.DangerousGetPinnableReference(), ref right.DangerousGetPinnableReference());
			}
			return false;
		}

		public unsafe override string ToString()
		{
			if (typeof(T) == typeof(char))
			{
				if (_byteOffset == MemoryExtensions.StringAdjustment)
				{
					object obj = Unsafe.As<object>(_pinnable);
					if (obj is string text && _length == text.Length)
					{
						return text;
					}
				}
				fixed (char* value = &Unsafe.As<T, char>(ref DangerousGetPinnableReference()))
				{
					return new string(value, 0, _length);
				}
			}
			return $"System.ReadOnlySpan<{typeof(T).Name}>[{_length}]";
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ReadOnlySpan<T> Slice(int start)
		{
			if ((uint)start > (uint)_length)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			IntPtr byteOffset = _byteOffset.Add<T>(start);
			int length = _length - start;
			return new ReadOnlySpan<T>(_pinnable, byteOffset, length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public ReadOnlySpan<T> Slice(int start, int length)
		{
			if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			IntPtr byteOffset = _byteOffset.Add<T>(start);
			return new ReadOnlySpan<T>(_pinnable, byteOffset, length);
		}

		public T[] ToArray()
		{
			if (_length == 0)
			{
				return System.SpanHelpers.PerTypeValues<T>.EmptyArray;
			}
			T[] array = new T[_length];
			CopyTo(array);
			return array;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[EditorBrowsable(EditorBrowsableState.Never)]
		internal unsafe ref T DangerousGetPinnableReference()
		{
			if (_pinnable == null)
			{
				IntPtr byteOffset = _byteOffset;
				return ref Unsafe.AsRef<T>(byteOffset.ToPointer());
			}
			return ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset);
		}
	}
	[DebuggerTypeProxy(typeof(System.SpanDebugView<>))]
	[DebuggerDisplay("{ToString(),raw}")]
	[DebuggerTypeProxy(typeof(System.SpanDebugView<>))]
	[DebuggerDisplay("{ToString(),raw}")]
	public readonly ref struct Span<T>
	{
		public ref struct Enumerator
		{
			private readonly Span<T> _span;

			private int _index;

			public ref T Current
			{
				[MethodImpl(MethodImplOptions.AggressiveInlining)]
				get
				{
					return ref _span[_index];
				}
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			internal Enumerator(Span<T> span)
			{
				_span = span;
				_index = -1;
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			public bool MoveNext()
			{
				int num = _index + 1;
				if (num < _span.Length)
				{
					_index = num;
					return true;
				}
				return false;
			}
		}

		private readonly Pinnable<T> _pinnable;

		private readonly IntPtr _byteOffset;

		private readonly int _length;

		public int Length => _length;

		public bool IsEmpty => _length == 0;

		public static Span<T> Empty => default(Span<T>);

		public unsafe ref T this[int index]
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				if ((uint)index >= (uint)_length)
				{
					System.ThrowHelper.ThrowIndexOutOfRangeException();
				}
				if (_pinnable == null)
				{
					IntPtr byteOffset = _byteOffset;
					return ref Unsafe.Add(ref Unsafe.AsRef<T>(byteOffset.ToPointer()), index);
				}
				return ref Unsafe.Add(ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset), index);
			}
		}

		internal Pinnable<T> Pinnable => _pinnable;

		internal IntPtr ByteOffset => _byteOffset;

		public static bool operator !=(Span<T> left, Span<T> right)
		{
			return !(left == right);
		}

		[Obsolete("Equals() on Span will always throw an exception. Use == instead.")]
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override bool Equals(object obj)
		{
			throw new NotSupportedException(System.SR.NotSupported_CannotCallEqualsOnSpan);
		}

		[Obsolete("GetHashCode() on Span will always throw an exception.")]
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override int GetHashCode()
		{
			throw new NotSupportedException(System.SR.NotSupported_CannotCallGetHashCodeOnSpan);
		}

		public static implicit operator Span<T>(T[] array)
		{
			return new Span<T>(array);
		}

		public static implicit operator Span<T>(ArraySegment<T> segment)
		{
			return new Span<T>(segment.Array, segment.Offset, segment.Count);
		}

		public Enumerator GetEnumerator()
		{
			return new Enumerator(this);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Span(T[] array)
		{
			if (array == null)
			{
				this = default(Span<T>);
				return;
			}
			if (default(T) == null && array.GetType() != typeof(T[]))
			{
				System.ThrowHelper.ThrowArrayTypeMismatchException();
			}
			_length = array.Length;
			_pinnable = Unsafe.As<Pinnable<T>>(array);
			_byteOffset = System.SpanHelpers.PerTypeValues<T>.ArrayAdjustment;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static Span<T> Create(T[] array, int start)
		{
			if (array == null)
			{
				if (start != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
				}
				return default(Span<T>);
			}
			if (default(T) == null && array.GetType() != typeof(T[]))
			{
				System.ThrowHelper.ThrowArrayTypeMismatchException();
			}
			if ((uint)start > (uint)array.Length)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			IntPtr byteOffset = System.SpanHelpers.PerTypeValues<T>.ArrayAdjustment.Add<T>(start);
			int length = array.Length - start;
			return new Span<T>(Unsafe.As<Pinnable<T>>(array), byteOffset, length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Span(T[] array, int start, int length)
		{
			if (array == null)
			{
				if (start != 0 || length != 0)
				{
					System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
				}
				this = default(Span<T>);
				return;
			}
			if (default(T) == null && array.GetType() != typeof(T[]))
			{
				System.ThrowHelper.ThrowArrayTypeMismatchException();
			}
			if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			_length = length;
			_pinnable = Unsafe.As<Pinnable<T>>(array);
			_byteOffset = System.SpanHelpers.PerTypeValues<T>.ArrayAdjustment.Add<T>(start);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[CLSCompliant(false)]
		public unsafe Span(void* pointer, int length)
		{
			if (System.SpanHelpers.IsReferenceOrContainsReferences<T>())
			{
				System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
			}
			if (length < 0)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			_length = length;
			_pinnable = null;
			_byteOffset = new IntPtr(pointer);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal Span(Pinnable<T> pinnable, IntPtr byteOffset, int length)
		{
			_length = length;
			_pinnable = pinnable;
			_byteOffset = byteOffset;
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public unsafe ref T GetPinnableReference()
		{
			if (_length != 0)
			{
				if (_pinnable == null)
				{
					IntPtr byteOffset = _byteOffset;
					return ref Unsafe.AsRef<T>(byteOffset.ToPointer());
				}
				return ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset);
			}
			return ref Unsafe.AsRef<T>(null);
		}

		public unsafe void Clear()
		{
			int length = _length;
			if (length == 0)
			{
				return;
			}
			UIntPtr byteLength = (UIntPtr)(ulong)((uint)length * Unsafe.SizeOf<T>());
			if ((Unsafe.SizeOf<T>() & (sizeof(IntPtr) - 1)) != 0)
			{
				if (_pinnable == null)
				{
					IntPtr byteOffset = _byteOffset;
					byte* ptr = (byte*)byteOffset.ToPointer();
					System.SpanHelpers.ClearLessThanPointerSized(ptr, byteLength);
				}
				else
				{
					System.SpanHelpers.ClearLessThanPointerSized(ref Unsafe.As<T, byte>(ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset)), byteLength);
				}
			}
			else if (System.SpanHelpers.IsReferenceOrContainsReferences<T>())
			{
				UIntPtr pointerSizeLength = (UIntPtr)(ulong)(length * Unsafe.SizeOf<T>() / sizeof(IntPtr));
				System.SpanHelpers.ClearPointerSizedWithReferences(ref Unsafe.As<T, IntPtr>(ref DangerousGetPinnableReference()), pointerSizeLength);
			}
			else
			{
				System.SpanHelpers.ClearPointerSizedWithoutReferences(ref Unsafe.As<T, byte>(ref DangerousGetPinnableReference()), byteLength);
			}
		}

		public unsafe void Fill(T value)
		{
			int length = _length;
			if (length == 0)
			{
				return;
			}
			if (Unsafe.SizeOf<T>() == 1)
			{
				byte value2 = Unsafe.As<T, byte>(ref value);
				if (_pinnable == null)
				{
					IntPtr byteOffset = _byteOffset;
					Unsafe.InitBlockUnaligned(byteOffset.ToPointer(), value2, (uint)length);
				}
				else
				{
					Unsafe.InitBlockUnaligned(ref Unsafe.As<T, byte>(ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset)), value2, (uint)length);
				}
				return;
			}
			ref T source = ref DangerousGetPinnableReference();
			int i;
			for (i = 0; i < (length & -8); i += 8)
			{
				Unsafe.Add(ref source, i) = value;
				Unsafe.Add(ref source, i + 1) = value;
				Unsafe.Add(ref source, i + 2) = value;
				Unsafe.Add(ref source, i + 3) = value;
				Unsafe.Add(ref source, i + 4) = value;
				Unsafe.Add(ref source, i + 5) = value;
				Unsafe.Add(ref source, i + 6) = value;
				Unsafe.Add(ref source, i + 7) = value;
			}
			if (i < (length & -4))
			{
				Unsafe.Add(ref source, i) = value;
				Unsafe.Add(ref source, i + 1) = value;
				Unsafe.Add(ref source, i + 2) = value;
				Unsafe.Add(ref source, i + 3) = value;
				i += 4;
			}
			for (; i < length; i++)
			{
				Unsafe.Add(ref source, i) = value;
			}
		}

		public void CopyTo(Span<T> destination)
		{
			if (!TryCopyTo(destination))
			{
				System.ThrowHelper.ThrowArgumentException_DestinationTooShort();
			}
		}

		public bool TryCopyTo(Span<T> destination)
		{
			int length = _length;
			int length2 = destination._length;
			if (length == 0)
			{
				return true;
			}
			if ((uint)length > (uint)length2)
			{
				return false;
			}
			ref T src = ref DangerousGetPinnableReference();
			System.SpanHelpers.CopyTo(ref destination.DangerousGetPinnableReference(), length2, ref src, length);
			return true;
		}

		public static bool operator ==(Span<T> left, Span<T> right)
		{
			if (left._length == right._length)
			{
				return Unsafe.AreSame(ref left.DangerousGetPinnableReference(), ref right.DangerousGetPinnableReference());
			}
			return false;
		}

		public static implicit operator ReadOnlySpan<T>(Span<T> span)
		{
			return new ReadOnlySpan<T>(span._pinnable, span._byteOffset, span._length);
		}

		public unsafe override string ToString()
		{
			if (typeof(T) == typeof(char))
			{
				fixed (char* value = &Unsafe.As<T, char>(ref DangerousGetPinnableReference()))
				{
					return new string(value, 0, _length);
				}
			}
			return $"System.Span<{typeof(T).Name}>[{_length}]";
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Span<T> Slice(int start)
		{
			if ((uint)start > (uint)_length)
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			IntPtr byteOffset = _byteOffset.Add<T>(start);
			int length = _length - start;
			return new Span<T>(_pinnable, byteOffset, length);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public Span<T> Slice(int start, int length)
		{
			if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start))
			{
				System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start);
			}
			IntPtr byteOffset = _byteOffset.Add<T>(start);
			return new Span<T>(_pinnable, byteOffset, length);
		}

		public T[] ToArray()
		{
			if (_length == 0)
			{
				return System.SpanHelpers.PerTypeValues<T>.EmptyArray;
			}
			T[] array = new T[_length];
			CopyTo(array);
			return array;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[EditorBrowsable(EditorBrowsableState.Never)]
		internal unsafe ref T DangerousGetPinnableReference()
		{
			if (_pinnable == null)
			{
				IntPtr byteOffset = _byteOffset;
				return ref Unsafe.AsRef<T>(byteOffset.ToPointer());
			}
			return ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset);
		}
	}
	internal sealed class SpanDebugView<T>
	{
		private readonly T[] _array;

		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
		public T[] Items => _array;

		public SpanDebugView(Span<T> span)
		{
			_array = span.ToArray();
		}

		public SpanDebugView(ReadOnlySpan<T> span)
		{
			_array = span.ToArray();
		}
	}
	internal static class SpanHelpers
	{
		internal struct ComparerComparable<T, TComparer> : IComparable<T> where TComparer : IComparer<T>
		{
			private readonly T _value;

			private readonly TComparer _comparer;

			public ComparerComparable(T value, TComparer comparer)
			{
				_value = value;
				_comparer = comparer;
			}

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			public int CompareTo(T other)
			{
				return _comparer.Compare(_value, other);
			}
		}

		[StructLayout(LayoutKind.Sequential, Size = 64)]
		private struct Reg64
		{
		}

		[StructLayout(LayoutKind.Sequential, Size = 32)]
		private struct Reg32
		{
		}

		[StructLayout(LayoutKind.Sequential, Size = 16)]
		private struct Reg16
		{
		}

		public static class PerTypeValues<T>
		{
			public static readonly bool IsReferenceOrContainsReferences = IsReferenceOrContainsReferencesCore(typeof(T));

			public static readonly T[] EmptyArray = new T[0];

			public static readonly IntPtr ArrayAdjustment = MeasureArrayAdjustment();

			private static IntPtr MeasureArrayAdjustment()
			{
				T[] array = new T[1];
				return Unsafe.ByteOffset(ref Unsafe.As<Pinnable<T>>(array).Data, ref array[0]);
			}
		}

		private const ulong XorPowerOfTwoToHighByte = 283686952306184uL;

		private const ulong XorPowerOfTwoToHighChar = 4295098372uL;

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int BinarySearch<T, TComparable>(this ReadOnlySpan<T> span, TComparable comparable) where TComparable : IComparable<T>
		{
			if (comparable == null)
			{
				System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.comparable);
			}
			return BinarySearch(ref MemoryMarshal.GetReference(span), span.Length, comparable);
		}

		public static int BinarySearch<T, TComparable>(ref T spanStart, int length, TComparable comparable) where TComparable : IComparable<T>
		{
			int num = 0;
			int num2 = length - 1;
			while (num <= num2)
			{
				int num3 = num2 + num >>> 1;
				int num4 = comparable.CompareTo(Unsafe.Add(ref spanStart, num3));
				if (num4 == 0)
				{
					return num3;
				}
				if (num4 > 0)
				{
					num = num3 + 1;
				}
				else
				{
					num2 = num3 - 1;
				}
			}
			return ~num;
		}

		public static int IndexOf(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength)
		{
			if (valueLength == 0)
			{
				return 0;
			}
			byte value2 = value;
			ref byte second = ref Unsafe.Add(ref value, 1);
			int num = valueLength - 1;
			int num2 = 0;
			while (true)
			{
				int num3 = searchSpaceLength - num2 - num;
				if (num3 <= 0)
				{
					break;
				}
				int num4 = IndexOf(ref Unsafe.Add(ref searchSpace, num2), value2, num3);
				if (num4 == -1)
				{
					break;
				}
				num2 += num4;
				if (SequenceEqual(ref Unsafe.Add(ref searchSpace, num2 + 1), ref second, num))
				{
					return num2;
				}
				num2++;
			}
			return -1;
		}

		public static int IndexOfAny(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength)
		{
			if (valueLength == 0)
			{
				return 0;
			}
			int num = -1;
			for (int i = 0; i < valueLength; i++)
			{
				int num2 = IndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength);
				if ((uint)num2 < (uint)num)
				{
					num = num2;
					searchSpaceLength = num2;
					if (num == 0)
					{
						break;
					}
				}
			}
			return num;
		}

		public static int LastIndexOfAny(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength)
		{
			if (valueLength == 0)
			{
				return 0;
			}
			int num = -1;
			for (int i = 0; i < valueLength; i++)
			{
				int num2 = LastIndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength);
				if (num2 > num)
				{
					num = num2;
				}
			}
			return num;
		}

		public unsafe static int IndexOf(ref byte searchSpace, byte value, int length)
		{
			IntPtr intPtr = (IntPtr)0;
			IntPtr intPtr2 = (IntPtr)length;
			if (Vector.IsHardwareAccelerated && length >= Vector<byte>.Count * 2)
			{
				int num = (int)Unsafe.AsPointer(ref searchSpace) & (Vector<byte>.Count - 1);
				intPtr2 = (IntPtr)((Vector<byte>.Count - num) & (Vector<byte>.Count - 1));
			}
			while (true)
			{
				if ((nuint)(void*)intPtr2 >= (nuint)8u)
				{
					intPtr2 -= 8;
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr))
					{
						goto IL_0242;
					}
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 1))
					{
						goto IL_024a;
					}
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 2))
					{
						goto IL_0258;
					}
					if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 3))
					{
						if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 4))
						{
							if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 5))
							{
								if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 6))
								{
									if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 7))
									{
										break;
									}
									intPtr += 8;
									continue;
								}
								return (int)(void*)(intPtr + 6);
							}
							return (int)(void*)(intPtr + 5);
						}
						return (int)(void*)(intPtr + 4);
					}
					goto IL_0266;
				}
				if ((nuint)(void*)intPtr2 >= (nuint)4u)
				{
					intPtr2 -= 4;
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr))
					{
						goto IL_0242;
					}
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 1))
					{
						goto IL_024a;
					}
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 2))
					{
						goto IL_0258;
					}
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 3))
					{
						goto IL_0266;
					}
					intPtr += 4;
				}
				while ((void*)intPtr2 != null)
				{
					intPtr2 -= 1;
					if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr))
					{
						intPtr += 1;
						continue;
					}
					goto IL_0242;
				}
				if (Vector.IsHardwareAccelerated && (int)(void*)intPtr < length)
				{
					intPtr2 = (IntPtr)((length - (int)(void*)intPtr) & ~(Vector<byte>.Count - 1));
					Vector<byte> vector = GetVector(value);
					for (; (void*)intPtr2 > (void*)intPtr; intPtr += Vector<byte>.Count)
					{
						Vector<byte> vector2 = Vector.Equals(vector, Unsafe.ReadUnaligned<Vector<byte>>(ref Unsafe.AddByteOffset(ref searchSpace, intPtr)));
						if (!Vector<byte>.Zero.Equals(vector2))
						{
							return (int)(void*)intPtr + LocateFirstFoundByte(vector2);
						}
					}
					if ((int)(void*)intPtr < length)
					{
						intPtr2 = (IntPtr)(length - (int)(void*)intPtr);
						continue;
					}
				}
				return -1;
				IL_0266:
				return (int)(void*)(intPtr + 3);
				IL_0242:
				return (int)(void*)intPtr;
				IL_0258:
				return (int)(void*)(intPtr + 2);
				IL_024a:
				return (int)(void*)(intPtr + 1);
			}
			return (int)(void*)(intPtr + 7);
		}

		public static int LastIndexOf(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength)
		{
			if (valueLength == 0)
			{
				return 0;
			}
			byte value2 = value;
			ref byte second = ref Unsafe.Add(ref value, 1);
			int num = valueLength - 1;
			int num2 = 0;
			while (true)
			{
				int num3 = searchSpaceLength - num2 - num;
				if (num3 <= 0)
				{
					break;
				}
				int num4 = LastIndexOf(ref searchSpace, value2, num3);
				if (num4 == -1)
				{
					break;
				}
				if (SequenceEqual(ref Unsafe.Add(ref searchSpace, num4 + 1), ref second, num))
				{
					return num4;
				}
				num2 += num3 - num4;
			}
			return -1;
		}

		public unsafe static int LastIndexOf(ref byte searchSpace, byte value, int length)
		{
			IntPtr intPtr = (IntPtr)length;
			IntPtr intPtr2 = (IntPtr)length;
			if (Vector.IsHardwareAccelerated && length >= Vector<byte>.Count * 2)
			{
				int num = (int)Unsafe.AsPointer(ref searchSpace) & (Vector<byte>.Count - 1);
				intPtr2 = (IntPtr)(((length & (Vector<byte>.Count - 1)) + num) & (Vector<byte>.Count - 1));
			}
			while (true)
			{
				if ((nuint)(void*)intPtr2 >= (nuint)8u)
				{
					intPtr2 -= 8;
					intPtr -= 8;
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 7))
					{
						break;
					}
					if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 6))
					{
						if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 5))
						{
							if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 4))
							{
								if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 3))
								{
									if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 2))
									{
										if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr + 1))
										{
											if (value != Unsafe.AddByteOffset(ref searchSpace, intPtr))
											{
												continue;
											}
											goto IL_0254;
										}
										goto IL_025c;
									}
									goto IL_026a;
								}
								goto IL_0278;
							}
							return (int)(void*)(intPtr + 4);
						}
						return (int)(void*)(intPtr + 5);
					}
					return (int)(void*)(intPtr + 6);
				}
				if ((nuint)(void*)intPtr2 >= (nuint)4u)
				{
					intPtr2 -= 4;
					intPtr -= 4;
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 3))
					{
						goto IL_0278;
					}
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 2))
					{
						goto IL_026a;
					}
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr + 1))
					{
						goto IL_025c;
					}
					if (value == Unsafe.AddByteOffset(ref searchSpace, intPtr))
					{
						goto IL_0254;
					}
				}
				while ((void*)intPtr2 != null)
				{
					intPtr2 -= 1;
					intPtr -= 1;
					if (value !

plugins\System.Numerics.Vectors.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Numerics;
using System.Numerics.Hashing;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using FxResources.System.Numerics.Vectors;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyTitle("System.Numerics.Vectors")]
[assembly: AssemblyDescription("System.Numerics.Vectors")]
[assembly: AssemblyDefaultAlias("System.Numerics.Vectors")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: AssemblyCopyright("© Microsoft Corporation.  All rights reserved.")]
[assembly: AssemblyFileVersion("4.6.25519.03")]
[assembly: AssemblyInformationalVersion("4.6.25519.03 built by: dlab-DDVSOWINAGE013. Commit Hash: 8321c729934c0f8be754953439b88e6e1c120c24")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.1.3.0")]
[assembly: TypeForwardedTo(typeof(Matrix3x2))]
[assembly: TypeForwardedTo(typeof(Matrix4x4))]
[assembly: TypeForwardedTo(typeof(Plane))]
[assembly: TypeForwardedTo(typeof(Quaternion))]
[assembly: TypeForwardedTo(typeof(Vector2))]
[assembly: TypeForwardedTo(typeof(Vector3))]
[assembly: TypeForwardedTo(typeof(Vector4))]
[module: UnverifiableCode]
namespace FxResources.System.Numerics.Vectors
{
	internal static class SR
	{
	}
}
namespace System
{
	internal static class MathF
	{
		public const float PI = 3.1415927f;

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Abs(float x)
		{
			return Math.Abs(x);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Acos(float x)
		{
			return (float)Math.Acos(x);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Cos(float x)
		{
			return (float)Math.Cos(x);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float IEEERemainder(float x, float y)
		{
			return (float)Math.IEEERemainder(x, y);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Sin(float x)
		{
			return (float)Math.Sin(x);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Sqrt(float x)
		{
			return (float)Math.Sqrt(x);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Tan(float x)
		{
			return (float)Math.Tan(x);
		}
	}
	internal static class SR
	{
		private static ResourceManager s_resourceManager;

		private const string s_resourcesName = "FxResources.System.Numerics.Vectors.SR";

		private static ResourceManager ResourceManager => s_resourceManager ?? (s_resourceManager = new ResourceManager(ResourceType));

		internal static string Arg_ArgumentOutOfRangeException => GetResourceString("Arg_ArgumentOutOfRangeException", null);

		internal static string Arg_ElementsInSourceIsGreaterThanDestination => GetResourceString("Arg_ElementsInSourceIsGreaterThanDestination", null);

		internal static string Arg_NullArgumentNullRef => GetResourceString("Arg_NullArgumentNullRef", null);

		internal static string Arg_TypeNotSupported => GetResourceString("Arg_TypeNotSupported", null);

		internal static Type ResourceType => typeof(SR);

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool UsingResourceKeys()
		{
			return false;
		}

		internal static string GetResourceString(string resourceKey, string defaultString)
		{
			string text = null;
			try
			{
				text = ResourceManager.GetString(resourceKey);
			}
			catch (MissingManifestResourceException)
			{
			}
			if (defaultString != null && resourceKey.Equals(text, StringComparison.Ordinal))
			{
				return defaultString;
			}
			return text;
		}

		internal static string Format(string resourceFormat, params object[] args)
		{
			if (args != null)
			{
				if (UsingResourceKeys())
				{
					return resourceFormat + string.Join(", ", args);
				}
				return string.Format(resourceFormat, args);
			}
			return resourceFormat;
		}

		internal static string Format(string resourceFormat, object p1)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1);
			}
			return string.Format(resourceFormat, p1);
		}

		internal static string Format(string resourceFormat, object p1, object p2)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2);
			}
			return string.Format(resourceFormat, p1, p2);
		}

		internal static string Format(string resourceFormat, object p1, object p2, object p3)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1, p2, p3);
			}
			return string.Format(resourceFormat, p1, p2, p3);
		}
	}
}
namespace System.Numerics
{
	internal class ConstantHelper
	{
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static byte GetByteWithAllBitsSet()
		{
			byte result = 0;
			result = byte.MaxValue;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static sbyte GetSByteWithAllBitsSet()
		{
			sbyte result = 0;
			result = -1;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ushort GetUInt16WithAllBitsSet()
		{
			ushort result = 0;
			result = ushort.MaxValue;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static short GetInt16WithAllBitsSet()
		{
			short result = 0;
			result = -1;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static uint GetUInt32WithAllBitsSet()
		{
			uint result = 0u;
			result = uint.MaxValue;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static int GetInt32WithAllBitsSet()
		{
			int result = 0;
			result = -1;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ulong GetUInt64WithAllBitsSet()
		{
			ulong result = 0uL;
			result = ulong.MaxValue;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static long GetInt64WithAllBitsSet()
		{
			long result = 0L;
			result = -1L;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public unsafe static float GetSingleWithAllBitsSet()
		{
			float result = 0f;
			*(int*)(&result) = -1;
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public unsafe static double GetDoubleWithAllBitsSet()
		{
			double result = 0.0;
			*(long*)(&result) = -1L;
			return result;
		}
	}
	[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property)]
	internal class JitIntrinsicAttribute : Attribute
	{
	}
	[StructLayout(LayoutKind.Explicit)]
	internal struct Register
	{
		[FieldOffset(0)]
		internal byte byte_0;

		[FieldOffset(1)]
		internal byte byte_1;

		[FieldOffset(2)]
		internal byte byte_2;

		[FieldOffset(3)]
		internal byte byte_3;

		[FieldOffset(4)]
		internal byte byte_4;

		[FieldOffset(5)]
		internal byte byte_5;

		[FieldOffset(6)]
		internal byte byte_6;

		[FieldOffset(7)]
		internal byte byte_7;

		[FieldOffset(8)]
		internal byte byte_8;

		[FieldOffset(9)]
		internal byte byte_9;

		[FieldOffset(10)]
		internal byte byte_10;

		[FieldOffset(11)]
		internal byte byte_11;

		[FieldOffset(12)]
		internal byte byte_12;

		[FieldOffset(13)]
		internal byte byte_13;

		[FieldOffset(14)]
		internal byte byte_14;

		[FieldOffset(15)]
		internal byte byte_15;

		[FieldOffset(0)]
		internal sbyte sbyte_0;

		[FieldOffset(1)]
		internal sbyte sbyte_1;

		[FieldOffset(2)]
		internal sbyte sbyte_2;

		[FieldOffset(3)]
		internal sbyte sbyte_3;

		[FieldOffset(4)]
		internal sbyte sbyte_4;

		[FieldOffset(5)]
		internal sbyte sbyte_5;

		[FieldOffset(6)]
		internal sbyte sbyte_6;

		[FieldOffset(7)]
		internal sbyte sbyte_7;

		[FieldOffset(8)]
		internal sbyte sbyte_8;

		[FieldOffset(9)]
		internal sbyte sbyte_9;

		[FieldOffset(10)]
		internal sbyte sbyte_10;

		[FieldOffset(11)]
		internal sbyte sbyte_11;

		[FieldOffset(12)]
		internal sbyte sbyte_12;

		[FieldOffset(13)]
		internal sbyte sbyte_13;

		[FieldOffset(14)]
		internal sbyte sbyte_14;

		[FieldOffset(15)]
		internal sbyte sbyte_15;

		[FieldOffset(0)]
		internal ushort uint16_0;

		[FieldOffset(2)]
		internal ushort uint16_1;

		[FieldOffset(4)]
		internal ushort uint16_2;

		[FieldOffset(6)]
		internal ushort uint16_3;

		[FieldOffset(8)]
		internal ushort uint16_4;

		[FieldOffset(10)]
		internal ushort uint16_5;

		[FieldOffset(12)]
		internal ushort uint16_6;

		[FieldOffset(14)]
		internal ushort uint16_7;

		[FieldOffset(0)]
		internal short int16_0;

		[FieldOffset(2)]
		internal short int16_1;

		[FieldOffset(4)]
		internal short int16_2;

		[FieldOffset(6)]
		internal short int16_3;

		[FieldOffset(8)]
		internal short int16_4;

		[FieldOffset(10)]
		internal short int16_5;

		[FieldOffset(12)]
		internal short int16_6;

		[FieldOffset(14)]
		internal short int16_7;

		[FieldOffset(0)]
		internal uint uint32_0;

		[FieldOffset(4)]
		internal uint uint32_1;

		[FieldOffset(8)]
		internal uint uint32_2;

		[FieldOffset(12)]
		internal uint uint32_3;

		[FieldOffset(0)]
		internal int int32_0;

		[FieldOffset(4)]
		internal int int32_1;

		[FieldOffset(8)]
		internal int int32_2;

		[FieldOffset(12)]
		internal int int32_3;

		[FieldOffset(0)]
		internal ulong uint64_0;

		[FieldOffset(8)]
		internal ulong uint64_1;

		[FieldOffset(0)]
		internal long int64_0;

		[FieldOffset(8)]
		internal long int64_1;

		[FieldOffset(0)]
		internal float single_0;

		[FieldOffset(4)]
		internal float single_1;

		[FieldOffset(8)]
		internal float single_2;

		[FieldOffset(12)]
		internal float single_3;

		[FieldOffset(0)]
		internal double double_0;

		[FieldOffset(8)]
		internal double double_1;
	}
	public struct Vector<T> : IEquatable<Vector<T>>, IFormattable where T : struct
	{
		private struct VectorSizeHelper
		{
			internal Vector<T> _placeholder;

			internal byte _byte;
		}

		private System.Numerics.Register register;

		private static readonly int s_count = InitializeCount();

		private static readonly Vector<T> zero = new Vector<T>(GetZeroValue());

		private static readonly Vector<T> one = new Vector<T>(GetOneValue());

		private static readonly Vector<T> allOnes = new Vector<T>(GetAllBitsSetValue());

		[JitIntrinsic]
		public static int Count => s_count;

		[JitIntrinsic]
		public static Vector<T> Zero => zero;

		[JitIntrinsic]
		public static Vector<T> One => one;

		internal static Vector<T> AllOnes => allOnes;

		[JitIntrinsic]
		public unsafe T this[int index]
		{
			get
			{
				if (index >= Count || index < 0)
				{
					throw new IndexOutOfRangeException(System.SR.Format(System.SR.Arg_ArgumentOutOfRangeException, index));
				}
				if (typeof(T) == typeof(byte))
				{
					fixed (byte* ptr = &register.byte_0)
					{
						return (T)(object)ptr[index];
					}
				}
				if (typeof(T) == typeof(sbyte))
				{
					fixed (sbyte* ptr2 = &register.sbyte_0)
					{
						return (T)(object)ptr2[index];
					}
				}
				if (typeof(T) == typeof(ushort))
				{
					fixed (ushort* ptr3 = &register.uint16_0)
					{
						return (T)(object)ptr3[index];
					}
				}
				if (typeof(T) == typeof(short))
				{
					fixed (short* ptr4 = &register.int16_0)
					{
						return (T)(object)ptr4[index];
					}
				}
				if (typeof(T) == typeof(uint))
				{
					fixed (uint* ptr5 = &register.uint32_0)
					{
						return (T)(object)ptr5[index];
					}
				}
				if (typeof(T) == typeof(int))
				{
					fixed (int* ptr6 = &register.int32_0)
					{
						return (T)(object)ptr6[index];
					}
				}
				if (typeof(T) == typeof(ulong))
				{
					fixed (ulong* ptr7 = &register.uint64_0)
					{
						return (T)(object)ptr7[index];
					}
				}
				if (typeof(T) == typeof(long))
				{
					fixed (long* ptr8 = &register.int64_0)
					{
						return (T)(object)ptr8[index];
					}
				}
				if (typeof(T) == typeof(float))
				{
					fixed (float* ptr9 = &register.single_0)
					{
						return (T)(object)ptr9[index];
					}
				}
				if (typeof(T) == typeof(double))
				{
					fixed (double* ptr10 = &register.double_0)
					{
						return (T)(object)ptr10[index];
					}
				}
				throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
			}
		}

		private unsafe static int InitializeCount()
		{
			VectorSizeHelper vectorSizeHelper = default(VectorSizeHelper);
			byte* ptr = &vectorSizeHelper._placeholder.register.byte_0;
			byte* ptr2 = &vectorSizeHelper._byte;
			int num = (int)(ptr2 - ptr);
			int num2 = -1;
			if (typeof(T) == typeof(byte))
			{
				num2 = 1;
			}
			else if (typeof(T) == typeof(sbyte))
			{
				num2 = 1;
			}
			else if (typeof(T) == typeof(ushort))
			{
				num2 = 2;
			}
			else if (typeof(T) == typeof(short))
			{
				num2 = 2;
			}
			else if (typeof(T) == typeof(uint))
			{
				num2 = 4;
			}
			else if (typeof(T) == typeof(int))
			{
				num2 = 4;
			}
			else if (typeof(T) == typeof(ulong))
			{
				num2 = 8;
			}
			else if (typeof(T) == typeof(long))
			{
				num2 = 8;
			}
			else if (typeof(T) == typeof(float))
			{
				num2 = 4;
			}
			else
			{
				if (!(typeof(T) == typeof(double)))
				{
					throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
				}
				num2 = 8;
			}
			return num / num2;
		}

		[JitIntrinsic]
		public unsafe Vector(T value)
		{
			this = default(Vector<T>);
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					fixed (byte* ptr = &register.byte_0)
					{
						for (int i = 0; i < Count; i++)
						{
							ptr[i] = (byte)(object)value;
						}
					}
				}
				else if (typeof(T) == typeof(sbyte))
				{
					fixed (sbyte* ptr2 = &register.sbyte_0)
					{
						for (int j = 0; j < Count; j++)
						{
							ptr2[j] = (sbyte)(object)value;
						}
					}
				}
				else if (typeof(T) == typeof(ushort))
				{
					fixed (ushort* ptr3 = &register.uint16_0)
					{
						for (int k = 0; k < Count; k++)
						{
							ptr3[k] = (ushort)(object)value;
						}
					}
				}
				else if (typeof(T) == typeof(short))
				{
					fixed (short* ptr4 = &register.int16_0)
					{
						for (int l = 0; l < Count; l++)
						{
							ptr4[l] = (short)(object)value;
						}
					}
				}
				else if (typeof(T) == typeof(uint))
				{
					fixed (uint* ptr5 = &register.uint32_0)
					{
						for (int m = 0; m < Count; m++)
						{
							ptr5[m] = (uint)(object)value;
						}
					}
				}
				else if (typeof(T) == typeof(int))
				{
					fixed (int* ptr6 = &register.int32_0)
					{
						for (int n = 0; n < Count; n++)
						{
							ptr6[n] = (int)(object)value;
						}
					}
				}
				else if (typeof(T) == typeof(ulong))
				{
					fixed (ulong* ptr7 = &register.uint64_0)
					{
						for (int num = 0; num < Count; num++)
						{
							ptr7[num] = (ulong)(object)value;
						}
					}
				}
				else if (typeof(T) == typeof(long))
				{
					fixed (long* ptr8 = &register.int64_0)
					{
						for (int num2 = 0; num2 < Count; num2++)
						{
							ptr8[num2] = (long)(object)value;
						}
					}
				}
				else if (typeof(T) == typeof(float))
				{
					fixed (float* ptr9 = &register.single_0)
					{
						for (int num3 = 0; num3 < Count; num3++)
						{
							ptr9[num3] = (float)(object)value;
						}
					}
				}
				else
				{
					if (!(typeof(T) == typeof(double)))
					{
						return;
					}
					fixed (double* ptr10 = &register.double_0)
					{
						for (int num4 = 0; num4 < Count; num4++)
						{
							ptr10[num4] = (double)(object)value;
						}
					}
				}
			}
			else if (typeof(T) == typeof(byte))
			{
				register.byte_0 = (byte)(object)value;
				register.byte_1 = (byte)(object)value;
				register.byte_2 = (byte)(object)value;
				register.byte_3 = (byte)(object)value;
				register.byte_4 = (byte)(object)value;
				register.byte_5 = (byte)(object)value;
				register.byte_6 = (byte)(object)value;
				register.byte_7 = (byte)(object)value;
				register.byte_8 = (byte)(object)value;
				register.byte_9 = (byte)(object)value;
				register.byte_10 = (byte)(object)value;
				register.byte_11 = (byte)(object)value;
				register.byte_12 = (byte)(object)value;
				register.byte_13 = (byte)(object)value;
				register.byte_14 = (byte)(object)value;
				register.byte_15 = (byte)(object)value;
			}
			else if (typeof(T) == typeof(sbyte))
			{
				register.sbyte_0 = (sbyte)(object)value;
				register.sbyte_1 = (sbyte)(object)value;
				register.sbyte_2 = (sbyte)(object)value;
				register.sbyte_3 = (sbyte)(object)value;
				register.sbyte_4 = (sbyte)(object)value;
				register.sbyte_5 = (sbyte)(object)value;
				register.sbyte_6 = (sbyte)(object)value;
				register.sbyte_7 = (sbyte)(object)value;
				register.sbyte_8 = (sbyte)(object)value;
				register.sbyte_9 = (sbyte)(object)value;
				register.sbyte_10 = (sbyte)(object)value;
				register.sbyte_11 = (sbyte)(object)value;
				register.sbyte_12 = (sbyte)(object)value;
				register.sbyte_13 = (sbyte)(object)value;
				register.sbyte_14 = (sbyte)(object)value;
				register.sbyte_15 = (sbyte)(object)value;
			}
			else if (typeof(T) == typeof(ushort))
			{
				register.uint16_0 = (ushort)(object)value;
				register.uint16_1 = (ushort)(object)value;
				register.uint16_2 = (ushort)(object)value;
				register.uint16_3 = (ushort)(object)value;
				register.uint16_4 = (ushort)(object)value;
				register.uint16_5 = (ushort)(object)value;
				register.uint16_6 = (ushort)(object)value;
				register.uint16_7 = (ushort)(object)value;
			}
			else if (typeof(T) == typeof(short))
			{
				register.int16_0 = (short)(object)value;
				register.int16_1 = (short)(object)value;
				register.int16_2 = (short)(object)value;
				register.int16_3 = (short)(object)value;
				register.int16_4 = (short)(object)value;
				register.int16_5 = (short)(object)value;
				register.int16_6 = (short)(object)value;
				register.int16_7 = (short)(object)value;
			}
			else if (typeof(T) == typeof(uint))
			{
				register.uint32_0 = (uint)(object)value;
				register.uint32_1 = (uint)(object)value;
				register.uint32_2 = (uint)(object)value;
				register.uint32_3 = (uint)(object)value;
			}
			else if (typeof(T) == typeof(int))
			{
				register.int32_0 = (int)(object)value;
				register.int32_1 = (int)(object)value;
				register.int32_2 = (int)(object)value;
				register.int32_3 = (int)(object)value;
			}
			else if (typeof(T) == typeof(ulong))
			{
				register.uint64_0 = (ulong)(object)value;
				register.uint64_1 = (ulong)(object)value;
			}
			else if (typeof(T) == typeof(long))
			{
				register.int64_0 = (long)(object)value;
				register.int64_1 = (long)(object)value;
			}
			else if (typeof(T) == typeof(float))
			{
				register.single_0 = (float)(object)value;
				register.single_1 = (float)(object)value;
				register.single_2 = (float)(object)value;
				register.single_3 = (float)(object)value;
			}
			else if (typeof(T) == typeof(double))
			{
				register.double_0 = (double)(object)value;
				register.double_1 = (double)(object)value;
			}
		}

		[JitIntrinsic]
		public Vector(T[] values)
			: this(values, 0)
		{
		}

		public unsafe Vector(T[] values, int index)
		{
			this = default(Vector<T>);
			if (values == null)
			{
				throw new NullReferenceException(System.SR.Arg_NullArgumentNullRef);
			}
			if (index < 0 || values.Length - index < Count)
			{
				throw new IndexOutOfRangeException();
			}
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					fixed (byte* ptr = &register.byte_0)
					{
						for (int i = 0; i < Count; i++)
						{
							ptr[i] = (byte)(object)values[i + index];
						}
					}
				}
				else if (typeof(T) == typeof(sbyte))
				{
					fixed (sbyte* ptr2 = &register.sbyte_0)
					{
						for (int j = 0; j < Count; j++)
						{
							ptr2[j] = (sbyte)(object)values[j + index];
						}
					}
				}
				else if (typeof(T) == typeof(ushort))
				{
					fixed (ushort* ptr3 = &register.uint16_0)
					{
						for (int k = 0; k < Count; k++)
						{
							ptr3[k] = (ushort)(object)values[k + index];
						}
					}
				}
				else if (typeof(T) == typeof(short))
				{
					fixed (short* ptr4 = &register.int16_0)
					{
						for (int l = 0; l < Count; l++)
						{
							ptr4[l] = (short)(object)values[l + index];
						}
					}
				}
				else if (typeof(T) == typeof(uint))
				{
					fixed (uint* ptr5 = &register.uint32_0)
					{
						for (int m = 0; m < Count; m++)
						{
							ptr5[m] = (uint)(object)values[m + index];
						}
					}
				}
				else if (typeof(T) == typeof(int))
				{
					fixed (int* ptr6 = &register.int32_0)
					{
						for (int n = 0; n < Count; n++)
						{
							ptr6[n] = (int)(object)values[n + index];
						}
					}
				}
				else if (typeof(T) == typeof(ulong))
				{
					fixed (ulong* ptr7 = &register.uint64_0)
					{
						for (int num = 0; num < Count; num++)
						{
							ptr7[num] = (ulong)(object)values[num + index];
						}
					}
				}
				else if (typeof(T) == typeof(long))
				{
					fixed (long* ptr8 = &register.int64_0)
					{
						for (int num2 = 0; num2 < Count; num2++)
						{
							ptr8[num2] = (long)(object)values[num2 + index];
						}
					}
				}
				else if (typeof(T) == typeof(float))
				{
					fixed (float* ptr9 = &register.single_0)
					{
						for (int num3 = 0; num3 < Count; num3++)
						{
							ptr9[num3] = (float)(object)values[num3 + index];
						}
					}
				}
				else
				{
					if (!(typeof(T) == typeof(double)))
					{
						return;
					}
					fixed (double* ptr10 = &register.double_0)
					{
						for (int num4 = 0; num4 < Count; num4++)
						{
							ptr10[num4] = (double)(object)values[num4 + index];
						}
					}
				}
			}
			else if (typeof(T) == typeof(byte))
			{
				fixed (byte* ptr11 = &register.byte_0)
				{
					*ptr11 = (byte)(object)values[index];
					ptr11[1] = (byte)(object)values[1 + index];
					ptr11[2] = (byte)(object)values[2 + index];
					ptr11[3] = (byte)(object)values[3 + index];
					ptr11[4] = (byte)(object)values[4 + index];
					ptr11[5] = (byte)(object)values[5 + index];
					ptr11[6] = (byte)(object)values[6 + index];
					ptr11[7] = (byte)(object)values[7 + index];
					ptr11[8] = (byte)(object)values[8 + index];
					ptr11[9] = (byte)(object)values[9 + index];
					ptr11[10] = (byte)(object)values[10 + index];
					ptr11[11] = (byte)(object)values[11 + index];
					ptr11[12] = (byte)(object)values[12 + index];
					ptr11[13] = (byte)(object)values[13 + index];
					ptr11[14] = (byte)(object)values[14 + index];
					ptr11[15] = (byte)(object)values[15 + index];
				}
			}
			else if (typeof(T) == typeof(sbyte))
			{
				fixed (sbyte* ptr12 = &register.sbyte_0)
				{
					*ptr12 = (sbyte)(object)values[index];
					ptr12[1] = (sbyte)(object)values[1 + index];
					ptr12[2] = (sbyte)(object)values[2 + index];
					ptr12[3] = (sbyte)(object)values[3 + index];
					ptr12[4] = (sbyte)(object)values[4 + index];
					ptr12[5] = (sbyte)(object)values[5 + index];
					ptr12[6] = (sbyte)(object)values[6 + index];
					ptr12[7] = (sbyte)(object)values[7 + index];
					ptr12[8] = (sbyte)(object)values[8 + index];
					ptr12[9] = (sbyte)(object)values[9 + index];
					ptr12[10] = (sbyte)(object)values[10 + index];
					ptr12[11] = (sbyte)(object)values[11 + index];
					ptr12[12] = (sbyte)(object)values[12 + index];
					ptr12[13] = (sbyte)(object)values[13 + index];
					ptr12[14] = (sbyte)(object)values[14 + index];
					ptr12[15] = (sbyte)(object)values[15 + index];
				}
			}
			else if (typeof(T) == typeof(ushort))
			{
				fixed (ushort* ptr13 = &register.uint16_0)
				{
					*ptr13 = (ushort)(object)values[index];
					ptr13[1] = (ushort)(object)values[1 + index];
					ptr13[2] = (ushort)(object)values[2 + index];
					ptr13[3] = (ushort)(object)values[3 + index];
					ptr13[4] = (ushort)(object)values[4 + index];
					ptr13[5] = (ushort)(object)values[5 + index];
					ptr13[6] = (ushort)(object)values[6 + index];
					ptr13[7] = (ushort)(object)values[7 + index];
				}
			}
			else if (typeof(T) == typeof(short))
			{
				fixed (short* ptr14 = &register.int16_0)
				{
					*ptr14 = (short)(object)values[index];
					ptr14[1] = (short)(object)values[1 + index];
					ptr14[2] = (short)(object)values[2 + index];
					ptr14[3] = (short)(object)values[3 + index];
					ptr14[4] = (short)(object)values[4 + index];
					ptr14[5] = (short)(object)values[5 + index];
					ptr14[6] = (short)(object)values[6 + index];
					ptr14[7] = (short)(object)values[7 + index];
				}
			}
			else if (typeof(T) == typeof(uint))
			{
				fixed (uint* ptr15 = &register.uint32_0)
				{
					*ptr15 = (uint)(object)values[index];
					ptr15[1] = (uint)(object)values[1 + index];
					ptr15[2] = (uint)(object)values[2 + index];
					ptr15[3] = (uint)(object)values[3 + index];
				}
			}
			else if (typeof(T) == typeof(int))
			{
				fixed (int* ptr16 = &register.int32_0)
				{
					*ptr16 = (int)(object)values[index];
					ptr16[1] = (int)(object)values[1 + index];
					ptr16[2] = (int)(object)values[2 + index];
					ptr16[3] = (int)(object)values[3 + index];
				}
			}
			else if (typeof(T) == typeof(ulong))
			{
				fixed (ulong* ptr17 = &register.uint64_0)
				{
					*ptr17 = (ulong)(object)values[index];
					ptr17[1] = (ulong)(object)values[1 + index];
				}
			}
			else if (typeof(T) == typeof(long))
			{
				fixed (long* ptr18 = &register.int64_0)
				{
					*ptr18 = (long)(object)values[index];
					ptr18[1] = (long)(object)values[1 + index];
				}
			}
			else if (typeof(T) == typeof(float))
			{
				fixed (float* ptr19 = &register.single_0)
				{
					*ptr19 = (float)(object)values[index];
					ptr19[1] = (float)(object)values[1 + index];
					ptr19[2] = (float)(object)values[2 + index];
					ptr19[3] = (float)(object)values[3 + index];
				}
			}
			else if (typeof(T) == typeof(double))
			{
				fixed (double* ptr20 = &register.double_0)
				{
					*ptr20 = (double)(object)values[index];
					ptr20[1] = (double)(object)values[1 + index];
				}
			}
		}

		internal unsafe Vector(void* dataPointer)
			: this(dataPointer, 0)
		{
		}

		internal unsafe Vector(void* dataPointer, int offset)
		{
			this = default(Vector<T>);
			if (typeof(T) == typeof(byte))
			{
				byte* ptr = (byte*)dataPointer;
				ptr += offset;
				fixed (byte* ptr2 = &register.byte_0)
				{
					for (int i = 0; i < Count; i++)
					{
						ptr2[i] = ptr[i];
					}
				}
				return;
			}
			if (typeof(T) == typeof(sbyte))
			{
				sbyte* ptr3 = (sbyte*)dataPointer;
				ptr3 += offset;
				fixed (sbyte* ptr4 = &register.sbyte_0)
				{
					for (int j = 0; j < Count; j++)
					{
						ptr4[j] = ptr3[j];
					}
				}
				return;
			}
			if (typeof(T) == typeof(ushort))
			{
				ushort* ptr5 = (ushort*)dataPointer;
				ptr5 += offset;
				fixed (ushort* ptr6 = &register.uint16_0)
				{
					for (int k = 0; k < Count; k++)
					{
						ptr6[k] = ptr5[k];
					}
				}
				return;
			}
			if (typeof(T) == typeof(short))
			{
				short* ptr7 = (short*)dataPointer;
				ptr7 += offset;
				fixed (short* ptr8 = &register.int16_0)
				{
					for (int l = 0; l < Count; l++)
					{
						ptr8[l] = ptr7[l];
					}
				}
				return;
			}
			if (typeof(T) == typeof(uint))
			{
				uint* ptr9 = (uint*)dataPointer;
				ptr9 += offset;
				fixed (uint* ptr10 = &register.uint32_0)
				{
					for (int m = 0; m < Count; m++)
					{
						ptr10[m] = ptr9[m];
					}
				}
				return;
			}
			if (typeof(T) == typeof(int))
			{
				int* ptr11 = (int*)dataPointer;
				ptr11 += offset;
				fixed (int* ptr12 = &register.int32_0)
				{
					for (int n = 0; n < Count; n++)
					{
						ptr12[n] = ptr11[n];
					}
				}
				return;
			}
			if (typeof(T) == typeof(ulong))
			{
				ulong* ptr13 = (ulong*)dataPointer;
				ptr13 += offset;
				fixed (ulong* ptr14 = &register.uint64_0)
				{
					for (int num = 0; num < Count; num++)
					{
						ptr14[num] = ptr13[num];
					}
				}
				return;
			}
			if (typeof(T) == typeof(long))
			{
				long* ptr15 = (long*)dataPointer;
				ptr15 += offset;
				fixed (long* ptr16 = &register.int64_0)
				{
					for (int num2 = 0; num2 < Count; num2++)
					{
						ptr16[num2] = ptr15[num2];
					}
				}
				return;
			}
			if (typeof(T) == typeof(float))
			{
				float* ptr17 = (float*)dataPointer;
				ptr17 += offset;
				fixed (float* ptr18 = &register.single_0)
				{
					for (int num3 = 0; num3 < Count; num3++)
					{
						ptr18[num3] = ptr17[num3];
					}
				}
				return;
			}
			if (typeof(T) == typeof(double))
			{
				double* ptr19 = (double*)dataPointer;
				ptr19 += offset;
				fixed (double* ptr20 = &register.double_0)
				{
					for (int num4 = 0; num4 < Count; num4++)
					{
						ptr20[num4] = ptr19[num4];
					}
				}
				return;
			}
			throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
		}

		private Vector(ref System.Numerics.Register existingRegister)
		{
			register = existingRegister;
		}

		[JitIntrinsic]
		public void CopyTo(T[] destination)
		{
			CopyTo(destination, 0);
		}

		[JitIntrinsic]
		public unsafe void CopyTo(T[] destination, int startIndex)
		{
			if (destination == null)
			{
				throw new NullReferenceException(System.SR.Arg_NullArgumentNullRef);
			}
			if (startIndex < 0 || startIndex >= destination.Length)
			{
				throw new ArgumentOutOfRangeException("startIndex", System.SR.Format(System.SR.Arg_ArgumentOutOfRangeException, startIndex));
			}
			if (destination.Length - startIndex < Count)
			{
				throw new ArgumentException(System.SR.Format(System.SR.Arg_ElementsInSourceIsGreaterThanDestination, startIndex));
			}
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					fixed (byte* ptr = (byte[])(object)destination)
					{
						for (int i = 0; i < Count; i++)
						{
							ptr[startIndex + i] = (byte)(object)this[i];
						}
					}
				}
				else if (typeof(T) == typeof(sbyte))
				{
					fixed (sbyte* ptr2 = (sbyte[])(object)destination)
					{
						for (int j = 0; j < Count; j++)
						{
							ptr2[startIndex + j] = (sbyte)(object)this[j];
						}
					}
				}
				else if (typeof(T) == typeof(ushort))
				{
					fixed (ushort* ptr3 = (ushort[])(object)destination)
					{
						for (int k = 0; k < Count; k++)
						{
							ptr3[startIndex + k] = (ushort)(object)this[k];
						}
					}
				}
				else if (typeof(T) == typeof(short))
				{
					fixed (short* ptr4 = (short[])(object)destination)
					{
						for (int l = 0; l < Count; l++)
						{
							ptr4[startIndex + l] = (short)(object)this[l];
						}
					}
				}
				else if (typeof(T) == typeof(uint))
				{
					fixed (uint* ptr5 = (uint[])(object)destination)
					{
						for (int m = 0; m < Count; m++)
						{
							ptr5[startIndex + m] = (uint)(object)this[m];
						}
					}
				}
				else if (typeof(T) == typeof(int))
				{
					fixed (int* ptr6 = (int[])(object)destination)
					{
						for (int n = 0; n < Count; n++)
						{
							ptr6[startIndex + n] = (int)(object)this[n];
						}
					}
				}
				else if (typeof(T) == typeof(ulong))
				{
					fixed (ulong* ptr7 = (ulong[])(object)destination)
					{
						for (int num = 0; num < Count; num++)
						{
							ptr7[startIndex + num] = (ulong)(object)this[num];
						}
					}
				}
				else if (typeof(T) == typeof(long))
				{
					fixed (long* ptr8 = (long[])(object)destination)
					{
						for (int num2 = 0; num2 < Count; num2++)
						{
							ptr8[startIndex + num2] = (long)(object)this[num2];
						}
					}
				}
				else if (typeof(T) == typeof(float))
				{
					fixed (float* ptr9 = (float[])(object)destination)
					{
						for (int num3 = 0; num3 < Count; num3++)
						{
							ptr9[startIndex + num3] = (float)(object)this[num3];
						}
					}
				}
				else
				{
					if (!(typeof(T) == typeof(double)))
					{
						return;
					}
					fixed (double* ptr10 = (double[])(object)destination)
					{
						for (int num4 = 0; num4 < Count; num4++)
						{
							ptr10[startIndex + num4] = (double)(object)this[num4];
						}
					}
				}
			}
			else if (typeof(T) == typeof(byte))
			{
				fixed (byte* ptr11 = (byte[])(object)destination)
				{
					ptr11[startIndex] = register.byte_0;
					ptr11[startIndex + 1] = register.byte_1;
					ptr11[startIndex + 2] = register.byte_2;
					ptr11[startIndex + 3] = register.byte_3;
					ptr11[startIndex + 4] = register.byte_4;
					ptr11[startIndex + 5] = register.byte_5;
					ptr11[startIndex + 6] = register.byte_6;
					ptr11[startIndex + 7] = register.byte_7;
					ptr11[startIndex + 8] = register.byte_8;
					ptr11[startIndex + 9] = register.byte_9;
					ptr11[startIndex + 10] = register.byte_10;
					ptr11[startIndex + 11] = register.byte_11;
					ptr11[startIndex + 12] = register.byte_12;
					ptr11[startIndex + 13] = register.byte_13;
					ptr11[startIndex + 14] = register.byte_14;
					ptr11[startIndex + 15] = register.byte_15;
				}
			}
			else if (typeof(T) == typeof(sbyte))
			{
				fixed (sbyte* ptr12 = (sbyte[])(object)destination)
				{
					ptr12[startIndex] = register.sbyte_0;
					ptr12[startIndex + 1] = register.sbyte_1;
					ptr12[startIndex + 2] = register.sbyte_2;
					ptr12[startIndex + 3] = register.sbyte_3;
					ptr12[startIndex + 4] = register.sbyte_4;
					ptr12[startIndex + 5] = register.sbyte_5;
					ptr12[startIndex + 6] = register.sbyte_6;
					ptr12[startIndex + 7] = register.sbyte_7;
					ptr12[startIndex + 8] = register.sbyte_8;
					ptr12[startIndex + 9] = register.sbyte_9;
					ptr12[startIndex + 10] = register.sbyte_10;
					ptr12[startIndex + 11] = register.sbyte_11;
					ptr12[startIndex + 12] = register.sbyte_12;
					ptr12[startIndex + 13] = register.sbyte_13;
					ptr12[startIndex + 14] = register.sbyte_14;
					ptr12[startIndex + 15] = register.sbyte_15;
				}
			}
			else if (typeof(T) == typeof(ushort))
			{
				fixed (ushort* ptr13 = (ushort[])(object)destination)
				{
					ptr13[startIndex] = register.uint16_0;
					ptr13[startIndex + 1] = register.uint16_1;
					ptr13[startIndex + 2] = register.uint16_2;
					ptr13[startIndex + 3] = register.uint16_3;
					ptr13[startIndex + 4] = register.uint16_4;
					ptr13[startIndex + 5] = register.uint16_5;
					ptr13[startIndex + 6] = register.uint16_6;
					ptr13[startIndex + 7] = register.uint16_7;
				}
			}
			else if (typeof(T) == typeof(short))
			{
				fixed (short* ptr14 = (short[])(object)destination)
				{
					ptr14[startIndex] = register.int16_0;
					ptr14[startIndex + 1] = register.int16_1;
					ptr14[startIndex + 2] = register.int16_2;
					ptr14[startIndex + 3] = register.int16_3;
					ptr14[startIndex + 4] = register.int16_4;
					ptr14[startIndex + 5] = register.int16_5;
					ptr14[startIndex + 6] = register.int16_6;
					ptr14[startIndex + 7] = register.int16_7;
				}
			}
			else if (typeof(T) == typeof(uint))
			{
				fixed (uint* ptr15 = (uint[])(object)destination)
				{
					ptr15[startIndex] = register.uint32_0;
					ptr15[startIndex + 1] = register.uint32_1;
					ptr15[startIndex + 2] = register.uint32_2;
					ptr15[startIndex + 3] = register.uint32_3;
				}
			}
			else if (typeof(T) == typeof(int))
			{
				fixed (int* ptr16 = (int[])(object)destination)
				{
					ptr16[startIndex] = register.int32_0;
					ptr16[startIndex + 1] = register.int32_1;
					ptr16[startIndex + 2] = register.int32_2;
					ptr16[startIndex + 3] = register.int32_3;
				}
			}
			else if (typeof(T) == typeof(ulong))
			{
				fixed (ulong* ptr17 = (ulong[])(object)destination)
				{
					ptr17[startIndex] = register.uint64_0;
					ptr17[startIndex + 1] = register.uint64_1;
				}
			}
			else if (typeof(T) == typeof(long))
			{
				fixed (long* ptr18 = (long[])(object)destination)
				{
					ptr18[startIndex] = register.int64_0;
					ptr18[startIndex + 1] = register.int64_1;
				}
			}
			else if (typeof(T) == typeof(float))
			{
				fixed (float* ptr19 = (float[])(object)destination)
				{
					ptr19[startIndex] = register.single_0;
					ptr19[startIndex + 1] = register.single_1;
					ptr19[startIndex + 2] = register.single_2;
					ptr19[startIndex + 3] = register.single_3;
				}
			}
			else if (typeof(T) == typeof(double))
			{
				fixed (double* ptr20 = (double[])(object)destination)
				{
					ptr20[startIndex] = register.double_0;
					ptr20[startIndex + 1] = register.double_1;
				}
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public override bool Equals(object obj)
		{
			if (!(obj is Vector<T>))
			{
				return false;
			}
			return Equals((Vector<T>)obj);
		}

		[JitIntrinsic]
		public bool Equals(Vector<T> other)
		{
			if (Vector.IsHardwareAccelerated)
			{
				for (int i = 0; i < Count; i++)
				{
					if (!ScalarEquals(this[i], other[i]))
					{
						return false;
					}
				}
				return true;
			}
			if (typeof(T) == typeof(byte))
			{
				if (register.byte_0 == other.register.byte_0 && register.byte_1 == other.register.byte_1 && register.byte_2 == other.register.byte_2 && register.byte_3 == other.register.byte_3 && register.byte_4 == other.register.byte_4 && register.byte_5 == other.register.byte_5 && register.byte_6 == other.register.byte_6 && register.byte_7 == other.register.byte_7 && register.byte_8 == other.register.byte_8 && register.byte_9 == other.register.byte_9 && register.byte_10 == other.register.byte_10 && register.byte_11 == other.register.byte_11 && register.byte_12 == other.register.byte_12 && register.byte_13 == other.register.byte_13 && register.byte_14 == other.register.byte_14)
				{
					return register.byte_15 == other.register.byte_15;
				}
				return false;
			}
			if (typeof(T) == typeof(sbyte))
			{
				if (register.sbyte_0 == other.register.sbyte_0 && register.sbyte_1 == other.register.sbyte_1 && register.sbyte_2 == other.register.sbyte_2 && register.sbyte_3 == other.register.sbyte_3 && register.sbyte_4 == other.register.sbyte_4 && register.sbyte_5 == other.register.sbyte_5 && register.sbyte_6 == other.register.sbyte_6 && register.sbyte_7 == other.register.sbyte_7 && register.sbyte_8 == other.register.sbyte_8 && register.sbyte_9 == other.register.sbyte_9 && register.sbyte_10 == other.register.sbyte_10 && register.sbyte_11 == other.register.sbyte_11 && register.sbyte_12 == other.register.sbyte_12 && register.sbyte_13 == other.register.sbyte_13 && register.sbyte_14 == other.register.sbyte_14)
				{
					return register.sbyte_15 == other.register.sbyte_15;
				}
				return false;
			}
			if (typeof(T) == typeof(ushort))
			{
				if (register.uint16_0 == other.register.uint16_0 && register.uint16_1 == other.register.uint16_1 && register.uint16_2 == other.register.uint16_2 && register.uint16_3 == other.register.uint16_3 && register.uint16_4 == other.register.uint16_4 && register.uint16_5 == other.register.uint16_5 && register.uint16_6 == other.register.uint16_6)
				{
					return register.uint16_7 == other.register.uint16_7;
				}
				return false;
			}
			if (typeof(T) == typeof(short))
			{
				if (register.int16_0 == other.register.int16_0 && register.int16_1 == other.register.int16_1 && register.int16_2 == other.register.int16_2 && register.int16_3 == other.register.int16_3 && register.int16_4 == other.register.int16_4 && register.int16_5 == other.register.int16_5 && register.int16_6 == other.register.int16_6)
				{
					return register.int16_7 == other.register.int16_7;
				}
				return false;
			}
			if (typeof(T) == typeof(uint))
			{
				if (register.uint32_0 == other.register.uint32_0 && register.uint32_1 == other.register.uint32_1 && register.uint32_2 == other.register.uint32_2)
				{
					return register.uint32_3 == other.register.uint32_3;
				}
				return false;
			}
			if (typeof(T) == typeof(int))
			{
				if (register.int32_0 == other.register.int32_0 && register.int32_1 == other.register.int32_1 && register.int32_2 == other.register.int32_2)
				{
					return register.int32_3 == other.register.int32_3;
				}
				return false;
			}
			if (typeof(T) == typeof(ulong))
			{
				if (register.uint64_0 == other.register.uint64_0)
				{
					return register.uint64_1 == other.register.uint64_1;
				}
				return false;
			}
			if (typeof(T) == typeof(long))
			{
				if (register.int64_0 == other.register.int64_0)
				{
					return register.int64_1 == other.register.int64_1;
				}
				return false;
			}
			if (typeof(T) == typeof(float))
			{
				if (register.single_0 == other.register.single_0 && register.single_1 == other.register.single_1 && register.single_2 == other.register.single_2)
				{
					return register.single_3 == other.register.single_3;
				}
				return false;
			}
			if (typeof(T) == typeof(double))
			{
				if (register.double_0 == other.register.double_0)
				{
					return register.double_1 == other.register.double_1;
				}
				return false;
			}
			throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
		}

		public override int GetHashCode()
		{
			int num = 0;
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					for (int i = 0; i < Count; i++)
					{
						num = HashHelpers.Combine(num, ((byte)(object)this[i]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(sbyte))
				{
					for (int j = 0; j < Count; j++)
					{
						num = HashHelpers.Combine(num, ((sbyte)(object)this[j]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(ushort))
				{
					for (int k = 0; k < Count; k++)
					{
						num = HashHelpers.Combine(num, ((ushort)(object)this[k]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(short))
				{
					for (int l = 0; l < Count; l++)
					{
						num = HashHelpers.Combine(num, ((short)(object)this[l]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(uint))
				{
					for (int m = 0; m < Count; m++)
					{
						num = HashHelpers.Combine(num, ((uint)(object)this[m]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(int))
				{
					for (int n = 0; n < Count; n++)
					{
						num = HashHelpers.Combine(num, ((int)(object)this[n]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(ulong))
				{
					for (int num2 = 0; num2 < Count; num2++)
					{
						num = HashHelpers.Combine(num, ((ulong)(object)this[num2]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(long))
				{
					for (int num3 = 0; num3 < Count; num3++)
					{
						num = HashHelpers.Combine(num, ((long)(object)this[num3]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(float))
				{
					for (int num4 = 0; num4 < Count; num4++)
					{
						num = HashHelpers.Combine(num, ((float)(object)this[num4]).GetHashCode());
					}
					return num;
				}
				if (typeof(T) == typeof(double))
				{
					for (int num5 = 0; num5 < Count; num5++)
					{
						num = HashHelpers.Combine(num, ((double)(object)this[num5]).GetHashCode());
					}
					return num;
				}
				throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
			}
			if (typeof(T) == typeof(byte))
			{
				num = HashHelpers.Combine(num, register.byte_0.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_1.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_2.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_3.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_4.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_5.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_6.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_7.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_8.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_9.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_10.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_11.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_12.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_13.GetHashCode());
				num = HashHelpers.Combine(num, register.byte_14.GetHashCode());
				return HashHelpers.Combine(num, register.byte_15.GetHashCode());
			}
			if (typeof(T) == typeof(sbyte))
			{
				num = HashHelpers.Combine(num, register.sbyte_0.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_1.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_2.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_3.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_4.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_5.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_6.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_7.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_8.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_9.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_10.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_11.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_12.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_13.GetHashCode());
				num = HashHelpers.Combine(num, register.sbyte_14.GetHashCode());
				return HashHelpers.Combine(num, register.sbyte_15.GetHashCode());
			}
			if (typeof(T) == typeof(ushort))
			{
				num = HashHelpers.Combine(num, register.uint16_0.GetHashCode());
				num = HashHelpers.Combine(num, register.uint16_1.GetHashCode());
				num = HashHelpers.Combine(num, register.uint16_2.GetHashCode());
				num = HashHelpers.Combine(num, register.uint16_3.GetHashCode());
				num = HashHelpers.Combine(num, register.uint16_4.GetHashCode());
				num = HashHelpers.Combine(num, register.uint16_5.GetHashCode());
				num = HashHelpers.Combine(num, register.uint16_6.GetHashCode());
				return HashHelpers.Combine(num, register.uint16_7.GetHashCode());
			}
			if (typeof(T) == typeof(short))
			{
				num = HashHelpers.Combine(num, register.int16_0.GetHashCode());
				num = HashHelpers.Combine(num, register.int16_1.GetHashCode());
				num = HashHelpers.Combine(num, register.int16_2.GetHashCode());
				num = HashHelpers.Combine(num, register.int16_3.GetHashCode());
				num = HashHelpers.Combine(num, register.int16_4.GetHashCode());
				num = HashHelpers.Combine(num, register.int16_5.GetHashCode());
				num = HashHelpers.Combine(num, register.int16_6.GetHashCode());
				return HashHelpers.Combine(num, register.int16_7.GetHashCode());
			}
			if (typeof(T) == typeof(uint))
			{
				num = HashHelpers.Combine(num, register.uint32_0.GetHashCode());
				num = HashHelpers.Combine(num, register.uint32_1.GetHashCode());
				num = HashHelpers.Combine(num, register.uint32_2.GetHashCode());
				return HashHelpers.Combine(num, register.uint32_3.GetHashCode());
			}
			if (typeof(T) == typeof(int))
			{
				num = HashHelpers.Combine(num, register.int32_0.GetHashCode());
				num = HashHelpers.Combine(num, register.int32_1.GetHashCode());
				num = HashHelpers.Combine(num, register.int32_2.GetHashCode());
				return HashHelpers.Combine(num, register.int32_3.GetHashCode());
			}
			if (typeof(T) == typeof(ulong))
			{
				num = HashHelpers.Combine(num, register.uint64_0.GetHashCode());
				return HashHelpers.Combine(num, register.uint64_1.GetHashCode());
			}
			if (typeof(T) == typeof(long))
			{
				num = HashHelpers.Combine(num, register.int64_0.GetHashCode());
				return HashHelpers.Combine(num, register.int64_1.GetHashCode());
			}
			if (typeof(T) == typeof(float))
			{
				num = HashHelpers.Combine(num, register.single_0.GetHashCode());
				num = HashHelpers.Combine(num, register.single_1.GetHashCode());
				num = HashHelpers.Combine(num, register.single_2.GetHashCode());
				return HashHelpers.Combine(num, register.single_3.GetHashCode());
			}
			if (typeof(T) == typeof(double))
			{
				num = HashHelpers.Combine(num, register.double_0.GetHashCode());
				return HashHelpers.Combine(num, register.double_1.GetHashCode());
			}
			throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
		}

		public override string ToString()
		{
			return ToString("G", CultureInfo.CurrentCulture);
		}

		public string ToString(string format)
		{
			return ToString(format, CultureInfo.CurrentCulture);
		}

		public string ToString(string format, IFormatProvider formatProvider)
		{
			StringBuilder stringBuilder = new StringBuilder();
			string numberGroupSeparator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
			stringBuilder.Append('<');
			for (int i = 0; i < Count - 1; i++)
			{
				stringBuilder.Append(((IFormattable)(object)this[i]).ToString(format, formatProvider));
				stringBuilder.Append(numberGroupSeparator);
				stringBuilder.Append(' ');
			}
			stringBuilder.Append(((IFormattable)(object)this[Count - 1]).ToString(format, formatProvider));
			stringBuilder.Append('>');
			return stringBuilder.ToString();
		}

		public unsafe static Vector<T>operator +(Vector<T> left, Vector<T> right)
		{
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					byte* ptr = stackalloc byte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int i = 0; i < Count; i++)
					{
						ptr[i] = (byte)(object)ScalarAdd(left[i], right[i]);
					}
					return new Vector<T>(ptr);
				}
				if (typeof(T) == typeof(sbyte))
				{
					sbyte* ptr2 = stackalloc sbyte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int j = 0; j < Count; j++)
					{
						ptr2[j] = (sbyte)(object)ScalarAdd(left[j], right[j]);
					}
					return new Vector<T>(ptr2);
				}
				if (typeof(T) == typeof(ushort))
				{
					ushort* ptr3 = stackalloc ushort[Count];
					for (int k = 0; k < Count; k++)
					{
						ptr3[k] = (ushort)(object)ScalarAdd(left[k], right[k]);
					}
					return new Vector<T>(ptr3);
				}
				if (typeof(T) == typeof(short))
				{
					short* ptr4 = stackalloc short[Count];
					for (int l = 0; l < Count; l++)
					{
						ptr4[l] = (short)(object)ScalarAdd(left[l], right[l]);
					}
					return new Vector<T>(ptr4);
				}
				if (typeof(T) == typeof(uint))
				{
					uint* ptr5 = stackalloc uint[Count];
					for (int m = 0; m < Count; m++)
					{
						ptr5[m] = (uint)(object)ScalarAdd(left[m], right[m]);
					}
					return new Vector<T>(ptr5);
				}
				if (typeof(T) == typeof(int))
				{
					int* ptr6 = stackalloc int[Count];
					for (int n = 0; n < Count; n++)
					{
						ptr6[n] = (int)(object)ScalarAdd(left[n], right[n]);
					}
					return new Vector<T>(ptr6);
				}
				if (typeof(T) == typeof(ulong))
				{
					ulong* ptr7 = stackalloc ulong[Count];
					for (int num = 0; num < Count; num++)
					{
						ptr7[num] = (ulong)(object)ScalarAdd(left[num], right[num]);
					}
					return new Vector<T>(ptr7);
				}
				if (typeof(T) == typeof(long))
				{
					long* ptr8 = stackalloc long[Count];
					for (int num2 = 0; num2 < Count; num2++)
					{
						ptr8[num2] = (long)(object)ScalarAdd(left[num2], right[num2]);
					}
					return new Vector<T>(ptr8);
				}
				if (typeof(T) == typeof(float))
				{
					float* ptr9 = stackalloc float[Count];
					for (int num3 = 0; num3 < Count; num3++)
					{
						ptr9[num3] = (float)(object)ScalarAdd(left[num3], right[num3]);
					}
					return new Vector<T>(ptr9);
				}
				if (typeof(T) == typeof(double))
				{
					double* ptr10 = stackalloc double[Count];
					for (int num4 = 0; num4 < Count; num4++)
					{
						ptr10[num4] = (double)(object)ScalarAdd(left[num4], right[num4]);
					}
					return new Vector<T>(ptr10);
				}
				throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
			}
			Vector<T> result = default(Vector<T>);
			if (typeof(T) == typeof(byte))
			{
				result.register.byte_0 = (byte)(left.register.byte_0 + right.register.byte_0);
				result.register.byte_1 = (byte)(left.register.byte_1 + right.register.byte_1);
				result.register.byte_2 = (byte)(left.register.byte_2 + right.register.byte_2);
				result.register.byte_3 = (byte)(left.register.byte_3 + right.register.byte_3);
				result.register.byte_4 = (byte)(left.register.byte_4 + right.register.byte_4);
				result.register.byte_5 = (byte)(left.register.byte_5 + right.register.byte_5);
				result.register.byte_6 = (byte)(left.register.byte_6 + right.register.byte_6);
				result.register.byte_7 = (byte)(left.register.byte_7 + right.register.byte_7);
				result.register.byte_8 = (byte)(left.register.byte_8 + right.register.byte_8);
				result.register.byte_9 = (byte)(left.register.byte_9 + right.register.byte_9);
				result.register.byte_10 = (byte)(left.register.byte_10 + right.register.byte_10);
				result.register.byte_11 = (byte)(left.register.byte_11 + right.register.byte_11);
				result.register.byte_12 = (byte)(left.register.byte_12 + right.register.byte_12);
				result.register.byte_13 = (byte)(left.register.byte_13 + right.register.byte_13);
				result.register.byte_14 = (byte)(left.register.byte_14 + right.register.byte_14);
				result.register.byte_15 = (byte)(left.register.byte_15 + right.register.byte_15);
			}
			else if (typeof(T) == typeof(sbyte))
			{
				result.register.sbyte_0 = (sbyte)(left.register.sbyte_0 + right.register.sbyte_0);
				result.register.sbyte_1 = (sbyte)(left.register.sbyte_1 + right.register.sbyte_1);
				result.register.sbyte_2 = (sbyte)(left.register.sbyte_2 + right.register.sbyte_2);
				result.register.sbyte_3 = (sbyte)(left.register.sbyte_3 + right.register.sbyte_3);
				result.register.sbyte_4 = (sbyte)(left.register.sbyte_4 + right.register.sbyte_4);
				result.register.sbyte_5 = (sbyte)(left.register.sbyte_5 + right.register.sbyte_5);
				result.register.sbyte_6 = (sbyte)(left.register.sbyte_6 + right.register.sbyte_6);
				result.register.sbyte_7 = (sbyte)(left.register.sbyte_7 + right.register.sbyte_7);
				result.register.sbyte_8 = (sbyte)(left.register.sbyte_8 + right.register.sbyte_8);
				result.register.sbyte_9 = (sbyte)(left.register.sbyte_9 + right.register.sbyte_9);
				result.register.sbyte_10 = (sbyte)(left.register.sbyte_10 + right.register.sbyte_10);
				result.register.sbyte_11 = (sbyte)(left.register.sbyte_11 + right.register.sbyte_11);
				result.register.sbyte_12 = (sbyte)(left.register.sbyte_12 + right.register.sbyte_12);
				result.register.sbyte_13 = (sbyte)(left.register.sbyte_13 + right.register.sbyte_13);
				result.register.sbyte_14 = (sbyte)(left.register.sbyte_14 + right.register.sbyte_14);
				result.register.sbyte_15 = (sbyte)(left.register.sbyte_15 + right.register.sbyte_15);
			}
			else if (typeof(T) == typeof(ushort))
			{
				result.register.uint16_0 = (ushort)(left.register.uint16_0 + right.register.uint16_0);
				result.register.uint16_1 = (ushort)(left.register.uint16_1 + right.register.uint16_1);
				result.register.uint16_2 = (ushort)(left.register.uint16_2 + right.register.uint16_2);
				result.register.uint16_3 = (ushort)(left.register.uint16_3 + right.register.uint16_3);
				result.register.uint16_4 = (ushort)(left.register.uint16_4 + right.register.uint16_4);
				result.register.uint16_5 = (ushort)(left.register.uint16_5 + right.register.uint16_5);
				result.register.uint16_6 = (ushort)(left.register.uint16_6 + right.register.uint16_6);
				result.register.uint16_7 = (ushort)(left.register.uint16_7 + right.register.uint16_7);
			}
			else if (typeof(T) == typeof(short))
			{
				result.register.int16_0 = (short)(left.register.int16_0 + right.register.int16_0);
				result.register.int16_1 = (short)(left.register.int16_1 + right.register.int16_1);
				result.register.int16_2 = (short)(left.register.int16_2 + right.register.int16_2);
				result.register.int16_3 = (short)(left.register.int16_3 + right.register.int16_3);
				result.register.int16_4 = (short)(left.register.int16_4 + right.register.int16_4);
				result.register.int16_5 = (short)(left.register.int16_5 + right.register.int16_5);
				result.register.int16_6 = (short)(left.register.int16_6 + right.register.int16_6);
				result.register.int16_7 = (short)(left.register.int16_7 + right.register.int16_7);
			}
			else if (typeof(T) == typeof(uint))
			{
				result.register.uint32_0 = left.register.uint32_0 + right.register.uint32_0;
				result.register.uint32_1 = left.register.uint32_1 + right.register.uint32_1;
				result.register.uint32_2 = left.register.uint32_2 + right.register.uint32_2;
				result.register.uint32_3 = left.register.uint32_3 + right.register.uint32_3;
			}
			else if (typeof(T) == typeof(int))
			{
				result.register.int32_0 = left.register.int32_0 + right.register.int32_0;
				result.register.int32_1 = left.register.int32_1 + right.register.int32_1;
				result.register.int32_2 = left.register.int32_2 + right.register.int32_2;
				result.register.int32_3 = left.register.int32_3 + right.register.int32_3;
			}
			else if (typeof(T) == typeof(ulong))
			{
				result.register.uint64_0 = left.register.uint64_0 + right.register.uint64_0;
				result.register.uint64_1 = left.register.uint64_1 + right.register.uint64_1;
			}
			else if (typeof(T) == typeof(long))
			{
				result.register.int64_0 = left.register.int64_0 + right.register.int64_0;
				result.register.int64_1 = left.register.int64_1 + right.register.int64_1;
			}
			else if (typeof(T) == typeof(float))
			{
				result.register.single_0 = left.register.single_0 + right.register.single_0;
				result.register.single_1 = left.register.single_1 + right.register.single_1;
				result.register.single_2 = left.register.single_2 + right.register.single_2;
				result.register.single_3 = left.register.single_3 + right.register.single_3;
			}
			else if (typeof(T) == typeof(double))
			{
				result.register.double_0 = left.register.double_0 + right.register.double_0;
				result.register.double_1 = left.register.double_1 + right.register.double_1;
			}
			return result;
		}

		public unsafe static Vector<T>operator -(Vector<T> left, Vector<T> right)
		{
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					byte* ptr = stackalloc byte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int i = 0; i < Count; i++)
					{
						ptr[i] = (byte)(object)ScalarSubtract(left[i], right[i]);
					}
					return new Vector<T>(ptr);
				}
				if (typeof(T) == typeof(sbyte))
				{
					sbyte* ptr2 = stackalloc sbyte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int j = 0; j < Count; j++)
					{
						ptr2[j] = (sbyte)(object)ScalarSubtract(left[j], right[j]);
					}
					return new Vector<T>(ptr2);
				}
				if (typeof(T) == typeof(ushort))
				{
					ushort* ptr3 = stackalloc ushort[Count];
					for (int k = 0; k < Count; k++)
					{
						ptr3[k] = (ushort)(object)ScalarSubtract(left[k], right[k]);
					}
					return new Vector<T>(ptr3);
				}
				if (typeof(T) == typeof(short))
				{
					short* ptr4 = stackalloc short[Count];
					for (int l = 0; l < Count; l++)
					{
						ptr4[l] = (short)(object)ScalarSubtract(left[l], right[l]);
					}
					return new Vector<T>(ptr4);
				}
				if (typeof(T) == typeof(uint))
				{
					uint* ptr5 = stackalloc uint[Count];
					for (int m = 0; m < Count; m++)
					{
						ptr5[m] = (uint)(object)ScalarSubtract(left[m], right[m]);
					}
					return new Vector<T>(ptr5);
				}
				if (typeof(T) == typeof(int))
				{
					int* ptr6 = stackalloc int[Count];
					for (int n = 0; n < Count; n++)
					{
						ptr6[n] = (int)(object)ScalarSubtract(left[n], right[n]);
					}
					return new Vector<T>(ptr6);
				}
				if (typeof(T) == typeof(ulong))
				{
					ulong* ptr7 = stackalloc ulong[Count];
					for (int num = 0; num < Count; num++)
					{
						ptr7[num] = (ulong)(object)ScalarSubtract(left[num], right[num]);
					}
					return new Vector<T>(ptr7);
				}
				if (typeof(T) == typeof(long))
				{
					long* ptr8 = stackalloc long[Count];
					for (int num2 = 0; num2 < Count; num2++)
					{
						ptr8[num2] = (long)(object)ScalarSubtract(left[num2], right[num2]);
					}
					return new Vector<T>(ptr8);
				}
				if (typeof(T) == typeof(float))
				{
					float* ptr9 = stackalloc float[Count];
					for (int num3 = 0; num3 < Count; num3++)
					{
						ptr9[num3] = (float)(object)ScalarSubtract(left[num3], right[num3]);
					}
					return new Vector<T>(ptr9);
				}
				if (typeof(T) == typeof(double))
				{
					double* ptr10 = stackalloc double[Count];
					for (int num4 = 0; num4 < Count; num4++)
					{
						ptr10[num4] = (double)(object)ScalarSubtract(left[num4], right[num4]);
					}
					return new Vector<T>(ptr10);
				}
				throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
			}
			Vector<T> result = default(Vector<T>);
			if (typeof(T) == typeof(byte))
			{
				result.register.byte_0 = (byte)(left.register.byte_0 - right.register.byte_0);
				result.register.byte_1 = (byte)(left.register.byte_1 - right.register.byte_1);
				result.register.byte_2 = (byte)(left.register.byte_2 - right.register.byte_2);
				result.register.byte_3 = (byte)(left.register.byte_3 - right.register.byte_3);
				result.register.byte_4 = (byte)(left.register.byte_4 - right.register.byte_4);
				result.register.byte_5 = (byte)(left.register.byte_5 - right.register.byte_5);
				result.register.byte_6 = (byte)(left.register.byte_6 - right.register.byte_6);
				result.register.byte_7 = (byte)(left.register.byte_7 - right.register.byte_7);
				result.register.byte_8 = (byte)(left.register.byte_8 - right.register.byte_8);
				result.register.byte_9 = (byte)(left.register.byte_9 - right.register.byte_9);
				result.register.byte_10 = (byte)(left.register.byte_10 - right.register.byte_10);
				result.register.byte_11 = (byte)(left.register.byte_11 - right.register.byte_11);
				result.register.byte_12 = (byte)(left.register.byte_12 - right.register.byte_12);
				result.register.byte_13 = (byte)(left.register.byte_13 - right.register.byte_13);
				result.register.byte_14 = (byte)(left.register.byte_14 - right.register.byte_14);
				result.register.byte_15 = (byte)(left.register.byte_15 - right.register.byte_15);
			}
			else if (typeof(T) == typeof(sbyte))
			{
				result.register.sbyte_0 = (sbyte)(left.register.sbyte_0 - right.register.sbyte_0);
				result.register.sbyte_1 = (sbyte)(left.register.sbyte_1 - right.register.sbyte_1);
				result.register.sbyte_2 = (sbyte)(left.register.sbyte_2 - right.register.sbyte_2);
				result.register.sbyte_3 = (sbyte)(left.register.sbyte_3 - right.register.sbyte_3);
				result.register.sbyte_4 = (sbyte)(left.register.sbyte_4 - right.register.sbyte_4);
				result.register.sbyte_5 = (sbyte)(left.register.sbyte_5 - right.register.sbyte_5);
				result.register.sbyte_6 = (sbyte)(left.register.sbyte_6 - right.register.sbyte_6);
				result.register.sbyte_7 = (sbyte)(left.register.sbyte_7 - right.register.sbyte_7);
				result.register.sbyte_8 = (sbyte)(left.register.sbyte_8 - right.register.sbyte_8);
				result.register.sbyte_9 = (sbyte)(left.register.sbyte_9 - right.register.sbyte_9);
				result.register.sbyte_10 = (sbyte)(left.register.sbyte_10 - right.register.sbyte_10);
				result.register.sbyte_11 = (sbyte)(left.register.sbyte_11 - right.register.sbyte_11);
				result.register.sbyte_12 = (sbyte)(left.register.sbyte_12 - right.register.sbyte_12);
				result.register.sbyte_13 = (sbyte)(left.register.sbyte_13 - right.register.sbyte_13);
				result.register.sbyte_14 = (sbyte)(left.register.sbyte_14 - right.register.sbyte_14);
				result.register.sbyte_15 = (sbyte)(left.register.sbyte_15 - right.register.sbyte_15);
			}
			else if (typeof(T) == typeof(ushort))
			{
				result.register.uint16_0 = (ushort)(left.register.uint16_0 - right.register.uint16_0);
				result.register.uint16_1 = (ushort)(left.register.uint16_1 - right.register.uint16_1);
				result.register.uint16_2 = (ushort)(left.register.uint16_2 - right.register.uint16_2);
				result.register.uint16_3 = (ushort)(left.register.uint16_3 - right.register.uint16_3);
				result.register.uint16_4 = (ushort)(left.register.uint16_4 - right.register.uint16_4);
				result.register.uint16_5 = (ushort)(left.register.uint16_5 - right.register.uint16_5);
				result.register.uint16_6 = (ushort)(left.register.uint16_6 - right.register.uint16_6);
				result.register.uint16_7 = (ushort)(left.register.uint16_7 - right.register.uint16_7);
			}
			else if (typeof(T) == typeof(short))
			{
				result.register.int16_0 = (short)(left.register.int16_0 - right.register.int16_0);
				result.register.int16_1 = (short)(left.register.int16_1 - right.register.int16_1);
				result.register.int16_2 = (short)(left.register.int16_2 - right.register.int16_2);
				result.register.int16_3 = (short)(left.register.int16_3 - right.register.int16_3);
				result.register.int16_4 = (short)(left.register.int16_4 - right.register.int16_4);
				result.register.int16_5 = (short)(left.register.int16_5 - right.register.int16_5);
				result.register.int16_6 = (short)(left.register.int16_6 - right.register.int16_6);
				result.register.int16_7 = (short)(left.register.int16_7 - right.register.int16_7);
			}
			else if (typeof(T) == typeof(uint))
			{
				result.register.uint32_0 = left.register.uint32_0 - right.register.uint32_0;
				result.register.uint32_1 = left.register.uint32_1 - right.register.uint32_1;
				result.register.uint32_2 = left.register.uint32_2 - right.register.uint32_2;
				result.register.uint32_3 = left.register.uint32_3 - right.register.uint32_3;
			}
			else if (typeof(T) == typeof(int))
			{
				result.register.int32_0 = left.register.int32_0 - right.register.int32_0;
				result.register.int32_1 = left.register.int32_1 - right.register.int32_1;
				result.register.int32_2 = left.register.int32_2 - right.register.int32_2;
				result.register.int32_3 = left.register.int32_3 - right.register.int32_3;
			}
			else if (typeof(T) == typeof(ulong))
			{
				result.register.uint64_0 = left.register.uint64_0 - right.register.uint64_0;
				result.register.uint64_1 = left.register.uint64_1 - right.register.uint64_1;
			}
			else if (typeof(T) == typeof(long))
			{
				result.register.int64_0 = left.register.int64_0 - right.register.int64_0;
				result.register.int64_1 = left.register.int64_1 - right.register.int64_1;
			}
			else if (typeof(T) == typeof(float))
			{
				result.register.single_0 = left.register.single_0 - right.register.single_0;
				result.register.single_1 = left.register.single_1 - right.register.single_1;
				result.register.single_2 = left.register.single_2 - right.register.single_2;
				result.register.single_3 = left.register.single_3 - right.register.single_3;
			}
			else if (typeof(T) == typeof(double))
			{
				result.register.double_0 = left.register.double_0 - right.register.double_0;
				result.register.double_1 = left.register.double_1 - right.register.double_1;
			}
			return result;
		}

		public unsafe static Vector<T>operator *(Vector<T> left, Vector<T> right)
		{
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					byte* ptr = stackalloc byte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int i = 0; i < Count; i++)
					{
						ptr[i] = (byte)(object)ScalarMultiply(left[i], right[i]);
					}
					return new Vector<T>(ptr);
				}
				if (typeof(T) == typeof(sbyte))
				{
					sbyte* ptr2 = stackalloc sbyte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int j = 0; j < Count; j++)
					{
						ptr2[j] = (sbyte)(object)ScalarMultiply(left[j], right[j]);
					}
					return new Vector<T>(ptr2);
				}
				if (typeof(T) == typeof(ushort))
				{
					ushort* ptr3 = stackalloc ushort[Count];
					for (int k = 0; k < Count; k++)
					{
						ptr3[k] = (ushort)(object)ScalarMultiply(left[k], right[k]);
					}
					return new Vector<T>(ptr3);
				}
				if (typeof(T) == typeof(short))
				{
					short* ptr4 = stackalloc short[Count];
					for (int l = 0; l < Count; l++)
					{
						ptr4[l] = (short)(object)ScalarMultiply(left[l], right[l]);
					}
					return new Vector<T>(ptr4);
				}
				if (typeof(T) == typeof(uint))
				{
					uint* ptr5 = stackalloc uint[Count];
					for (int m = 0; m < Count; m++)
					{
						ptr5[m] = (uint)(object)ScalarMultiply(left[m], right[m]);
					}
					return new Vector<T>(ptr5);
				}
				if (typeof(T) == typeof(int))
				{
					int* ptr6 = stackalloc int[Count];
					for (int n = 0; n < Count; n++)
					{
						ptr6[n] = (int)(object)ScalarMultiply(left[n], right[n]);
					}
					return new Vector<T>(ptr6);
				}
				if (typeof(T) == typeof(ulong))
				{
					ulong* ptr7 = stackalloc ulong[Count];
					for (int num = 0; num < Count; num++)
					{
						ptr7[num] = (ulong)(object)ScalarMultiply(left[num], right[num]);
					}
					return new Vector<T>(ptr7);
				}
				if (typeof(T) == typeof(long))
				{
					long* ptr8 = stackalloc long[Count];
					for (int num2 = 0; num2 < Count; num2++)
					{
						ptr8[num2] = (long)(object)ScalarMultiply(left[num2], right[num2]);
					}
					return new Vector<T>(ptr8);
				}
				if (typeof(T) == typeof(float))
				{
					float* ptr9 = stackalloc float[Count];
					for (int num3 = 0; num3 < Count; num3++)
					{
						ptr9[num3] = (float)(object)ScalarMultiply(left[num3], right[num3]);
					}
					return new Vector<T>(ptr9);
				}
				if (typeof(T) == typeof(double))
				{
					double* ptr10 = stackalloc double[Count];
					for (int num4 = 0; num4 < Count; num4++)
					{
						ptr10[num4] = (double)(object)ScalarMultiply(left[num4], right[num4]);
					}
					return new Vector<T>(ptr10);
				}
				throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
			}
			Vector<T> result = default(Vector<T>);
			if (typeof(T) == typeof(byte))
			{
				result.register.byte_0 = (byte)(left.register.byte_0 * right.register.byte_0);
				result.register.byte_1 = (byte)(left.register.byte_1 * right.register.byte_1);
				result.register.byte_2 = (byte)(left.register.byte_2 * right.register.byte_2);
				result.register.byte_3 = (byte)(left.register.byte_3 * right.register.byte_3);
				result.register.byte_4 = (byte)(left.register.byte_4 * right.register.byte_4);
				result.register.byte_5 = (byte)(left.register.byte_5 * right.register.byte_5);
				result.register.byte_6 = (byte)(left.register.byte_6 * right.register.byte_6);
				result.register.byte_7 = (byte)(left.register.byte_7 * right.register.byte_7);
				result.register.byte_8 = (byte)(left.register.byte_8 * right.register.byte_8);
				result.register.byte_9 = (byte)(left.register.byte_9 * right.register.byte_9);
				result.register.byte_10 = (byte)(left.register.byte_10 * right.register.byte_10);
				result.register.byte_11 = (byte)(left.register.byte_11 * right.register.byte_11);
				result.register.byte_12 = (byte)(left.register.byte_12 * right.register.byte_12);
				result.register.byte_13 = (byte)(left.register.byte_13 * right.register.byte_13);
				result.register.byte_14 = (byte)(left.register.byte_14 * right.register.byte_14);
				result.register.byte_15 = (byte)(left.register.byte_15 * right.register.byte_15);
			}
			else if (typeof(T) == typeof(sbyte))
			{
				result.register.sbyte_0 = (sbyte)(left.register.sbyte_0 * right.register.sbyte_0);
				result.register.sbyte_1 = (sbyte)(left.register.sbyte_1 * right.register.sbyte_1);
				result.register.sbyte_2 = (sbyte)(left.register.sbyte_2 * right.register.sbyte_2);
				result.register.sbyte_3 = (sbyte)(left.register.sbyte_3 * right.register.sbyte_3);
				result.register.sbyte_4 = (sbyte)(left.register.sbyte_4 * right.register.sbyte_4);
				result.register.sbyte_5 = (sbyte)(left.register.sbyte_5 * right.register.sbyte_5);
				result.register.sbyte_6 = (sbyte)(left.register.sbyte_6 * right.register.sbyte_6);
				result.register.sbyte_7 = (sbyte)(left.register.sbyte_7 * right.register.sbyte_7);
				result.register.sbyte_8 = (sbyte)(left.register.sbyte_8 * right.register.sbyte_8);
				result.register.sbyte_9 = (sbyte)(left.register.sbyte_9 * right.register.sbyte_9);
				result.register.sbyte_10 = (sbyte)(left.register.sbyte_10 * right.register.sbyte_10);
				result.register.sbyte_11 = (sbyte)(left.register.sbyte_11 * right.register.sbyte_11);
				result.register.sbyte_12 = (sbyte)(left.register.sbyte_12 * right.register.sbyte_12);
				result.register.sbyte_13 = (sbyte)(left.register.sbyte_13 * right.register.sbyte_13);
				result.register.sbyte_14 = (sbyte)(left.register.sbyte_14 * right.register.sbyte_14);
				result.register.sbyte_15 = (sbyte)(left.register.sbyte_15 * right.register.sbyte_15);
			}
			else if (typeof(T) == typeof(ushort))
			{
				result.register.uint16_0 = (ushort)(left.register.uint16_0 * right.register.uint16_0);
				result.register.uint16_1 = (ushort)(left.register.uint16_1 * right.register.uint16_1);
				result.register.uint16_2 = (ushort)(left.register.uint16_2 * right.register.uint16_2);
				result.register.uint16_3 = (ushort)(left.register.uint16_3 * right.register.uint16_3);
				result.register.uint16_4 = (ushort)(left.register.uint16_4 * right.register.uint16_4);
				result.register.uint16_5 = (ushort)(left.register.uint16_5 * right.register.uint16_5);
				result.register.uint16_6 = (ushort)(left.register.uint16_6 * right.register.uint16_6);
				result.register.uint16_7 = (ushort)(left.register.uint16_7 * right.register.uint16_7);
			}
			else if (typeof(T) == typeof(short))
			{
				result.register.int16_0 = (short)(left.register.int16_0 * right.register.int16_0);
				result.register.int16_1 = (short)(left.register.int16_1 * right.register.int16_1);
				result.register.int16_2 = (short)(left.register.int16_2 * right.register.int16_2);
				result.register.int16_3 = (short)(left.register.int16_3 * right.register.int16_3);
				result.register.int16_4 = (short)(left.register.int16_4 * right.register.int16_4);
				result.register.int16_5 = (short)(left.register.int16_5 * right.register.int16_5);
				result.register.int16_6 = (short)(left.register.int16_6 * right.register.int16_6);
				result.register.int16_7 = (short)(left.register.int16_7 * right.register.int16_7);
			}
			else if (typeof(T) == typeof(uint))
			{
				result.register.uint32_0 = left.register.uint32_0 * right.register.uint32_0;
				result.register.uint32_1 = left.register.uint32_1 * right.register.uint32_1;
				result.register.uint32_2 = left.register.uint32_2 * right.register.uint32_2;
				result.register.uint32_3 = left.register.uint32_3 * right.register.uint32_3;
			}
			else if (typeof(T) == typeof(int))
			{
				result.register.int32_0 = left.register.int32_0 * right.register.int32_0;
				result.register.int32_1 = left.register.int32_1 * right.register.int32_1;
				result.register.int32_2 = left.register.int32_2 * right.register.int32_2;
				result.register.int32_3 = left.register.int32_3 * right.register.int32_3;
			}
			else if (typeof(T) == typeof(ulong))
			{
				result.register.uint64_0 = left.register.uint64_0 * right.register.uint64_0;
				result.register.uint64_1 = left.register.uint64_1 * right.register.uint64_1;
			}
			else if (typeof(T) == typeof(long))
			{
				result.register.int64_0 = left.register.int64_0 * right.register.int64_0;
				result.register.int64_1 = left.register.int64_1 * right.register.int64_1;
			}
			else if (typeof(T) == typeof(float))
			{
				result.register.single_0 = left.register.single_0 * right.register.single_0;
				result.register.single_1 = left.register.single_1 * right.register.single_1;
				result.register.single_2 = left.register.single_2 * right.register.single_2;
				result.register.single_3 = left.register.single_3 * right.register.single_3;
			}
			else if (typeof(T) == typeof(double))
			{
				result.register.double_0 = left.register.double_0 * right.register.double_0;
				result.register.double_1 = left.register.double_1 * right.register.double_1;
			}
			return result;
		}

		public static Vector<T>operator *(Vector<T> value, T factor)
		{
			if (Vector.IsHardwareAccelerated)
			{
				return new Vector<T>(factor) * value;
			}
			Vector<T> result = default(Vector<T>);
			if (typeof(T) == typeof(byte))
			{
				result.register.byte_0 = (byte)(value.register.byte_0 * (byte)(object)factor);
				result.register.byte_1 = (byte)(value.register.byte_1 * (byte)(object)factor);
				result.register.byte_2 = (byte)(value.register.byte_2 * (byte)(object)factor);
				result.register.byte_3 = (byte)(value.register.byte_3 * (byte)(object)factor);
				result.register.byte_4 = (byte)(value.register.byte_4 * (byte)(object)factor);
				result.register.byte_5 = (byte)(value.register.byte_5 * (byte)(object)factor);
				result.register.byte_6 = (byte)(value.register.byte_6 * (byte)(object)factor);
				result.register.byte_7 = (byte)(value.register.byte_7 * (byte)(object)factor);
				result.register.byte_8 = (byte)(value.register.byte_8 * (byte)(object)factor);
				result.register.byte_9 = (byte)(value.register.byte_9 * (byte)(object)factor);
				result.register.byte_10 = (byte)(value.register.byte_10 * (byte)(object)factor);
				result.register.byte_11 = (byte)(value.register.byte_11 * (byte)(object)factor);
				result.register.byte_12 = (byte)(value.register.byte_12 * (byte)(object)factor);
				result.register.byte_13 = (byte)(value.register.byte_13 * (byte)(object)factor);
				result.register.byte_14 = (byte)(value.register.byte_14 * (byte)(object)factor);
				result.register.byte_15 = (byte)(value.register.byte_15 * (byte)(object)factor);
			}
			else if (typeof(T) == typeof(sbyte))
			{
				result.register.sbyte_0 = (sbyte)(value.register.sbyte_0 * (sbyte)(object)factor);
				result.register.sbyte_1 = (sbyte)(value.register.sbyte_1 * (sbyte)(object)factor);
				result.register.sbyte_2 = (sbyte)(value.register.sbyte_2 * (sbyte)(object)factor);
				result.register.sbyte_3 = (sbyte)(value.register.sbyte_3 * (sbyte)(object)factor);
				result.register.sbyte_4 = (sbyte)(value.register.sbyte_4 * (sbyte)(object)factor);
				result.register.sbyte_5 = (sbyte)(value.register.sbyte_5 * (sbyte)(object)factor);
				result.register.sbyte_6 = (sbyte)(value.register.sbyte_6 * (sbyte)(object)factor);
				result.register.sbyte_7 = (sbyte)(value.register.sbyte_7 * (sbyte)(object)factor);
				result.register.sbyte_8 = (sbyte)(value.register.sbyte_8 * (sbyte)(object)factor);
				result.register.sbyte_9 = (sbyte)(value.register.sbyte_9 * (sbyte)(object)factor);
				result.register.sbyte_10 = (sbyte)(value.register.sbyte_10 * (sbyte)(object)factor);
				result.register.sbyte_11 = (sbyte)(value.register.sbyte_11 * (sbyte)(object)factor);
				result.register.sbyte_12 = (sbyte)(value.register.sbyte_12 * (sbyte)(object)factor);
				result.register.sbyte_13 = (sbyte)(value.register.sbyte_13 * (sbyte)(object)factor);
				result.register.sbyte_14 = (sbyte)(value.register.sbyte_14 * (sbyte)(object)factor);
				result.register.sbyte_15 = (sbyte)(value.register.sbyte_15 * (sbyte)(object)factor);
			}
			else if (typeof(T) == typeof(ushort))
			{
				result.register.uint16_0 = (ushort)(value.register.uint16_0 * (ushort)(object)factor);
				result.register.uint16_1 = (ushort)(value.register.uint16_1 * (ushort)(object)factor);
				result.register.uint16_2 = (ushort)(value.register.uint16_2 * (ushort)(object)factor);
				result.register.uint16_3 = (ushort)(value.register.uint16_3 * (ushort)(object)factor);
				result.register.uint16_4 = (ushort)(value.register.uint16_4 * (ushort)(object)factor);
				result.register.uint16_5 = (ushort)(value.register.uint16_5 * (ushort)(object)factor);
				result.register.uint16_6 = (ushort)(value.register.uint16_6 * (ushort)(object)factor);
				result.register.uint16_7 = (ushort)(value.register.uint16_7 * (ushort)(object)factor);
			}
			else if (typeof(T) == typeof(short))
			{
				result.register.int16_0 = (short)(value.register.int16_0 * (short)(object)factor);
				result.register.int16_1 = (short)(value.register.int16_1 * (short)(object)factor);
				result.register.int16_2 = (short)(value.register.int16_2 * (short)(object)factor);
				result.register.int16_3 = (short)(value.register.int16_3 * (short)(object)factor);
				result.register.int16_4 = (short)(value.register.int16_4 * (short)(object)factor);
				result.register.int16_5 = (short)(value.register.int16_5 * (short)(object)factor);
				result.register.int16_6 = (short)(value.register.int16_6 * (short)(object)factor);
				result.register.int16_7 = (short)(value.register.int16_7 * (short)(object)factor);
			}
			else if (typeof(T) == typeof(uint))
			{
				result.register.uint32_0 = value.register.uint32_0 * (uint)(object)factor;
				result.register.uint32_1 = value.register.uint32_1 * (uint)(object)factor;
				result.register.uint32_2 = value.register.uint32_2 * (uint)(object)factor;
				result.register.uint32_3 = value.register.uint32_3 * (uint)(object)factor;
			}
			else if (typeof(T) == typeof(int))
			{
				result.register.int32_0 = value.register.int32_0 * (int)(object)factor;
				result.register.int32_1 = value.register.int32_1 * (int)(object)factor;
				result.register.int32_2 = value.register.int32_2 * (int)(object)factor;
				result.register.int32_3 = value.register.int32_3 * (int)(object)factor;
			}
			else if (typeof(T) == typeof(ulong))
			{
				result.register.uint64_0 = value.register.uint64_0 * (ulong)(object)factor;
				result.register.uint64_1 = value.register.uint64_1 * (ulong)(object)factor;
			}
			else if (typeof(T) == typeof(long))
			{
				result.register.int64_0 = value.register.int64_0 * (long)(object)factor;
				result.register.int64_1 = value.register.int64_1 * (long)(object)factor;
			}
			else if (typeof(T) == typeof(float))
			{
				result.register.single_0 = value.register.single_0 * (float)(object)factor;
				result.register.single_1 = value.register.single_1 * (float)(object)factor;
				result.register.single_2 = value.register.single_2 * (float)(object)factor;
				result.register.single_3 = value.register.single_3 * (float)(object)factor;
			}
			else if (typeof(T) == typeof(double))
			{
				result.register.double_0 = value.register.double_0 * (double)(object)factor;
				result.register.double_1 = value.register.double_1 * (double)(object)factor;
			}
			return result;
		}

		public static Vector<T>operator *(T factor, Vector<T> value)
		{
			if (Vector.IsHardwareAccelerated)
			{
				return new Vector<T>(factor) * value;
			}
			Vector<T> result = default(Vector<T>);
			if (typeof(T) == typeof(byte))
			{
				result.register.byte_0 = (byte)(value.register.byte_0 * (byte)(object)factor);
				result.register.byte_1 = (byte)(value.register.byte_1 * (byte)(object)factor);
				result.register.byte_2 = (byte)(value.register.byte_2 * (byte)(object)factor);
				result.register.byte_3 = (byte)(value.register.byte_3 * (byte)(object)factor);
				result.register.byte_4 = (byte)(value.register.byte_4 * (byte)(object)factor);
				result.register.byte_5 = (byte)(value.register.byte_5 * (byte)(object)factor);
				result.register.byte_6 = (byte)(value.register.byte_6 * (byte)(object)factor);
				result.register.byte_7 = (byte)(value.register.byte_7 * (byte)(object)factor);
				result.register.byte_8 = (byte)(value.register.byte_8 * (byte)(object)factor);
				result.register.byte_9 = (byte)(value.register.byte_9 * (byte)(object)factor);
				result.register.byte_10 = (byte)(value.register.byte_10 * (byte)(object)factor);
				result.register.byte_11 = (byte)(value.register.byte_11 * (byte)(object)factor);
				result.register.byte_12 = (byte)(value.register.byte_12 * (byte)(object)factor);
				result.register.byte_13 = (byte)(value.register.byte_13 * (byte)(object)factor);
				result.register.byte_14 = (byte)(value.register.byte_14 * (byte)(object)factor);
				result.register.byte_15 = (byte)(value.register.byte_15 * (byte)(object)factor);
			}
			else if (typeof(T) == typeof(sbyte))
			{
				result.register.sbyte_0 = (sbyte)(value.register.sbyte_0 * (sbyte)(object)factor);
				result.register.sbyte_1 = (sbyte)(value.register.sbyte_1 * (sbyte)(object)factor);
				result.register.sbyte_2 = (sbyte)(value.register.sbyte_2 * (sbyte)(object)factor);
				result.register.sbyte_3 = (sbyte)(value.register.sbyte_3 * (sbyte)(object)factor);
				result.register.sbyte_4 = (sbyte)(value.register.sbyte_4 * (sbyte)(object)factor);
				result.register.sbyte_5 = (sbyte)(value.register.sbyte_5 * (sbyte)(object)factor);
				result.register.sbyte_6 = (sbyte)(value.register.sbyte_6 * (sbyte)(object)factor);
				result.register.sbyte_7 = (sbyte)(value.register.sbyte_7 * (sbyte)(object)factor);
				result.register.sbyte_8 = (sbyte)(value.register.sbyte_8 * (sbyte)(object)factor);
				result.register.sbyte_9 = (sbyte)(value.register.sbyte_9 * (sbyte)(object)factor);
				result.register.sbyte_10 = (sbyte)(value.register.sbyte_10 * (sbyte)(object)factor);
				result.register.sbyte_11 = (sbyte)(value.register.sbyte_11 * (sbyte)(object)factor);
				result.register.sbyte_12 = (sbyte)(value.register.sbyte_12 * (sbyte)(object)factor);
				result.register.sbyte_13 = (sbyte)(value.register.sbyte_13 * (sbyte)(object)factor);
				result.register.sbyte_14 = (sbyte)(value.register.sbyte_14 * (sbyte)(object)factor);
				result.register.sbyte_15 = (sbyte)(value.register.sbyte_15 * (sbyte)(object)factor);
			}
			else if (typeof(T) == typeof(ushort))
			{
				result.register.uint16_0 = (ushort)(value.register.uint16_0 * (ushort)(object)factor);
				result.register.uint16_1 = (ushort)(value.register.uint16_1 * (ushort)(object)factor);
				result.register.uint16_2 = (ushort)(value.register.uint16_2 * (ushort)(object)factor);
				result.register.uint16_3 = (ushort)(value.register.uint16_3 * (ushort)(object)factor);
				result.register.uint16_4 = (ushort)(value.register.uint16_4 * (ushort)(object)factor);
				result.register.uint16_5 = (ushort)(value.register.uint16_5 * (ushort)(object)factor);
				result.register.uint16_6 = (ushort)(value.register.uint16_6 * (ushort)(object)factor);
				result.register.uint16_7 = (ushort)(value.register.uint16_7 * (ushort)(object)factor);
			}
			else if (typeof(T) == typeof(short))
			{
				result.register.int16_0 = (short)(value.register.int16_0 * (short)(object)factor);
				result.register.int16_1 = (short)(value.register.int16_1 * (short)(object)factor);
				result.register.int16_2 = (short)(value.register.int16_2 * (short)(object)factor);
				result.register.int16_3 = (short)(value.register.int16_3 * (short)(object)factor);
				result.register.int16_4 = (short)(value.register.int16_4 * (short)(object)factor);
				result.register.int16_5 = (short)(value.register.int16_5 * (short)(object)factor);
				result.register.int16_6 = (short)(value.register.int16_6 * (short)(object)factor);
				result.register.int16_7 = (short)(value.register.int16_7 * (short)(object)factor);
			}
			else if (typeof(T) == typeof(uint))
			{
				result.register.uint32_0 = value.register.uint32_0 * (uint)(object)factor;
				result.register.uint32_1 = value.register.uint32_1 * (uint)(object)factor;
				result.register.uint32_2 = value.register.uint32_2 * (uint)(object)factor;
				result.register.uint32_3 = value.register.uint32_3 * (uint)(object)factor;
			}
			else if (typeof(T) == typeof(int))
			{
				result.register.int32_0 = value.register.int32_0 * (int)(object)factor;
				result.register.int32_1 = value.register.int32_1 * (int)(object)factor;
				result.register.int32_2 = value.register.int32_2 * (int)(object)factor;
				result.register.int32_3 = value.register.int32_3 * (int)(object)factor;
			}
			else if (typeof(T) == typeof(ulong))
			{
				result.register.uint64_0 = value.register.uint64_0 * (ulong)(object)factor;
				result.register.uint64_1 = value.register.uint64_1 * (ulong)(object)factor;
			}
			else if (typeof(T) == typeof(long))
			{
				result.register.int64_0 = value.register.int64_0 * (long)(object)factor;
				result.register.int64_1 = value.register.int64_1 * (long)(object)factor;
			}
			else if (typeof(T) == typeof(float))
			{
				result.register.single_0 = value.register.single_0 * (float)(object)factor;
				result.register.single_1 = value.register.single_1 * (float)(object)factor;
				result.register.single_2 = value.register.single_2 * (float)(object)factor;
				result.register.single_3 = value.register.single_3 * (float)(object)factor;
			}
			else if (typeof(T) == typeof(double))
			{
				result.register.double_0 = value.register.double_0 * (double)(object)factor;
				result.register.double_1 = value.register.double_1 * (double)(object)factor;
			}
			return result;
		}

		public unsafe static Vector<T>operator /(Vector<T> left, Vector<T> right)
		{
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					byte* ptr = stackalloc byte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int i = 0; i < Count; i++)
					{
						ptr[i] = (byte)(object)ScalarDivide(left[i], right[i]);
					}
					return new Vector<T>(ptr);
				}
				if (typeof(T) == typeof(sbyte))
				{
					sbyte* ptr2 = stackalloc sbyte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int j = 0; j < Count; j++)
					{
						ptr2[j] = (sbyte)(object)ScalarDivide(left[j], right[j]);
					}
					return new Vector<T>(ptr2);
				}
				if (typeof(T) == typeof(ushort))
				{
					ushort* ptr3 = stackalloc ushort[Count];
					for (int k = 0; k < Count; k++)
					{
						ptr3[k] = (ushort)(object)ScalarDivide(left[k], right[k]);
					}
					return new Vector<T>(ptr3);
				}
				if (typeof(T) == typeof(short))
				{
					short* ptr4 = stackalloc short[Count];
					for (int l = 0; l < Count; l++)
					{
						ptr4[l] = (short)(object)ScalarDivide(left[l], right[l]);
					}
					return new Vector<T>(ptr4);
				}
				if (typeof(T) == typeof(uint))
				{
					uint* ptr5 = stackalloc uint[Count];
					for (int m = 0; m < Count; m++)
					{
						ptr5[m] = (uint)(object)ScalarDivide(left[m], right[m]);
					}
					return new Vector<T>(ptr5);
				}
				if (typeof(T) == typeof(int))
				{
					int* ptr6 = stackalloc int[Count];
					for (int n = 0; n < Count; n++)
					{
						ptr6[n] = (int)(object)ScalarDivide(left[n], right[n]);
					}
					return new Vector<T>(ptr6);
				}
				if (typeof(T) == typeof(ulong))
				{
					ulong* ptr7 = stackalloc ulong[Count];
					for (int num = 0; num < Count; num++)
					{
						ptr7[num] = (ulong)(object)ScalarDivide(left[num], right[num]);
					}
					return new Vector<T>(ptr7);
				}
				if (typeof(T) == typeof(long))
				{
					long* ptr8 = stackalloc long[Count];
					for (int num2 = 0; num2 < Count; num2++)
					{
						ptr8[num2] = (long)(object)ScalarDivide(left[num2], right[num2]);
					}
					return new Vector<T>(ptr8);
				}
				if (typeof(T) == typeof(float))
				{
					float* ptr9 = stackalloc float[Count];
					for (int num3 = 0; num3 < Count; num3++)
					{
						ptr9[num3] = (float)(object)ScalarDivide(left[num3], right[num3]);
					}
					return new Vector<T>(ptr9);
				}
				if (typeof(T) == typeof(double))
				{
					double* ptr10 = stackalloc double[Count];
					for (int num4 = 0; num4 < Count; num4++)
					{
						ptr10[num4] = (double)(object)ScalarDivide(left[num4], right[num4]);
					}
					return new Vector<T>(ptr10);
				}
				throw new NotSupportedException(System.SR.Arg_TypeNotSupported);
			}
			Vector<T> result = default(Vector<T>);
			if (typeof(T) == typeof(byte))
			{
				result.register.byte_0 = (byte)(left.register.byte_0 / right.register.byte_0);
				result.register.byte_1 = (byte)(left.register.byte_1 / right.register.byte_1);
				result.register.byte_2 = (byte)(left.register.byte_2 / right.register.byte_2);
				result.register.byte_3 = (byte)(left.register.byte_3 / right.register.byte_3);
				result.register.byte_4 = (byte)(left.register.byte_4 / right.register.byte_4);
				result.register.byte_5 = (byte)(left.register.byte_5 / right.register.byte_5);
				result.register.byte_6 = (byte)(left.register.byte_6 / right.register.byte_6);
				result.register.byte_7 = (byte)(left.register.byte_7 / right.register.byte_7);
				result.register.byte_8 = (byte)(left.register.byte_8 / right.register.byte_8);
				result.register.byte_9 = (byte)(left.register.byte_9 / right.register.byte_9);
				result.register.byte_10 = (byte)(left.register.byte_10 / right.register.byte_10);
				result.register.byte_11 = (byte)(left.register.byte_11 / right.register.byte_11);
				result.register.byte_12 = (byte)(left.register.byte_12 / right.register.byte_12);
				result.register.byte_13 = (byte)(left.register.byte_13 / right.register.byte_13);
				result.register.byte_14 = (byte)(left.register.byte_14 / right.register.byte_14);
				result.register.byte_15 = (byte)(left.register.byte_15 / right.register.byte_15);
			}
			else if (typeof(T) == typeof(sbyte))
			{
				result.register.sbyte_0 = (sbyte)(left.register.sbyte_0 / right.register.sbyte_0);
				result.register.sbyte_1 = (sbyte)(left.register.sbyte_1 / right.register.sbyte_1);
				result.register.sbyte_2 = (sbyte)(left.register.sbyte_2 / right.register.sbyte_2);
				result.register.sbyte_3 = (sbyte)(left.register.sbyte_3 / right.register.sbyte_3);
				result.register.sbyte_4 = (sbyte)(left.register.sbyte_4 / right.register.sbyte_4);
				result.register.sbyte_5 = (sbyte)(left.register.sbyte_5 / right.register.sbyte_5);
				result.register.sbyte_6 = (sbyte)(left.register.sbyte_6 / right.register.sbyte_6);
				result.register.sbyte_7 = (sbyte)(left.register.sbyte_7 / right.register.sbyte_7);
				result.register.sbyte_8 = (sbyte)(left.register.sbyte_8 / right.register.sbyte_8);
				result.register.sbyte_9 = (sbyte)(left.register.sbyte_9 / right.register.sbyte_9);
				result.register.sbyte_10 = (sbyte)(left.register.sbyte_10 / right.register.sbyte_10);
				result.register.sbyte_11 = (sbyte)(left.register.sbyte_11 / right.register.sbyte_11);
				result.register.sbyte_12 = (sbyte)(left.register.sbyte_12 / right.register.sbyte_12);
				result.register.sbyte_13 = (sbyte)(left.register.sbyte_13 / right.register.sbyte_13);
				result.register.sbyte_14 = (sbyte)(left.register.sbyte_14 / right.register.sbyte_14);
				result.register.sbyte_15 = (sbyte)(left.register.sbyte_15 / right.register.sbyte_15);
			}
			else if (typeof(T) == typeof(ushort))
			{
				result.register.uint16_0 = (ushort)(left.register.uint16_0 / right.register.uint16_0);
				result.register.uint16_1 = (ushort)(left.register.uint16_1 / right.register.uint16_1);
				result.register.uint16_2 = (ushort)(left.register.uint16_2 / right.register.uint16_2);
				result.register.uint16_3 = (ushort)(left.register.uint16_3 / right.register.uint16_3);
				result.register.uint16_4 = (ushort)(left.register.uint16_4 / right.register.uint16_4);
				result.register.uint16_5 = (ushort)(left.register.uint16_5 / right.register.uint16_5);
				result.register.uint16_6 = (ushort)(left.register.uint16_6 / right.register.uint16_6);
				result.register.uint16_7 = (ushort)(left.register.uint16_7 / right.register.uint16_7);
			}
			else if (typeof(T) == typeof(short))
			{
				result.register.int16_0 = (short)(left.register.int16_0 / right.register.int16_0);
				result.register.int16_1 = (short)(left.register.int16_1 / right.register.int16_1);
				result.register.int16_2 = (short)(left.register.int16_2 / right.register.int16_2);
				result.register.int16_3 = (short)(left.register.int16_3 / right.register.int16_3);
				result.register.int16_4 = (short)(left.register.int16_4 / right.register.int16_4);
				result.register.int16_5 = (short)(left.register.int16_5 / right.register.int16_5);
				result.register.int16_6 = (short)(left.register.int16_6 / right.register.int16_6);
				result.register.int16_7 = (short)(left.register.int16_7 / right.register.int16_7);
			}
			else if (typeof(T) == typeof(uint))
			{
				result.register.uint32_0 = left.register.uint32_0 / right.register.uint32_0;
				result.register.uint32_1 = left.register.uint32_1 / right.register.uint32_1;
				result.register.uint32_2 = left.register.uint32_2 / right.register.uint32_2;
				result.register.uint32_3 = left.register.uint32_3 / right.register.uint32_3;
			}
			else if (typeof(T) == typeof(int))
			{
				result.register.int32_0 = left.register.int32_0 / right.register.int32_0;
				result.register.int32_1 = left.register.int32_1 / right.register.int32_1;
				result.register.int32_2 = left.register.int32_2 / right.register.int32_2;
				result.register.int32_3 = left.register.int32_3 / right.register.int32_3;
			}
			else if (typeof(T) == typeof(ulong))
			{
				result.register.uint64_0 = left.register.uint64_0 / right.register.uint64_0;
				result.register.uint64_1 = left.register.uint64_1 / right.register.uint64_1;
			}
			else if (typeof(T) == typeof(long))
			{
				result.register.int64_0 = left.register.int64_0 / right.register.int64_0;
				result.register.int64_1 = left.register.int64_1 / right.register.int64_1;
			}
			else if (typeof(T) == typeof(float))
			{
				result.register.single_0 = left.register.single_0 / right.register.single_0;
				result.register.single_1 = left.register.single_1 / right.register.single_1;
				result.register.single_2 = left.register.single_2 / right.register.single_2;
				result.register.single_3 = left.register.single_3 / right.register.single_3;
			}
			else if (typeof(T) == typeof(double))
			{
				result.register.double_0 = left.register.double_0 / right.register.double_0;
				result.register.double_1 = left.register.double_1 / right.register.double_1;
			}
			return result;
		}

		public static Vector<T>operator -(Vector<T> value)
		{
			return Zero - value;
		}

		[JitIntrinsic]
		public unsafe static Vector<T>operator &(Vector<T> left, Vector<T> right)
		{
			Vector<T> result = default(Vector<T>);
			if (Vector.IsHardwareAccelerated)
			{
				long* ptr = &result.register.int64_0;
				long* ptr2 = &left.register.int64_0;
				long* ptr3 = &right.register.int64_0;
				for (int i = 0; i < Vector<long>.Count; i++)
				{
					ptr[i] = ptr2[i] & ptr3[i];
				}
			}
			else
			{
				result.register.int64_0 = left.register.int64_0 & right.register.int64_0;
				result.register.int64_1 = left.register.int64_1 & right.register.int64_1;
			}
			return result;
		}

		[JitIntrinsic]
		public unsafe static Vector<T>operator |(Vector<T> left, Vector<T> right)
		{
			Vector<T> result = default(Vector<T>);
			if (Vector.IsHardwareAccelerated)
			{
				long* ptr = &result.register.int64_0;
				long* ptr2 = &left.register.int64_0;
				long* ptr3 = &right.register.int64_0;
				for (int i = 0; i < Vector<long>.Count; i++)
				{
					ptr[i] = ptr2[i] | ptr3[i];
				}
			}
			else
			{
				result.register.int64_0 = left.register.int64_0 | right.register.int64_0;
				result.register.int64_1 = left.register.int64_1 | right.register.int64_1;
			}
			return result;
		}

		[JitIntrinsic]
		public unsafe static Vector<T>operator ^(Vector<T> left, Vector<T> right)
		{
			Vector<T> result = default(Vector<T>);
			if (Vector.IsHardwareAccelerated)
			{
				long* ptr = &result.register.int64_0;
				long* ptr2 = &left.register.int64_0;
				long* ptr3 = &right.register.int64_0;
				for (int i = 0; i < Vector<long>.Count; i++)
				{
					ptr[i] = ptr2[i] ^ ptr3[i];
				}
			}
			else
			{
				result.register.int64_0 = left.register.int64_0 ^ right.register.int64_0;
				result.register.int64_1 = left.register.int64_1 ^ right.register.int64_1;
			}
			return result;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector<T>operator ~(Vector<T> value)
		{
			return allOnes ^ value;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool operator ==(Vector<T> left, Vector<T> right)
		{
			return left.Equals(right);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool operator !=(Vector<T> left, Vector<T> right)
		{
			return !(left == right);
		}

		[JitIntrinsic]
		public static explicit operator Vector<byte>(Vector<T> value)
		{
			return new Vector<byte>(ref value.register);
		}

		[CLSCompliant(false)]
		[JitIntrinsic]
		public static explicit operator Vector<sbyte>(Vector<T> value)
		{
			return new Vector<sbyte>(ref value.register);
		}

		[CLSCompliant(false)]
		[JitIntrinsic]
		public static explicit operator Vector<ushort>(Vector<T> value)
		{
			return new Vector<ushort>(ref value.register);
		}

		[JitIntrinsic]
		public static explicit operator Vector<short>(Vector<T> value)
		{
			return new Vector<short>(ref value.register);
		}

		[CLSCompliant(false)]
		[JitIntrinsic]
		public static explicit operator Vector<uint>(Vector<T> value)
		{
			return new Vector<uint>(ref value.register);
		}

		[JitIntrinsic]
		public static explicit operator Vector<int>(Vector<T> value)
		{
			return new Vector<int>(ref value.register);
		}

		[CLSCompliant(false)]
		[JitIntrinsic]
		public static explicit operator Vector<ulong>(Vector<T> value)
		{
			return new Vector<ulong>(ref value.register);
		}

		[JitIntrinsic]
		public static explicit operator Vector<long>(Vector<T> value)
		{
			return new Vector<long>(ref value.register);
		}

		[JitIntrinsic]
		public static explicit operator Vector<float>(Vector<T> value)
		{
			return new Vector<float>(ref value.register);
		}

		[JitIntrinsic]
		public static explicit operator Vector<double>(Vector<T> value)
		{
			return new Vector<double>(ref value.register);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[JitIntrinsic]
		internal unsafe static Vector<T> Equals(Vector<T> left, Vector<T> right)
		{
			if (Vector.IsHardwareAccelerated)
			{
				if (typeof(T) == typeof(byte))
				{
					byte* ptr = stackalloc byte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int i = 0; i < Count; i++)
					{
						ptr[i] = (byte)(ScalarEquals(left[i], right[i]) ? ConstantHelper.GetByteWithAllBitsSet() : 0);
					}
					return new Vector<T>(ptr);
				}
				if (typeof(T) == typeof(sbyte))
				{
					sbyte* ptr2 = stackalloc sbyte[(int)checked(unchecked((nuint)(uint)Count) * (nuint)1u)];
					for (int j = 0; j < Count; j++)
					{
						ptr2[j] = (sbyte)(ScalarEquals(left[j], right[j]) ? ConstantHelper.GetSByteWithAllBitsSet() : 0);
					}
					return new Vector<T>(ptr2);
				}
				if (typeof(T) == typeof(ushort))
				{
					ushort* ptr3 = stackalloc ushort[Count];
					for (int k = 0; k < Count; k++)
					{
						ptr3[k] =

plugins\System.Runtime.CompilerServices.Unsafe.dll

Decompiled a year ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyFileVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.0.0.0")]
[assembly: AssemblyTitle("System.Runtime.CompilerServices.Unsafe")]
[assembly: AssemblyDescription("System.Runtime.CompilerServices.Unsafe")]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyCopyright("© Microsoft Corporation.  All rights reserved.")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: CLSCompliant(false)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("4.0.4.1")]
namespace System.Runtime.CompilerServices
{
	public static class Unsafe : Object
	{
		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static T Read<T>(void* source)
		{
			return Unsafe.Read<T>(source);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static T ReadUnaligned<T>(void* source)
		{
			return Unsafe.ReadUnaligned<T>(source);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static T ReadUnaligned<T>(ref byte source)
		{
			return Unsafe.ReadUnaligned<T>(ref source);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void Write<T>(void* destination, T value)
		{
			Unsafe.Write(destination, value);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void WriteUnaligned<T>(void* destination, T value)
		{
			Unsafe.WriteUnaligned(destination, value);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static void WriteUnaligned<T>(ref byte destination, T value)
		{
			Unsafe.WriteUnaligned(ref destination, value);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void Copy<T>(void* destination, ref T source)
		{
			Unsafe.Write(destination, source);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void Copy<T>(ref T destination, void* source)
		{
			destination = Unsafe.Read<T>(source);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void* AsPointer<T>(ref T value)
		{
			return Unsafe.AsPointer(ref value);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static int SizeOf<T>()
		{
			return Unsafe.SizeOf<T>();
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void CopyBlock(void* destination, void* source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlock(destination, source, byteCount);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static void CopyBlock(ref byte destination, ref byte source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlock(ref destination, ref source, byteCount);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void CopyBlockUnaligned(void* destination, void* source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlockUnaligned(destination, source, byteCount);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static void CopyBlockUnaligned(ref byte destination, ref byte source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlockUnaligned(ref destination, ref source, byteCount);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void InitBlock(void* startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlock(startAddress, value, byteCount);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static void InitBlock(ref byte startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlock(ref startAddress, value, byteCount);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void InitBlockUnaligned(void* startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlockUnaligned(startAddress, value, byteCount);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static void InitBlockUnaligned(ref byte startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlockUnaligned(ref startAddress, value, byteCount);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static T As<T>(object o) where T : class
		{
			return (T)o;
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static ref T AsRef<T>(void* source)
		{
			return ref *(T*)source;
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static ref T AsRef<T>(in T source)
		{
			return ref source;
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static ref TTo As<TFrom, TTo>(ref TFrom source)
		{
			return ref Unsafe.As<TFrom, TTo>(ref source);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static ref T Add<T>(ref T source, int elementOffset)
		{
			return ref Unsafe.Add(ref source, elementOffset);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void* Add<T>(void* source, int elementOffset)
		{
			return (byte*)source + (nint)elementOffset * (nint)Unsafe.SizeOf<T>();
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static ref T Add<T>(ref T source, System.IntPtr elementOffset)
		{
			return ref Unsafe.Add(ref source, elementOffset);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static ref T AddByteOffset<T>(ref T source, System.IntPtr byteOffset)
		{
			return ref Unsafe.AddByteOffset(ref source, byteOffset);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static ref T Subtract<T>(ref T source, int elementOffset)
		{
			return ref Unsafe.Subtract(ref source, elementOffset);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public unsafe static void* Subtract<T>(void* source, int elementOffset)
		{
			return (byte*)source - (nint)elementOffset * (nint)Unsafe.SizeOf<T>();
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static ref T Subtract<T>(ref T source, System.IntPtr elementOffset)
		{
			return ref Unsafe.Subtract(ref source, elementOffset);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static ref T SubtractByteOffset<T>(ref T source, System.IntPtr byteOffset)
		{
			return ref Unsafe.SubtractByteOffset(ref source, byteOffset);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static System.IntPtr ByteOffset<T>(ref T origin, ref T target)
		{
			return Unsafe.ByteOffset(target: ref target, origin: ref origin);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static bool AreSame<T>(ref T left, ref T right)
		{
			return Unsafe.AreSame(ref left, ref right);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static bool IsAddressGreaterThan<T>(ref T left, ref T right)
		{
			return Unsafe.IsAddressGreaterThan(ref left, ref right);
		}

		[MethodImpl(256)]
		[NonVersionable]
		public static bool IsAddressLessThan<T>(ref T left, ref T right)
		{
			return Unsafe.IsAddressLessThan(ref left, ref right);
		}
	}
}
namespace System.Runtime.Versioning
{
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NonVersionableAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
}