Decompiled source of Blackbox v0.2.7

Blackbox.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using crecheng.DSPModSave;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Blackbox")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.7.0")]
[assembly: AssemblyInformationalVersion("0.2.7")]
[assembly: AssemblyProduct("Blackbox")]
[assembly: AssemblyTitle("Blackbox")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace System.Runtime.CompilerServices
{
	public record IsExternalInit;
}
namespace DysonSphereProgram.Modding.Blackbox
{
	public class AutoBlackbox
	{
		private int currentBlackboxId;

		private int currentFactoryIdx;

		private int currentStationIdx;

		public bool isActive;

		private int debounceControl;

		private const int saveLogicVersion = 1;

		public void GameTick()
		{
			if (!isActive || DSPGame.IsMenuDemo)
			{
				return;
			}
			debounceControl = (debounceControl + 1) % 60;
			if (debounceControl != 0)
			{
				return;
			}
			if (currentBlackboxId > 0)
			{
				Blackbox blackbox = BlackboxManager.Instance.blackboxes.Find((Blackbox b) => b.Id == currentBlackboxId);
				if (blackbox == null || IsInTerminalState(blackbox.Status))
				{
					currentBlackboxId = 0;
				}
			}
			if (currentBlackboxId != 0)
			{
				return;
			}
			GameData data = GameMain.data;
			currentFactoryIdx %= data.factoryCount;
			PlanetFactory val = data.factories[currentFactoryIdx];
			PlanetTransport transport = val.transport;
			StationComponent[] stationPool = transport.stationPool;
			IEnumerable<Blackbox> source = BlackboxManager.Instance.blackboxes.Where((Blackbox x) => x.FactoryIndex == currentFactoryIdx);
			for (int i = 1; i <= transport.stationCursor; i++)
			{
				int effectiveIdx = (i + currentStationIdx) % transport.stationCursor;
				if (effectiveIdx != 0)
				{
					StationComponent val2 = stationPool[effectiveIdx];
					if (val2 != null && val2.id == effectiveIdx && val2.minerId == 0 && !source.Any((Blackbox b) => b.Selection.stationIds.Contains(effectiveIdx)))
					{
						Plugin.Log.LogDebug((object)("Found unblackboxed stationIdx: " + effectiveIdx));
						currentStationIdx = effectiveIdx;
						Blackbox blackbox2 = BlackboxManager.Instance.CreateForSelection(BlackboxSelection.CreateFrom(val, new int[1] { val2.entityId }));
						currentBlackboxId = blackbox2.Id;
						return;
					}
				}
			}
			for (int j = 1; j <= data.factoryCount; j++)
			{
				int num = (j + currentFactoryIdx) % data.factoryCount;
				if (data.factories[num] != null)
				{
					currentFactoryIdx = num;
					break;
				}
			}
		}

		private bool IsInTerminalState(BlackboxStatus status)
		{
			if (status != BlackboxStatus.Invalid && status != BlackboxStatus.AnalysisFailed)
			{
				return status == BlackboxStatus.Blackboxed;
			}
			return true;
		}

		public void Export(BinaryWriter w)
		{
			w.Write(1);
			w.Write(isActive);
			w.Write(currentBlackboxId);
			w.Write(currentFactoryIdx);
			w.Write(currentStationIdx);
		}

		public void Import(BinaryReader r)
		{
			r.ReadInt32();
			isActive = r.ReadBoolean();
			currentBlackboxId = r.ReadInt32();
			currentFactoryIdx = r.ReadInt32();
			currentStationIdx = r.ReadInt32();
			debounceControl = 0;
		}
	}
	public enum BlackboxStatus
	{
		Initialized,
		SelectionExpanding,
		SelectionFinalized,
		Fingerprinted,
		Invalid,
		InAnalysis,
		AnalysisFailed,
		RecipeObtained,
		Blackboxed
	}
	public class Blackbox
	{
		public readonly int Id;

		public string Name;

		internal bool analyseInBackground;

		public static bool analyseInBackgroundConfig = true;

		private const int saveLogicVersion = 1;

		public BlackboxSelection Selection { get; private set; }

		public BlackboxFingerprint Fingerprint { get; private set; }

		public BlackboxRecipe Recipe { get; private set; }

		public BlackboxAnalysis Analysis { get; private set; }

		public BlackboxSimulation Simulation { get; private set; }

		public BlackboxStatus Status { get; private set; }

		public int FactoryIndex => Selection.factoryIndex;

		public WeakReference<PlanetFactory> FactoryRef => Selection.factoryRef;

		internal Blackbox(int id, BlackboxSelection selection)
		{
			Id = id;
			Selection = selection;
			Status = BlackboxStatus.Initialized;
			Name = "Blackbox #" + Id;
			analyseInBackground = analyseInBackgroundConfig;
		}

		public void NotifyBlackboxed(BlackboxRecipe recipe)
		{
			if (Status == BlackboxStatus.InAnalysis)
			{
				Recipe = recipe;
				Status = BlackboxStatus.RecipeObtained;
			}
		}

		public void NotifyAnalysisFailed()
		{
			if (Status == BlackboxStatus.InAnalysis)
			{
				Status = BlackboxStatus.AnalysisFailed;
			}
		}

		public void GameTick()
		{
			if (!FactoryRef.TryGetTarget(out var _))
			{
				Plugin.Log.LogError((object)"PlanetFactory instance pulled out from under Blackbox in GameTick");
				return;
			}
			switch (Status)
			{
			case BlackboxStatus.Initialized:
				Status = BlackboxStatus.SelectionExpanding;
				break;
			case BlackboxStatus.SelectionExpanding:
				Selection = BlackboxSelection.Expand(Selection);
				if (BlackboxSelection.IsInvalid(Selection))
				{
					Status = BlackboxStatus.Invalid;
				}
				else
				{
					Status = BlackboxStatus.SelectionFinalized;
				}
				break;
			case BlackboxStatus.SelectionFinalized:
				Fingerprint = BlackboxFingerprint.CreateFrom(Selection);
				Status = BlackboxStatus.Fingerprinted;
				break;
			case BlackboxStatus.Fingerprinted:
				Analysis = new BlackboxBenchmark(this);
				Status = BlackboxStatus.InAnalysis;
				Analysis.Begin();
				break;
			case BlackboxStatus.AnalysisFailed:
				Analysis?.Free();
				Analysis = null;
				break;
			case BlackboxStatus.RecipeObtained:
				Analysis?.Free();
				Analysis = null;
				Status = BlackboxStatus.Blackboxed;
				if (Simulation == null)
				{
					Simulation = new BlackboxSimulation(this);
					Simulation.BeginBlackboxing();
				}
				break;
			case BlackboxStatus.Invalid:
			case BlackboxStatus.InAnalysis:
				break;
			}
		}

		public void PreserveVanillaSaveBefore()
		{
			Simulation?.PreserveVanillaSaveBefore();
		}

		public void PreserveVanillaSaveAfter()
		{
			Simulation?.PreserveVanillaSaveAfter();
		}

		public void Export(BinaryWriter w)
		{
			w.Write(1);
			w.Write(Id);
			Selection.Export(w);
			w.Write(Name);
			w.Write(analyseInBackground);
			BlackboxStatus blackboxStatus = Status;
			if (blackboxStatus == BlackboxStatus.InAnalysis)
			{
				blackboxStatus = BlackboxStatus.Fingerprinted;
			}
			w.Write((int)blackboxStatus);
			bool value = Fingerprint != null;
			w.Write(value);
			bool flag = Recipe != null;
			w.Write(flag);
			if (flag)
			{
				Recipe.Export(w);
			}
			bool flag2 = Simulation != null;
			w.Write(flag2);
			if (flag2)
			{
				Simulation.Export(w);
			}
		}

		public static Blackbox Import(BinaryReader r)
		{
			r.ReadInt32();
			int id = r.ReadInt32();
			BlackboxSelection selection = BlackboxSelection.Import(r);
			Blackbox blackbox = new Blackbox(id, selection);
			blackbox.Name = r.ReadString();
			blackbox.analyseInBackground = r.ReadBoolean();
			blackbox.Status = (BlackboxStatus)r.ReadInt32();
			if (r.ReadBoolean())
			{
				blackbox.Fingerprint = BlackboxFingerprint.CreateFrom(blackbox.Selection);
			}
			if (r.ReadBoolean())
			{
				blackbox.Recipe = BlackboxRecipe.Import(r);
			}
			if (r.ReadBoolean())
			{
				blackbox.Simulation = new BlackboxSimulation(blackbox);
				blackbox.Simulation.CreateBlackboxingResources();
				blackbox.Simulation.Import(r);
			}
			return blackbox;
		}
	}
	public abstract class BlackboxAnalysis
	{
		internal Blackbox blackbox;

		internal WeakReference<PlanetFactory> factoryRef;

		public abstract BlackboxRecipe EffectiveRecipe { get; }

		public abstract float Progress { get; }

		public abstract string ProgressText { get; }

		public BlackboxAnalysis(Blackbox blackbox)
		{
			this.blackbox = blackbox;
			factoryRef = blackbox.FactoryRef;
		}

		public abstract void Begin();

		public abstract void Free();
	}
	public struct ProduceConsumePair
	{
		public int Produced;

		public int Consumed;
	}
	public enum BenchmarkPhase
	{
		SpraySaturation,
		SelfSpraySaturation,
		ItemSaturation,
		Benchmarking,
		Averaging
	}
	public record struct StationStorageData(int stationId, int stationIdx, int storageIdx, ELogisticStorage effectiveLogic, int itemId, int itemIdx) : IComparable<StationStorageData>
	{
		public bool isSpray = sprayItemIds.Contains(itemId);

		private static readonly int[] sprayItemIds = new int[3] { 1141, 1142, 1143 };

		public int CompareTo(StationStorageData other)
		{
			int num = stationIdx.CompareTo(other.stationIdx);
			if (num != 0)
			{
				return num;
			}
			return storageIdx.CompareTo(other.storageIdx);
		}

		[CompilerGenerated]
		private readonly bool PrintMembers(StringBuilder builder)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			builder.Append("stationId = ");
			builder.Append(stationId.ToString());
			builder.Append(", stationIdx = ");
			builder.Append(stationIdx.ToString());
			builder.Append(", storageIdx = ");
			builder.Append(storageIdx.ToString());
			builder.Append(", effectiveLogic = ");
			ELogisticStorage val = effectiveLogic;
			builder.Append(((object)(ELogisticStorage)(ref val)).ToString());
			builder.Append(", itemId = ");
			builder.Append(itemId.ToString());
			builder.Append(", itemIdx = ");
			builder.Append(itemIdx.ToString());
			builder.Append(", isSpray = ");
			builder.Append(isSpray.ToString());
			return true;
		}

		[CompilerGenerated]
		public readonly void Deconstruct(out int stationId, out int stationIdx, out int storageIdx, out ELogisticStorage effectiveLogic, out int itemId, out int itemIdx)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected I4, but got Unknown
			stationId = this.stationId;
			stationIdx = this.stationIdx;
			storageIdx = this.storageIdx;
			effectiveLogic = (ELogisticStorage)(int)this.effectiveLogic;
			itemId = this.itemId;
			itemIdx = this.itemIdx;
		}
	}
	public struct StationEntryExit
	{
		public int EntryCount;

		public int EntryInc;

		public int ExitCount;

		public int ExitInc;
	}
	public class BlackboxBenchmark : BlackboxBenchmarkBase
	{
		private class BlackboxBenchmarkSummarizer : ISummarizer<int>
		{
			public BlackboxBenchmark analysis;

			public void Initialize(Span<int> data)
			{
				data.Clear();
			}

			public void Summarize(Span<int> detailed, Span<int> summary)
			{
				int num = 1;
				Span<long> span = MemoryMarshal.Cast<int, long>(detailed.Slice(0, num * 2));
				Span<long> span2 = MemoryMarshal.Cast<int, long>(summary.Slice(0, num * 2));
				for (int i = 0; i < span2.Length; i++)
				{
					span2[i] += span[i];
				}
				Span<int> span3 = detailed.Slice(analysis.stationOffset, analysis.stationSize + analysis.factoryStatsSize + analysis.stationStatsSize);
				Span<int> span4 = summary.Slice(analysis.stationOffset, analysis.stationSize + analysis.factoryStatsSize + analysis.stationStatsSize);
				for (int j = 0; j < span4.Length; j++)
				{
					span4[j] += span3[j];
				}
				Span<int> span5 = detailed.Slice(analysis.statsDiffOffset, analysis.statsDiffSize);
				Span<int> span6 = summary.Slice(analysis.statsDiffOffset, analysis.statsDiffSize);
				for (int k = 0; k < span6.Length; k++)
				{
					span6[k] = Math.Max(span6[k], span5[k]);
				}
			}
		}

		private enum StabilityDetectionAction
		{
			Max,
			Min
		}

		private enum StationEntryExitRecordAction
		{
			EntryBefore,
			EntryAfter,
			ExitBefore,
			ExitAfter
		}

		internal readonly ImmutableSortedSet<int> entityIds;

		internal readonly ImmutableSortedSet<int> pcIds;

		internal readonly ImmutableSortedSet<int> assemblerIds;

		internal readonly ImmutableSortedSet<int> labIds;

		internal readonly ImmutableSortedSet<int> inserterIds;

		internal readonly ImmutableSortedSet<int> stationIds;

		internal readonly ImmutableSortedSet<int> cargoPathIds;

		internal readonly ImmutableSortedSet<int> splitterIds;

		internal readonly ImmutableSortedSet<int> pilerIds;

		internal readonly ImmutableSortedSet<int> spraycoaterIds;

		internal readonly ImmutableSortedSet<int> fractionatorIds;

		internal readonly ImmutableSortedSet<int> itemIds;

		internal StationStorageData[] stationStorages;

		private const int TicksPerSecond = 60;

		private const int TicksPerMinute = 3600;

		public static bool logProfiledData = false;

		public static bool forceNoStackingConfig = false;

		public static bool adaptiveStackingConfig = false;

		public bool adaptiveStacking;

		public bool forceNoStacking;

		public static bool continuousLogging = false;

		private StreamWriter continuousLogger;

		private ProduceConsumePair[] totalStats;

		private ISummarizer<int> summarizer;

		private int[] cycleDetectionData;

		private TimeSeriesData<int> profilingTsData;

		private const int pcOffset = 0;

		private int pcSize;

		private int stationOffset;

		private int stationSize;

		private int factoryStatsOffset;

		private int factoryStatsSize;

		private int stationStatsOffset;

		private int stationStatsSize;

		private int statsDiffOffset;

		private int statsDiffSize;

		private int perTickProfilingSize;

		private int profilingTick;

		private int[] stabilityDetectionData;

		private int stabilizedTick;

		private int spraySaturationTick;

		private int averagingDataSize;

		private long[] averagingDataRaw;

		private int[] averagingDataStats;

		private int averagingDataStatsIdx;

		public static int analysisVerificationCountConfig = 4;

		public static int analysisDurationMultiplierConfig = 3;

		public static float averagingThresholdPcConfig = 0.0001f;

		public static float averagingThresholdItemStatsConfig = 0.0001f;

		public static float stabilityDetectionThresholdConfig = 0f;

		public static bool useItemSaturationPhaseConfig = false;

		public int analysisVerificationCount;

		public int analysisDurationMultiplier;

		public float averagingThresholdPc;

		public float averagingThresholdItemStats;

		public float stabilityDetectionThreshold;

		public bool useItemSaturationPhase;

		private int timeSpendGCD;

		private int timeSpendLCM;

		private int timeSpendMaxIndividual;

		private int profilingTickCount;

		private int profilingEntryCount;

		private int observedCycleLength;

		private BenchmarkPhase phase;

		public static bool shouldOverrideCycleLengthConfig = false;

		public static int overrideCycleLengthConfig = 60;

		public bool shouldOverrideCycleLength;

		public int overrideCycleLength;

		private BlackboxRecipe analysedRecipe;

		internal PlanetFactory simulationFactory;

		internal Task profilingTask;

		internal CancellationTokenSource profilingTaskCancel;

		public override BlackboxRecipe EffectiveRecipe => analysedRecipe;

		public static string FileLogPath => Path.GetDirectoryName(Plugin.Path);

		private int totalTicks => stabilizedTick + profilingTickCount * analysisDurationMultiplier;

		public override float Progress => (float)profilingTick / (float)totalTicks;

		public override string ProgressText => $"{profilingTick} / {totalTicks}";

		public BlackboxBenchmark(Blackbox blackbox)
			: base(blackbox)
		{
			entityIds = blackbox.Selection.entityIds;
			pcIds = blackbox.Selection.pcIds;
			assemblerIds = blackbox.Selection.assemblerIds;
			labIds = blackbox.Selection.labIds;
			inserterIds = blackbox.Selection.inserterIds;
			stationIds = blackbox.Selection.stationIds;
			cargoPathIds = blackbox.Selection.cargoPathIds;
			splitterIds = blackbox.Selection.splitterIds;
			pilerIds = blackbox.Selection.pilerIds;
			spraycoaterIds = blackbox.Selection.spraycoaterIds;
			fractionatorIds = blackbox.Selection.fractionatorIds;
			itemIds = blackbox.Selection.itemIds;
		}

		public override void Begin()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			if (!factoryRef.TryGetTarget(out var target))
			{
				Plugin.Log.LogError((object)"PlanetFactory instance pulled out from under BlackboxBenchmark in Begin");
				return;
			}
			simulationFactory = (blackbox.analyseInBackground ? PlanetFactorySimulation.CloneForSimulation(target, blackbox.Selection) : target);
			List<int> list = new List<int>();
			Builder<StationStorageData> val = ImmutableSortedSet.CreateBuilder<StationStorageData>();
			Enumerator<int> enumerator = entityIds.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					int current = enumerator.Current;
					ref EntityData reference = ref simulationFactory.entityPool[current];
					if (reference.assemblerId > 0)
					{
						ref AssemblerComponent reference2 = ref simulationFactory.factorySystem.assemblerPool[reference.assemblerId];
						list.Add(reference2.timeSpend / reference2.speed);
					}
					if (reference.labId > 0)
					{
						ref LabComponent reference3 = ref simulationFactory.factorySystem.labPool[reference.labId];
						LabComponent val2 = reference3;
						if (((LabComponent)(ref val2)).matrixMode)
						{
							list.Add(reference3.timeSpend / 10000);
						}
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			pcSize = 2;
			stationSize = 0;
			for (int i = 0; i < stationIds.Count; i++)
			{
				ref StationComponent reference4 = ref simulationFactory.transport.stationPool[stationIds[i]];
				for (int j = 0; j < reference4.storage.Length; j++)
				{
					ref StationStore reference5 = ref reference4.storage[j];
					ELogisticStorage effectiveLogic = (((int)reference5.remoteLogic == 0) ? reference5.localLogic : reference5.remoteLogic);
					if (reference5.itemId > 0)
					{
						int itemIdx = itemIds.IndexOf(reference5.itemId);
						val.Add(new StationStorageData(stationIds[i], i, j, effectiveLogic, reference5.itemId, itemIdx));
					}
				}
			}
			stationStorages = ((IEnumerable<StationStorageData>)val.ToImmutable()).ToArray();
			stationSize = stationStorages.Length * 4;
			factoryStatsSize = itemIds.Count * 2;
			stationStatsSize = itemIds.Count * 2;
			statsDiffSize = itemIds.Count;
			stationOffset = pcSize;
			factoryStatsOffset = stationOffset + stationSize;
			stationStatsOffset = factoryStatsOffset + factoryStatsSize;
			statsDiffOffset = stationStatsOffset + stationStatsSize;
			perTickProfilingSize = pcSize + stationSize + factoryStatsSize + stationStatsSize + statsDiffSize;
			totalStats = new ProduceConsumePair[itemIds.Count];
			analysisVerificationCount = analysisVerificationCountConfig;
			analysisDurationMultiplier = analysisDurationMultiplierConfig;
			averagingThresholdPc = averagingThresholdPcConfig;
			averagingThresholdItemStats = averagingThresholdItemStatsConfig;
			stabilityDetectionThreshold = stabilityDetectionThresholdConfig;
			useItemSaturationPhase = useItemSaturationPhaseConfig;
			shouldOverrideCycleLength = shouldOverrideCycleLengthConfig;
			overrideCycleLength = overrideCycleLengthConfig;
			List<int> list2 = list.Distinct().DefaultIfEmpty(60).ToList();
			timeSpendGCD = Math.Max(60, Utils.GCD(list2));
			timeSpendLCM = (int)Utils.LCM(Utils.LCM(list2) * 4, timeSpendGCD);
			timeSpendMaxIndividual = (int)Utils.LCM(list2.Max(), timeSpendGCD);
			profilingTickCount = timeSpendLCM * analysisVerificationCount;
			profilingEntryCount = profilingTickCount / timeSpendGCD;
			MultiLevelGranularity mlg = default(MultiLevelGranularity);
			mlg.levels = 2;
			mlg.entryCounts = new int[2] { timeSpendGCD, profilingEntryCount };
			mlg.ratios = new int[1] { timeSpendGCD };
			summarizer = new BlackboxBenchmarkSummarizer
			{
				analysis = this
			};
			profilingTsData = new TimeSeriesData<int>(perTickProfilingSize, mlg, summarizer);
			cycleDetectionData = new int[perTickProfilingSize * 2];
			stabilityDetectionData = new int[statsDiffSize];
			profilingTick = 0;
			phase = ((spraycoaterIds.Count <= 0) ? (useItemSaturationPhase ? BenchmarkPhase.ItemSaturation : BenchmarkPhase.Benchmarking) : BenchmarkPhase.SpraySaturation);
			averagingDataSize = pcSize + stationSize + factoryStatsSize;
			averagingDataRaw = new long[averagingDataSize];
			averagingDataStats = new int[averagingDataSize * analysisVerificationCount];
			Plugin.Log.LogDebug((object)("Profiling Mem Requirement: " + profilingTsData.Data.Length * 4));
			Plugin.Log.LogDebug((object)("Aggregation ticks: " + timeSpendGCD));
			Plugin.Log.LogDebug((object)("Per-cycle Analysis ticks: " + timeSpendLCM));
			forceNoStacking = forceNoStackingConfig;
			adaptiveStacking = adaptiveStackingConfig;
			if (continuousLogging)
			{
				Directory.CreateDirectory(FileLogPath + "\\DataAnalysis");
				continuousLogger = new StreamWriter($"{FileLogPath}\\DataAnalysis\\BenchmarkV4_CL_{blackbox.Id}.csv");
				WriteContinuousLoggingHeader();
			}
			if (!blackbox.analyseInBackground)
			{
				return;
			}
			profilingTaskCancel = new CancellationTokenSource();
			CancellationToken ct = profilingTaskCancel.Token;
			profilingTask = Task.Factory.StartNew(delegate
			{
				SimulateTillProfilingDone(ct);
			}, profilingTaskCancel.Token, TaskCreationOptions.PreferFairness, TaskScheduler.Default);
			profilingTask.ContinueWith(delegate(Task t)
			{
				Exception ex = t.Exception?.InnerException;
				if (ex != null)
				{
					Plugin.Log.LogError((object)ex);
				}
			}, TaskContinuationOptions.OnlyOnFaulted);
		}

		private void SimulateTillProfilingDone(CancellationToken ct)
		{
			while (blackbox.Status == BlackboxStatus.InAnalysis)
			{
				ct.ThrowIfCancellationRequested();
				PlanetFactorySimulation.SimulateGameTick(this);
			}
		}

		public override void Free()
		{
			if (continuousLogging)
			{
				continuousLogger.Dispose();
				continuousLogger = null;
			}
			analysedRecipe = null;
			if (blackbox.analyseInBackground)
			{
				if (profilingTask != null && profilingTaskCancel != null)
				{
					try
					{
						if (!profilingTask.IsCompleted)
						{
							profilingTaskCancel.Cancel();
							profilingTask.Wait();
						}
					}
					catch (AggregateException ex)
					{
						if (ex.InnerException is OperationCanceledException)
						{
							ManualLogSource log = Plugin.Log;
							int id = blackbox.Id;
							log.LogInfo((object)("Blackbox #" + id + " benchmarking was cancelled"));
						}
						else
						{
							Plugin.Log.LogError((object)ex);
						}
					}
					catch (Exception ex2)
					{
						Plugin.Log.LogError((object)ex2);
					}
					finally
					{
						profilingTaskCancel.Dispose();
						profilingTaskCancel = null;
					}
				}
				PlanetFactorySimulation.FreeSimulationFactory(simulationFactory);
			}
			if (logProfiledData)
			{
				DumpAnalysisToFile();
			}
			simulationFactory = null;
		}

		private void DumpAnalysisToFile()
		{
			Directory.CreateDirectory(FileLogPath + "\\DataAnalysis");
			using FileStream stream = new FileStream($"{FileLogPath}\\DataAnalysis\\BenchmarkV4_{blackbox.Id}.txt", FileMode.Create);
			using StreamWriter streamWriter = new StreamWriter(stream);
			int dataSize = profilingTsData.DataSize;
			streamWriter.WriteLine(dataSize);
			int[] data = profilingTsData.Data;
			int num = data.Length / dataSize;
			int num2 = 0;
			for (int i = 0; i < num; i++)
			{
				Span<long> span = MemoryMarshal.Cast<int, long>(new Span<int>(data, i * dataSize, pcSize));
				for (int j = 0; j < span.Length; j++)
				{
					long value = span[j];
					streamWriter.Write(value);
					streamWriter.Write(" ");
				}
				num2 += pcSize;
				for (int k = pcSize; k < dataSize; k++)
				{
					streamWriter.Write(data[num2++]);
					streamWriter.Write(" ");
				}
				streamWriter.WriteLine();
			}
			streamWriter.WriteLine();
			for (int l = 0; l < itemIds.Count; l++)
			{
				string value2 = LDB.ItemName(itemIds[l]);
				streamWriter.WriteLine(value2);
				ProduceConsumePair produceConsumePair = totalStats[l];
				streamWriter.WriteLine($"  Produced: {produceConsumePair.Produced}");
				streamWriter.WriteLine($"  Consumed: {produceConsumePair.Consumed}");
				streamWriter.WriteLine($"  Difference: {produceConsumePair.Produced - produceConsumePair.Consumed}");
			}
		}

		private void WriteContinuousLoggingHeader()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected I4, but got Unknown
			continuousLogger.Write("Phase,");
			continuousLogger.Write("Tick,");
			continuousLogger.Write("PC,");
			for (int i = 0; i < stationStorages.Length; i++)
			{
				ELogisticStorage effectiveLogic = stationStorages[i].effectiveLogic;
				string arg = (int)effectiveLogic switch
				{
					2 => "D", 
					1 => "S", 
					0 => "N", 
					_ => "U", 
				};
				string arg2 = LDB.ItemName(stationStorages[i].itemId).Replace(" ", "").Trim();
				continuousLogger.Write($"S{i}_{arg}_{arg2}_Entry,");
				continuousLogger.Write($"S{i}_{arg}_{arg2}_EntryInc,");
				continuousLogger.Write($"S{i}_{arg}_{arg2}_Exit,");
				continuousLogger.Write($"S{i}_{arg}_{arg2}_ExitInc,");
			}
			for (int j = 0; j < itemIds.Count; j++)
			{
				string text = LDB.ItemName(itemIds[j]).Replace(" ", "").Trim();
				continuousLogger.Write("F_P_" + text + ",");
				continuousLogger.Write("F_C_" + text + ",");
				continuousLogger.Write("S_P_" + text + ",");
				continuousLogger.Write("S_C_" + text + ",");
			}
			for (int k = 0; k < itemIds.Count; k++)
			{
				string text2 = LDB.ItemName(itemIds[k]).Replace(" ", "").Trim();
				continuousLogger.Write("T_P_" + text2 + ",");
				continuousLogger.Write("T_C_" + text2 + ",");
				continuousLogger.Write("T_D_" + text2 + ",");
			}
			continuousLogger.WriteLine("EOL");
		}

		private void WriteContinuousLoggingData(int level)
		{
			Span<int> span = profilingTsData.LevelEntryOffset(level, profilingTick);
			Span<int> span2 = ((phase == BenchmarkPhase.Averaging) ? new Span<int>(averagingDataStats, averagingDataStatsIdx % analysisVerificationCount, averagingDataSize) : span);
			continuousLogger.Write(phase.ToString());
			continuousLogger.Write(',');
			continuousLogger.Write(profilingTick);
			continuousLogger.Write(',');
			long value = MemoryMarshal.Cast<int, long>(span2.Slice(0, pcSize))[0];
			continuousLogger.Write(value);
			continuousLogger.Write(',');
			Span<StationEntryExit> span3 = MemoryMarshal.Cast<int, StationEntryExit>(span2.Slice(stationOffset, stationSize));
			for (int i = 0; i < stationStorages.Length; i++)
			{
				continuousLogger.Write(span3[i].EntryCount);
				continuousLogger.Write(',');
				continuousLogger.Write(span3[i].EntryInc);
				continuousLogger.Write(',');
				continuousLogger.Write(span3[i].ExitCount);
				continuousLogger.Write(',');
				continuousLogger.Write(span3[i].ExitInc);
				continuousLogger.Write(',');
			}
			Span<ProduceConsumePair> span4 = MemoryMarshal.Cast<int, ProduceConsumePair>(span2.Slice(factoryStatsOffset, factoryStatsSize));
			Span<ProduceConsumePair> span5 = MemoryMarshal.Cast<int, ProduceConsumePair>(span.Slice(stationStatsOffset, stationStatsSize));
			for (int j = 0; j < itemIds.Count; j++)
			{
				continuousLogger.Write(span4[j].Produced);
				continuousLogger.Write(',');
				continuousLogger.Write(span4[j].Consumed);
				continuousLogger.Write(',');
				continuousLogger.Write(span5[j].Produced);
				continuousLogger.Write(',');
				continuousLogger.Write(span5[j].Consumed);
				continuousLogger.Write(',');
			}
			for (int k = 0; k < itemIds.Count; k++)
			{
				continuousLogger.Write(totalStats[k].Produced);
				continuousLogger.Write(',');
				continuousLogger.Write(totalStats[k].Consumed);
				continuousLogger.Write(',');
				continuousLogger.Write(totalStats[k].Produced - totalStats[k].Consumed);
				continuousLogger.Write(',');
			}
			continuousLogger.WriteLine(0);
			if (phase == BenchmarkPhase.Averaging)
			{
				continuousLogger.Write("Averaging Total");
				continuousLogger.Write(',');
				continuousLogger.Write(profilingTick);
				continuousLogger.Write(',');
				continuousLogger.Write(averagingDataRaw[0]);
				continuousLogger.Write(',');
				Span<long> span6 = new Span<long>(averagingDataRaw);
				Span<long> span7 = span6.Slice(stationOffset, stationSize);
				for (int l = 0; l < stationStorages.Length; l++)
				{
					continuousLogger.Write(span7[4 * l]);
					continuousLogger.Write(',');
					continuousLogger.Write(span7[4 * l + 1]);
					continuousLogger.Write(',');
					continuousLogger.Write(span7[4 * l + 2]);
					continuousLogger.Write(',');
					continuousLogger.Write(span7[4 * l + 3]);
					continuousLogger.Write(',');
				}
				Span<long> span8 = span6.Slice(factoryStatsOffset, factoryStatsSize);
				for (int m = 0; m < itemIds.Count; m++)
				{
					continuousLogger.Write(span8[2 * m]);
					continuousLogger.Write(',');
					continuousLogger.Write(span8[2 * m + 1]);
					continuousLogger.Write(',');
					continuousLogger.Write(0);
					continuousLogger.Write(',');
					continuousLogger.Write(0);
					continuousLogger.Write(',');
				}
				for (int n = 0; n < itemIds.Count; n++)
				{
					continuousLogger.Write(totalStats[n].Produced);
					continuousLogger.Write(',');
					continuousLogger.Write(totalStats[n].Consumed);
					continuousLogger.Write(',');
					continuousLogger.Write(totalStats[n].Produced - totalStats[n].Consumed);
					continuousLogger.Write(',');
				}
				continuousLogger.WriteLine(0);
			}
		}

		private void LogItemStats()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Invalid comparison between Unknown and I4
			//IL_0126: Invalid comparison between Unknown and I4
			Span<int> span = profilingTsData.LevelEntryOffset(0, profilingTick);
			Span<ProduceConsumePair> span2 = MemoryMarshal.Cast<int, ProduceConsumePair>(span.Slice(factoryStatsOffset, factoryStatsSize));
			Span<ProduceConsumePair> span3 = MemoryMarshal.Cast<int, ProduceConsumePair>(span.Slice(stationStatsOffset, stationStatsSize));
			for (int i = 0; i < itemIds.Count; i++)
			{
				span2[i].Consumed += consumeRegister[itemIds[i]];
				span2[i].Produced += productRegister[itemIds[i]];
			}
			Span<StationEntryExit> span4 = MemoryMarshal.Cast<int, StationEntryExit>(span.Slice(stationOffset, stationSize));
			for (int j = 0; j < stationStorages.Length; j++)
			{
				int itemIdx = stationStorages[j].itemIdx;
				ELogisticStorage effectiveLogic = stationStorages[j].effectiveLogic;
				if ((int)effectiveLogic == 1)
				{
					span3[itemIdx].Consumed += span4[j].EntryCount - span4[j].ExitCount;
				}
				if ((int)effectiveLogic == 2)
				{
					span3[itemIdx].Produced += span4[j].ExitCount - span4[j].EntryCount;
				}
			}
		}

		private void LogTotalItemStats()
		{
			Span<int> span = profilingTsData.LevelEntryOffset(0, profilingTick);
			Span<int> span2 = span.Slice(factoryStatsOffset, factoryStatsSize);
			Span<int> span3 = span.Slice(stationStatsOffset, stationStatsSize);
			Span<int> span4 = MemoryMarshal.Cast<ProduceConsumePair, int>(new Span<ProduceConsumePair>(totalStats));
			for (int i = 0; i < span4.Length; i++)
			{
				span4[i] += span2[i];
				span4[i] += span3[i];
			}
			Span<int> span5 = span.Slice(statsDiffOffset, statsDiffSize);
			for (int j = 0; j < totalStats.Length; j++)
			{
				span5[j] = totalStats[j].Produced - totalStats[j].Consumed;
			}
		}

		private void InitializeStabilizationData(int value)
		{
			for (int i = 0; i < stabilityDetectionData.Length; i++)
			{
				stabilityDetectionData[i] = value;
			}
		}

		private void CheckStabilization_V2(StabilityDetectionAction action)
		{
			Span<int> span = profilingTsData.LevelEntryOffset(0, profilingTick).Slice(statsDiffOffset, statsDiffSize);
			for (int i = 0; i < span.Length; i++)
			{
				int num = ((action == StabilityDetectionAction.Max) ? (span[i] - stabilityDetectionData[i]) : (stabilityDetectionData[i] - span[i]));
				int num2 = (int)((float)Math.Abs(stabilityDetectionData[i]) * stabilityDetectionThreshold);
				if (num > num2)
				{
					stabilizedTick = profilingTick;
					stabilityDetectionData[i] = span[i];
				}
			}
		}

		private void CheckStabilization_Max()
		{
			Span<int> span = profilingTsData.LevelEntryOffset(0, profilingTick).Slice(statsDiffOffset, statsDiffSize);
			for (int i = 0; i < span.Length; i++)
			{
				if (span[i] > stabilityDetectionData[i])
				{
					stabilizedTick = profilingTick;
					stabilityDetectionData[i] = span[i];
				}
			}
		}

		private void CheckStabilization_Min()
		{
			Span<int> span = profilingTsData.LevelEntryOffset(0, profilingTick).Slice(statsDiffOffset, statsDiffSize);
			for (int i = 0; i < span.Length; i++)
			{
				if (span[i] < stabilityDetectionData[i])
				{
					stabilizedTick = profilingTick;
					stabilityDetectionData[i] = span[i];
				}
			}
		}

		private void ClearItemStats()
		{
			Span<int> span = profilingTsData.LevelEntryOffset(0, profilingTick);
			span.Slice(0, pcSize).Clear();
			span = profilingTsData.LevelEntryOffset(0, profilingTick);
			span.Slice(factoryStatsOffset, factoryStatsSize).Clear();
			span = profilingTsData.LevelEntryOffset(0, profilingTick);
			span.Slice(stationStatsOffset, stationStatsSize).Clear();
		}

		private void BoostSpraySaturation()
		{
			for (int i = 0; i < spraycoaterIds.Count; i++)
			{
				ref SpraycoaterComponent reference = ref simulationFactory.cargoTraffic.spraycoaterPool[spraycoaterIds[i]];
				if (reference.incCount > 0)
				{
					reference.incCount = reference.incCapacity;
					reference.extraIncCount = 0;
				}
			}
		}

		private void BoostProductionSaturation()
		{
			for (int i = 0; i < assemblerIds.Count; i++)
			{
				ref AssemblerComponent reference = ref simulationFactory.factorySystem.assemblerPool[assemblerIds[i]];
				if (reference.replicating)
				{
					for (int j = 0; j < reference.served.Length; j++)
					{
						reference.served[j] = reference.requireCounts[j] * 3;
					}
					for (int k = 0; k < reference.produced.Length; k++)
					{
						reference.produced[k] = reference.productCounts[k] * 5;
					}
				}
			}
			for (int l = 0; l < labIds.Count; l++)
			{
				ref LabComponent reference2 = ref simulationFactory.factorySystem.labPool[labIds[l]];
				if (reference2.replicating)
				{
					for (int m = 0; m < reference2.served.Length; m++)
					{
						reference2.served[m] = reference2.requireCounts[m] * 3;
					}
					for (int n = 0; n < reference2.produced.Length; n++)
					{
						reference2.produced[n] = reference2.productCounts[n] * 5;
					}
				}
			}
			for (int num = 0; num < fractionatorIds.Count; num++)
			{
				ref FractionatorComponent reference3 = ref simulationFactory.factorySystem.fractionatorPool[fractionatorIds[num]];
				if (reference3.fractionSuccess || reference3.productOutputCount > 0)
				{
					reference3.productOutputCount = reference3.productOutputMax;
					reference3.fluidOutputCount = reference3.fluidOutputMax;
					reference3.fluidInputCount = reference3.fluidInputMax;
				}
			}
		}

		private void EndGameTick_SpraySaturation()
		{
			profilingTsData.SummarizeAtHigherGranularity(profilingTick);
			if (continuousLogging && (profilingTick + 1) % timeSpendGCD == 0)
			{
				WriteContinuousLoggingData(1);
			}
			profilingTick++;
			ClearItemStats();
			BoostSpraySaturation();
			if (profilingTick % timeSpendGCD == 0)
			{
				Plugin.Log.LogDebug((object)("Spray Saturation Tick: " + profilingTick));
				if (profilingTick > timeSpendGCD * analysisVerificationCount)
				{
					int num = profilingTick / timeSpendGCD - 1;
					int num2 = 0;
					if (num > profilingEntryCount)
					{
						num2 = (num - profilingEntryCount) % profilingEntryCount;
						num = profilingEntryCount - 1;
					}
					bool flag = true;
					int num3 = num;
					while (flag && num3 >= num - analysisVerificationCount)
					{
						Span<int> span = profilingTsData.Level(1).Entry((num3 + num2) % profilingEntryCount).Slice(stationOffset, stationSize);
						for (int i = 0; i < stationSize; i++)
						{
							if (span[i] != 0)
							{
								flag = false;
								break;
							}
						}
						num3--;
					}
					if (flag)
					{
						spraySaturationTick = profilingTick;
						phase = BenchmarkPhase.SelfSpraySaturation;
						profilingTick = 0;
						ClearItemStats();
					}
				}
			}
			if (profilingTick >= totalTicks)
			{
				profilingTick = 0;
				Plugin.Log.LogDebug((object)"Analysis Failed");
				blackbox.NotifyAnalysisFailed();
			}
		}

		private void EndGameTick_SelfSpraySaturation()
		{
			profilingTick++;
			BoostSpraySaturation();
			if (profilingTick % timeSpendGCD == 0)
			{
				Plugin.Log.LogDebug((object)("Self Spray Saturation Tick: " + profilingTick));
			}
			if (profilingTick < spraySaturationTick)
			{
				for (int i = 0; i < spraycoaterIds.Count; i++)
				{
					ref SpraycoaterComponent reference = ref simulationFactory.cargoTraffic.spraycoaterPool[spraycoaterIds[i]];
					reference.incCount = 0;
					reference.extraIncCount = 0;
				}
			}
			if (profilingTick >= spraySaturationTick * 2)
			{
				phase = (useItemSaturationPhase ? BenchmarkPhase.ItemSaturation : BenchmarkPhase.Benchmarking);
				profilingTick = 0;
				ClearItemStats();
			}
		}

		private void EndGameTick_ItemSaturation()
		{
			profilingTsData.SummarizeAtHigherGranularity(profilingTick);
			if (continuousLogging && (profilingTick + 1) % timeSpendGCD == 0)
			{
				WriteContinuousLoggingData(1);
			}
			profilingTick++;
			ClearItemStats();
			BoostSpraySaturation();
			BoostProductionSaturation();
			if (profilingTick % timeSpendGCD == 0)
			{
				Plugin.Log.LogDebug((object)("Item Saturation Tick: " + profilingTick));
			}
			if (profilingTick % timeSpendMaxIndividual != 0 || profilingTick <= timeSpendMaxIndividual * analysisVerificationCount)
			{
				return;
			}
			int num = profilingTick / timeSpendGCD - 1;
			int num2 = 0;
			if (num > profilingEntryCount)
			{
				num2 = (num - profilingEntryCount) % profilingEntryCount;
				num = profilingEntryCount - 1;
			}
			int num3 = num - timeSpendMaxIndividual / timeSpendGCD * analysisVerificationCount;
			bool flag = true;
			int num4 = num;
			while (flag && num4 >= num3)
			{
				Span<int> span = profilingTsData.Level(1).Entry((num4 + num2) % profilingEntryCount).Slice(stationOffset, stationSize);
				for (int i = 0; i < stationSize; i++)
				{
					if (span[i] != 0)
					{
						flag = false;
						break;
					}
				}
				num4--;
			}
			if (flag)
			{
				InitializeStabilizationData(int.MaxValue);
				phase = BenchmarkPhase.Benchmarking;
				profilingTick = 0;
				ClearItemStats();
			}
		}

		private void BenchmarkingCycleDetection(int circularOffset, out Func<int, int, bool> indexEquals, out Func<int, int, int, bool> summarizeEquals)
		{
			indexEquals = delegate(int i1, int i2)
			{
				TimeSeriesData<int>.LevelSpan<int> levelSpan2 = profilingTsData.Level(1);
				Span<int> span3 = levelSpan2.Entry((i1 + circularOffset) % profilingEntryCount);
				levelSpan2 = profilingTsData.Level(1);
				Span<int> span4 = levelSpan2.Entry((i2 + circularOffset) % profilingEntryCount);
				for (int k = factoryStatsOffset; k < factoryStatsOffset + factoryStatsSize; k++)
				{
					if (span3[k] != span4[k])
					{
						return false;
					}
				}
				return true;
			};
			summarizeEquals = delegate(int i1, int i2, int stride)
			{
				Span<int> span = new Span<int>(cycleDetectionData, 0, perTickProfilingSize);
				Span<int> span2 = new Span<int>(cycleDetectionData, perTickProfilingSize, perTickProfilingSize);
				summarizer.Initialize(span);
				summarizer.Initialize(span2);
				for (int num = stride - 1; num >= 0; num--)
				{
					TimeSeriesData<int>.LevelSpan<int> levelSpan = profilingTsData.Level(1);
					Span<int> detailed = levelSpan.Entry((i1 - num + circularOffset) % profilingEntryCount);
					levelSpan = profilingTsData.Level(1);
					Span<int> detailed2 = levelSpan.Entry((i2 - num + circularOffset) % profilingEntryCount);
					summarizer.Summarize(detailed, span);
					summarizer.Summarize(detailed2, span2);
				}
				for (int j = factoryStatsOffset; j < factoryStatsOffset + factoryStatsSize; j++)
				{
					if (span[j] != span2[j])
					{
						return false;
					}
				}
				return true;
			};
		}

		private void EndGameTick_Benchmarking()
		{
			LogItemStats();
			LogTotalItemStats();
			CheckStabilization_V2(useItemSaturationPhase ? StabilityDetectionAction.Min : StabilityDetectionAction.Max);
			profilingTsData.SummarizeAtHigherGranularity(profilingTick);
			if (continuousLogging && (profilingTick + 1) % timeSpendGCD == 0)
			{
				WriteContinuousLoggingData(1);
			}
			profilingTick++;
			ClearItemStats();
			if (profilingTick % timeSpendGCD == 0)
			{
				Plugin.Log.LogDebug((object)("Profiling Tick: " + profilingTick));
			}
			if (profilingTick - stabilizedTick > timeSpendLCM && profilingTick % timeSpendLCM == 0)
			{
				Plugin.Log.LogDebug((object)"Checking cycles");
				int num = profilingTick / timeSpendGCD - 1;
				int circularOffset = 0;
				if (num > profilingEntryCount)
				{
					circularOffset = (num - profilingEntryCount) % profilingEntryCount;
					num = profilingEntryCount - 1;
				}
				BenchmarkingCycleDetection(circularOffset, out var indexEquals, out var summarizeEquals);
				if (CycleDetection.TryDetectCycles(num, 0, analysisVerificationCount, indexEquals, summarizeEquals, out var cycleLength))
				{
					int num2 = cycleLength * timeSpendGCD;
					Plugin.Log.LogDebug((object)$"Cycle Length of {num2} detected");
					MoveToAveragingPhase(num2);
				}
			}
			if (profilingTick >= totalTicks)
			{
				int num3 = Math.Min(timeSpendLCM, Math.Max(timeSpendMaxIndividual, 7200));
				Plugin.Log.LogDebug((object)$"Cycle Length of {num3} assumed");
				MoveToAveragingPhase(num3);
			}
		}

		private void MoveToAveragingPhase(int cycleLength)
		{
			observedCycleLength = cycleLength;
			if (shouldOverrideCycleLength)
			{
				Plugin.Log.LogDebug((object)$"Cycle Length overriden to {overrideCycleLength}");
				observedCycleLength = overrideCycleLength;
			}
			profilingTick = 0;
			ClearItemStats();
			phase = BenchmarkPhase.Averaging;
		}

		private void EndGameTick_Averaging()
		{
			LogItemStats();
			LogTotalItemStats();
			profilingTsData.SummarizeAtHigherGranularity(profilingTick);
			if (continuousLogging && (profilingTick + 1) % timeSpendGCD == 0)
			{
				WriteContinuousLoggingData(1);
			}
			profilingTick++;
			ClearItemStats();
			if (profilingTick % timeSpendGCD != 0)
			{
				return;
			}
			Plugin.Log.LogDebug((object)("Averaging Tick: " + profilingTick));
			int num = profilingTick / timeSpendGCD - 1;
			int num2 = 0;
			if (num > profilingEntryCount)
			{
				num2 = (num - profilingEntryCount) % profilingEntryCount;
				num = profilingEntryCount - 1;
			}
			int num3 = observedCycleLength;
			Span<int> span = profilingTsData.Level(1).Entry((num + num2) % profilingEntryCount);
			Span<long> span2 = new Span<long>(averagingDataRaw);
			int num4 = averagingDataStatsIdx % analysisVerificationCount;
			Span<int> span3 = new Span<int>(averagingDataStats, num4 * averagingDataSize, averagingDataSize);
			int num5 = 1;
			Span<long> span4 = MemoryMarshal.Cast<int, long>(span.Slice(0, num5 * 2));
			Span<long> span5 = span2.Slice(0, num5);
			for (int i = 0; i < num5; i++)
			{
				span5[i] += span4[i];
			}
			Span<int> span6 = span.Slice(stationOffset, stationSize);
			Span<long> span7 = span2.Slice(stationOffset, stationSize);
			for (int j = 0; j < stationSize; j++)
			{
				span7[j] += span6[j];
			}
			Span<int> span8 = span.Slice(factoryStatsOffset, factoryStatsSize);
			Span<long> span9 = span2.Slice(factoryStatsOffset, factoryStatsSize);
			for (int k = 0; k < factoryStatsSize; k++)
			{
				span9[k] += span8[k];
			}
			Span<long> span10 = MemoryMarshal.Cast<int, long>(span3.Slice(0, num5 * 2));
			for (int l = 0; l < num5; l++)
			{
				span10[l] = (long)Math.Round((double)(span5[l] * num3) / (double)profilingTick);
			}
			Span<int> span11 = span3.Slice(stationOffset, stationSize);
			for (int m = 0; m < stationSize; m++)
			{
				span11[m] = (int)Math.Round((double)(span7[m] * num3) / (double)profilingTick);
			}
			Span<ProduceConsumePair> span12 = MemoryMarshal.Cast<int, ProduceConsumePair>(span3.Slice(factoryStatsOffset, factoryStatsSize));
			for (int n = 0; n < factoryStatsSize; n++)
			{
				double a = (double)(span9[n] * num3) / (double)profilingTick;
				if (n % 2 == 0)
				{
					span12[n / 2].Produced = (int)Math.Round(a);
				}
				else
				{
					span12[n / 2].Consumed = (int)Math.Round(a);
				}
			}
			averagingDataStatsIdx++;
			bool flag = true;
			double num6 = 0.0;
			long num7 = 0L;
			long num8 = 0L;
			int num9 = 0;
			int num10 = 0;
			int num11 = 0;
			while (flag && num11 < analysisVerificationCount)
			{
				Span<int> span13 = new Span<int>(averagingDataStats, num11 * averagingDataSize, averagingDataSize);
				Span<long> span14 = MemoryMarshal.Cast<int, long>(span13.Slice(0, num5 * 2));
				for (int num12 = 0; num12 < num5; num12++)
				{
					long num13 = Math.Abs(span10[num12] - span14[num12]);
					float num14 = (float)span10[num12] * averagingThresholdPc;
					if (num13 > (long)num14)
					{
						flag = false;
						float num15 = (float)num13 / num14;
						if ((double)num15 > num6)
						{
							num6 = num15;
							num7 = span10[num12];
							num8 = span14[num12];
						}
					}
				}
				Span<int> span15 = span3.Slice(stationOffset, stationSize + factoryStatsSize);
				Span<int> span16 = span13.Slice(stationOffset, stationSize + factoryStatsSize);
				for (int num16 = 0; num16 < stationSize + factoryStatsSize; num16++)
				{
					int num17 = Math.Abs(span15[num16] - span16[num16]);
					float num18 = (float)span15[num16] * averagingThresholdItemStats;
					if (num17 > (int)num18)
					{
						flag = false;
						float num19 = (float)num17 / num18;
						if ((double)num19 > num6)
						{
							num6 = num19;
							num9 = span15[num16];
							num10 = span16[num16];
						}
					}
				}
				num11++;
			}
			if (flag)
			{
				Plugin.Log.LogDebug((object)"Stable!");
				GenerateRecipe_V2();
				blackbox.NotifyBlackboxed(analysedRecipe);
				return;
			}
			Plugin.Log.LogDebug((object)("Deviation: " + num6));
			if (num7 > 0)
			{
				Plugin.Log.LogDebug((object)("Cur Pc : " + num7));
				Plugin.Log.LogDebug((object)("Prev Pc: " + num8));
			}
			if (num9 > 0)
			{
				Plugin.Log.LogDebug((object)("Cur Stats : " + num9));
				Plugin.Log.LogDebug((object)("Prev Stats: " + num10));
			}
		}

		public override void EndGameTick()
		{
			if (blackbox.Status == BlackboxStatus.InAnalysis)
			{
				switch (phase)
				{
				case BenchmarkPhase.SpraySaturation:
					EndGameTick_SpraySaturation();
					break;
				case BenchmarkPhase.SelfSpraySaturation:
					EndGameTick_SelfSpraySaturation();
					break;
				case BenchmarkPhase.ItemSaturation:
					EndGameTick_ItemSaturation();
					break;
				case BenchmarkPhase.Benchmarking:
					EndGameTick_Benchmarking();
					break;
				case BenchmarkPhase.Averaging:
					EndGameTick_Averaging();
					break;
				}
			}
		}

		private void GenerateRecipe_V2()
		{
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Invalid comparison between Unknown and I4
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Invalid comparison between Unknown and I4
			long num = 0L;
			for (int i = 0; i < pcIds.Count; i++)
			{
				num += simulationFactory.powerSystem.consumerPool[pcIds[i]].idleEnergyPerTick;
			}
			long num2 = num * observedCycleLength;
			Span<int> span = new Span<int>(averagingDataStats, 0, averagingDataSize);
			long num3 = 0L;
			Span<long> span2 = MemoryMarshal.Cast<int, long>(span.Slice(0, pcSize));
			for (int j = 0; j < span2.Length; j++)
			{
				long num4 = span2[j];
				num3 += num4;
			}
			Dictionary<int, Dictionary<int, CNT>> dictionary = new Dictionary<int, Dictionary<int, CNT>>();
			Dictionary<int, Dictionary<int, CNTINC>> dictionary2 = new Dictionary<int, Dictionary<int, CNTINC>>();
			Span<StationEntryExit> span3 = MemoryMarshal.Cast<int, StationEntryExit>(span.Slice(stationOffset, stationSize));
			for (int k = 0; k < stationStorages.Length; k++)
			{
				int stationIdx = stationStorages[k].stationIdx;
				int itemId = stationStorages[k].itemId;
				ELogisticStorage effectiveLogic = stationStorages[k].effectiveLogic;
				ref StationEntryExit reference = ref span3[k];
				int num5 = reference.ExitCount - reference.EntryCount;
				int num6 = reference.ExitInc - reference.EntryInc;
				if ((int)effectiveLogic == 2 && num5 > 0)
				{
					if (!dictionary.ContainsKey(stationIdx))
					{
						dictionary[stationIdx] = new Dictionary<int, CNT>();
					}
					dictionary[stationIdx][itemId] = new CNT
					{
						count = num5
					};
				}
				else if ((int)effectiveLogic == 1 && num5 < 0)
				{
					if (!dictionary2.ContainsKey(stationIdx))
					{
						dictionary2[stationIdx] = new Dictionary<int, CNTINC>();
					}
					dictionary2[stationIdx][itemId] = new CNTINC
					{
						count = -num5,
						inc = -num6
					};
				}
			}
			Dictionary<int, int> dictionary3 = new Dictionary<int, int>();
			Dictionary<int, int> dictionary4 = new Dictionary<int, int>();
			Span<ProduceConsumePair> span4 = MemoryMarshal.Cast<int, ProduceConsumePair>(span.Slice(factoryStatsOffset, factoryStatsSize));
			for (int l = 0; l < itemIds.Count; l++)
			{
				if (span4[l].Produced > 0)
				{
					dictionary3[itemIds[l]] = span4[l].Produced;
				}
				if (span4[l].Consumed > 0)
				{
					dictionary4[itemIds[l]] = span4[l].Consumed;
				}
			}
			Plugin.Log.LogDebug((object)$"Idle Energy per cycle: {num2}");
			Plugin.Log.LogDebug((object)$"Working Energy per cycle: {num3}");
			Plugin.Log.LogDebug((object)$"Idle Power: {num2 / observedCycleLength * 60}");
			Plugin.Log.LogDebug((object)$"Working Power: {num3 / observedCycleLength * 60}");
			Plugin.Log.LogDebug((object)"Consumed");
			foreach (KeyValuePair<int, int> item in dictionary4)
			{
				string arg = LDB.ItemName(item.Key);
				Plugin.Log.LogDebug((object)$"  {item.Value} {arg}");
			}
			Plugin.Log.LogDebug((object)"Produced");
			foreach (KeyValuePair<int, int> item2 in dictionary3)
			{
				string arg2 = LDB.ItemName(item2.Key);
				Plugin.Log.LogDebug((object)$"  {item2.Value} {arg2}");
			}
			Plugin.Log.LogDebug((object)"Inputs");
			foreach (KeyValuePair<int, Dictionary<int, CNT>> item3 in dictionary)
			{
				Plugin.Log.LogDebug((object)$"  Station #{item3.Key}:");
				foreach (KeyValuePair<int, CNT> item4 in item3.Value)
				{
					string arg3 = LDB.ItemName(item4.Key);
					Plugin.Log.LogDebug((object)$"    {item4.Value} {arg3}");
				}
			}
			Plugin.Log.LogDebug((object)"Outputs");
			foreach (KeyValuePair<int, Dictionary<int, CNTINC>> item5 in dictionary2)
			{
				Plugin.Log.LogDebug((object)$"  Station #{item5.Key}:");
				foreach (KeyValuePair<int, CNTINC> item6 in item5.Value)
				{
					string arg4 = LDB.ItemName(item6.Key);
					Plugin.Log.LogDebug((object)$"    {item6.Value} {arg4}");
				}
			}
			Plugin.Log.LogDebug((object)$"Time (in ticks): {observedCycleLength}");
			Plugin.Log.LogDebug((object)$"Time (in seconds): {(float)observedCycleLength / 60f}");
			analysedRecipe = new BlackboxRecipe
			{
				idleEnergyPerTick = num,
				workingEnergyPerTick = num3 / observedCycleLength,
				timeSpend = observedCycleLength,
				produces = dictionary3,
				consumes = dictionary4,
				inputs = dictionary,
				outputs = dictionary2
			};
		}

		public override void LogPowerConsumer()
		{
			Span<long> span = MemoryMarshal.Cast<int, long>(profilingTsData.LevelEntryOffset(0, profilingTick).Slice(0, pcSize));
			for (int i = 0; i < pcIds.Count; i++)
			{
				ref PowerConsumerComponent reference = ref simulationFactory.powerSystem.consumerPool[pcIds[i]];
				span[0] += reference.requiredEnergy;
			}
		}

		public override bool ShouldInterceptAssembler(FactorySystem factorySystem, int assemblerId)
		{
			if (factorySystem == simulationFactory.factorySystem)
			{
				return assemblerIds.Contains(assemblerId);
			}
			return false;
		}

		public override bool ShouldInterceptLab(FactorySystem factorySystem, int labId)
		{
			if (factorySystem == simulationFactory.factorySystem)
			{
				return labIds.Contains(labId);
			}
			return false;
		}

		public override bool ShouldInterceptSpraycoater(CargoTraffic cargoTraffic, int spraycoaterId)
		{
			if (cargoTraffic == simulationFactory.cargoTraffic)
			{
				return spraycoaterIds.Contains(spraycoaterId);
			}
			return false;
		}

		public override bool ShouldInterceptFractionator(FactorySystem factorySystem, int fractionatorId)
		{
			if (factorySystem == simulationFactory.factorySystem)
			{
				return fractionatorIds.Contains(fractionatorId);
			}
			return false;
		}

		public override void AdjustStationStorageCount()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Invalid comparison between Unknown and I4
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Invalid comparison between Unknown and I4
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Invalid comparison between Unknown and I4
			StationComponent[] stationPool = simulationFactory.transport.stationPool;
			for (int i = 0; i < stationStorages.Length; i++)
			{
				ref StationStorageData reference = ref stationStorages[i];
				StationComponent obj = stationPool[reference.stationId];
				int[] needs = obj.needs;
				ref StationStore reference2 = ref obj.storage[reference.storageIdx];
				int count = reference2.count;
				int max = reference2.max;
				int inc = reference2.inc;
				switch (phase)
				{
				case BenchmarkPhase.SpraySaturation:
				case BenchmarkPhase.SelfSpraySaturation:
					if ((int)reference.effectiveLogic == 2)
					{
						int num2 = (reference.isSpray ? (max / 2) : 0);
						inc = 0;
						count = num2;
					}
					needs[reference.storageIdx] = 0;
					break;
				case BenchmarkPhase.ItemSaturation:
					if ((int)reference.effectiveLogic == 2)
					{
						int num3 = max / 2;
						inc = 0;
						count = num3;
					}
					needs[reference.storageIdx] = 0;
					break;
				case BenchmarkPhase.Benchmarking:
				case BenchmarkPhase.Averaging:
					if ((int)reference.effectiveLogic == 2)
					{
						int num = max / 2;
						inc = 0;
						count = num;
					}
					needs[reference.storageIdx] = reference2.itemId;
					break;
				}
				reference2.count = count;
				reference2.inc = inc;
			}
		}

		public override void LogStationEntryBefore()
		{
			LogStationEntryExit(StationEntryExitRecordAction.EntryBefore);
		}

		public override void LogStationEntryAfter()
		{
			LogStationEntryExit(StationEntryExitRecordAction.EntryAfter);
		}

		public override void LogStationExitBefore()
		{
			LogStationEntryExit(StationEntryExitRecordAction.ExitBefore);
		}

		public override void LogStationExitAfter()
		{
			LogStationEntryExit(StationEntryExitRecordAction.ExitAfter);
		}

		private void LogStationEntryExit(StationEntryExitRecordAction recordAction)
		{
			Span<StationEntryExit> span = MemoryMarshal.Cast<int, StationEntryExit>(profilingTsData.LevelEntryOffset(0, profilingTick).Slice(stationOffset, stationSize));
			StationComponent[] stationPool = simulationFactory.transport.stationPool;
			for (int i = 0; i < stationStorages.Length; i++)
			{
				ref StationStorageData reference = ref stationStorages[i];
				ref StationStore reference2 = ref stationPool[reference.stationId].storage[reference.storageIdx];
				ref StationEntryExit reference3 = ref span[i];
				switch (recordAction)
				{
				case StationEntryExitRecordAction.EntryBefore:
					reference3.EntryCount = reference2.count;
					reference3.EntryInc = reference2.inc;
					break;
				case StationEntryExitRecordAction.EntryAfter:
					reference3.EntryCount = reference2.count - reference3.EntryCount;
					reference3.EntryInc = reference2.inc - reference3.EntryInc;
					break;
				case StationEntryExitRecordAction.ExitBefore:
					reference3.ExitCount = reference2.count;
					reference3.ExitInc = reference2.inc;
					break;
				case StationEntryExitRecordAction.ExitAfter:
					reference3.ExitCount -= reference2.count;
					reference3.ExitInc -= reference2.inc;
					break;
				}
			}
		}

		public override void DoInserterAdaptiveStacking()
		{
			if (adaptiveStacking || forceNoStacking)
			{
				for (int i = 0; i < inserterIds.Count; i++)
				{
					PlanetFactorySimulation.DoAdaptiveStacking(ref simulationFactory.factorySystem.inserterPool[inserterIds[i]], simulationFactory, forceNoStacking);
				}
			}
		}
	}
	public abstract class BlackboxBenchmarkBase : BlackboxAnalysis
	{
		public readonly int[] productRegister = new int[12000];

		public readonly int[] consumeRegister = new int[12000];

		protected BlackboxBenchmarkBase(Blackbox blackbox)
			: base(blackbox)
		{
		}

		public void BeginGameTick()
		{
			Array.Clear(productRegister, 0, 12000);
			Array.Clear(consumeRegister, 0, 12000);
		}

		public virtual void EndGameTick()
		{
		}

		public virtual void LogPowerConsumer()
		{
		}

		public virtual void AdjustStationStorageCount()
		{
		}

		public virtual void LogStationEntryBefore()
		{
		}

		public virtual void LogStationEntryAfter()
		{
		}

		public virtual void LogStationExitBefore()
		{
		}

		public virtual void LogStationExitAfter()
		{
		}

		public virtual void DoInserterAdaptiveStacking()
		{
		}

		public virtual bool ShouldInterceptAssembler(FactorySystem factorySystem, int assemblerId)
		{
			return false;
		}

		public virtual bool ShouldInterceptLab(FactorySystem factorySystem, int labId)
		{
			return false;
		}

		public virtual bool ShouldInterceptSpraycoater(CargoTraffic cargoTraffic, int spraycoaterId)
		{
			return false;
		}

		public virtual bool ShouldInterceptFractionator(FactorySystem factorySystem, int fractionatorId)
		{
			return false;
		}
	}
	public class BlackboxGatewayMethods
	{
		private static List<BlackboxBenchmarkBase> benchmarks = new List<BlackboxBenchmarkBase>();

		private static readonly Action<BlackboxBenchmarkBase> actionAfterPowerConsumerComponents = delegate(BlackboxBenchmarkBase b)
		{
			b.LogPowerConsumer();
		};

		private static readonly Action<BlackboxBenchmarkBase> actionBeforeStationBeltInput = delegate(BlackboxBenchmarkBase b)
		{
			b.AdjustStationStorageCount();
			b.LogStationEntryBefore();
		};

		private static readonly Action<BlackboxBenchmarkBase> actionAfterStationBeltInput = delegate(BlackboxBenchmarkBase b)
		{
			b.LogStationEntryAfter();
		};

		private static readonly Action<BlackboxBenchmarkBase> actionBeforeStationBeltOutput = delegate(BlackboxBenchmarkBase b)
		{
			b.AdjustStationStorageCount();
			b.LogStationExitBefore();
		};

		private static readonly Action<BlackboxBenchmarkBase> actionAfterStationBeltOutput = delegate(BlackboxBenchmarkBase b)
		{
			b.LogStationExitAfter();
			b.DoInserterAdaptiveStacking();
		};

		public static void GameTick_AfterPowerConsumerComponents(PlanetFactory factory)
		{
			DoForRelevantBenchmarks(factory, actionAfterPowerConsumerComponents);
		}

		public static void GameTick_BeforeStationBeltInput(PlanetFactory factory)
		{
			DoForRelevantBenchmarks(factory, actionBeforeStationBeltInput);
		}

		public static void GameTick_AfterStationBeltInput(PlanetFactory factory)
		{
			DoForRelevantBenchmarks(factory, actionAfterStationBeltInput);
		}

		public static void GameTick_BeforeStationBeltOutput(PlanetFactory factory)
		{
			DoForRelevantBenchmarks(factory, actionBeforeStationBeltOutput);
		}

		public static void GameTick_AfterStationBeltOutput(PlanetFactory factory)
		{
			DoForRelevantBenchmarks(factory, actionAfterStationBeltOutput);
		}

		public static void DoForRelevantBenchmarks(PlanetFactory factory, Action<BlackboxBenchmarkBase> action)
		{
			if (DSPGame.IsMenuDemo)
			{
				return;
			}
			foreach (BlackboxBenchmarkBase benchmark in benchmarks)
			{
				if (benchmark.blackbox.Status == BlackboxStatus.InAnalysis)
				{
					if (!benchmark.factoryRef.TryGetTarget(out var target))
					{
						Plugin.Log.LogError((object)"PlanetFactory instance pulled out from under BlackboxBenchmark in DoForRelevantBenchmarks");
					}
					else if (target == factory)
					{
						action(benchmark);
					}
				}
			}
		}

		public static void GameTick_Begin()
		{
			benchmarks = (from x in BlackboxManager.Instance.blackboxes
				where x.Status == BlackboxStatus.InAnalysis && !x.analyseInBackground && x.Analysis is BlackboxBenchmarkBase
				select x.Analysis as BlackboxBenchmarkBase).ToList();
			foreach (BlackboxBenchmarkBase benchmark in benchmarks)
			{
				benchmark.BeginGameTick();
			}
		}

		public static void GameTick_End()
		{
			foreach (BlackboxBenchmarkBase benchmark in benchmarks)
			{
				if (benchmark.blackbox.Status == BlackboxStatus.InAnalysis)
				{
					benchmark.EndGameTick();
				}
			}
		}

		public static uint InterceptAssemblerInternalUpdate(FactorySystem factorySystem, ref AssemblerComponent assembler, float power, int[] productRegister, int[] consumeRegister)
		{
			foreach (BlackboxBenchmarkBase benchmark in benchmarks)
			{
				if (benchmark.blackbox.Status == BlackboxStatus.InAnalysis && benchmark.ShouldInterceptAssembler(factorySystem, assembler.id))
				{
					return (!PlanetFactorySimulation.IsAssemblerStacking(ref assembler)) ? ((AssemblerComponent)(ref assembler)).InternalUpdate(1f, benchmark.productRegister, benchmark.consumeRegister) : 0u;
				}
			}
			return ((AssemblerComponent)(ref assembler)).InternalUpdate(power, productRegister, consumeRegister);
		}

		public static uint InterceptFractionatorInternalUpdate(FactorySystem factorySystem, int fractionatorId, float power, SignData[] entitySignPool, int[] productRegister, int[] consumeRegister)
		{
			foreach (BlackboxBenchmarkBase benchmark in benchmarks)
			{
				if (benchmark.blackbox.Status == BlackboxStatus.InAnalysis && benchmark.ShouldInterceptFractionator(factorySystem, fractionatorId))
				{
					return ((FractionatorComponent)(ref factorySystem.fractionatorPool[fractionatorId])).InternalUpdate(factorySystem.factory, 1f, entitySignPool, benchmark.productRegister, benchmark.consumeRegister);
				}
			}
			return ((FractionatorComponent)(ref factorySystem.fractionatorPool[fractionatorId])).InternalUpdate(factorySystem.factory, power, entitySignPool, productRegister, consumeRegister);
		}

		public static uint InterceptLabInternalUpdateAssemble(FactorySystem factorySystem, int labId, float power, int[] productRegister, int[] consumeRegister)
		{
			foreach (BlackboxBenchmarkBase benchmark in benchmarks)
			{
				if (benchmark.blackbox.Status == BlackboxStatus.InAnalysis && benchmark.ShouldInterceptLab(factorySystem, labId))
				{
					return ((LabComponent)(ref factorySystem.labPool[labId])).InternalUpdateAssemble(1f, benchmark.productRegister, benchmark.consumeRegister);
				}
			}
			return ((LabComponent)(ref factorySystem.labPool[labId])).InternalUpdateAssemble(power, productRegister, consumeRegister);
		}

		public static void InterceptSpraycoaterInternalUpdate(CargoTraffic cargoTraffic, int spraycoaterId, AnimData[] animPool, int[] consumeRegister)
		{
			foreach (BlackboxBenchmarkBase benchmark in benchmarks)
			{
				if (benchmark.blackbox.Status == BlackboxStatus.InAnalysis && benchmark.ShouldInterceptSpraycoater(cargoTraffic, spraycoaterId))
				{
					((SpraycoaterComponent)(ref cargoTraffic.spraycoaterPool[spraycoaterId])).InternalUpdate(cargoTraffic, animPool, benchmark.consumeRegister);
					return;
				}
			}
			((SpraycoaterComponent)(ref cargoTraffic.spraycoaterPool[spraycoaterId])).InternalUpdate(cargoTraffic, animPool, consumeRegister);
		}
	}
	[HarmonyPatch]
	internal class BlackboxBenchmarkPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(FactorySystem), "GameTickBeforePower")]
		public static void FactorySystem__GameTickBeforePower(FactorySystem __instance)
		{
			BlackboxGatewayMethods.GameTick_AfterPowerConsumerComponents(__instance.factory);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MultithreadSystem), "PreparePowerSystemFactoryData")]
		public static void MultithreadSystem__PreparePowerSystemFactoryData(PlanetFactory[] _factories)
		{
			for (int i = 0; i < _factories.Length; i++)
			{
				BlackboxGatewayMethods.GameTick_AfterPowerConsumerComponents(_factories[i]);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlanetTransport), "GameTick_InputFromBelt")]
		public static void PlanetTransport__GameTick_InputFromBeltPrefix(PlanetTransport __instance)
		{
			BlackboxGatewayMethods.GameTick_BeforeStationBeltInput(__instance.factory);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlanetTransport), "GameTick_InputFromBelt")]
		public static void PlanetTransport__GameTick_InputFromBeltPostfix(PlanetTransport __instance)
		{
			BlackboxGatewayMethods.GameTick_AfterStationBeltInput(__instance.factory);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlanetTransport), "GameTick_OutputToBelt")]
		public static void PlanetTransport__GameTick_OutputToBeltPrefix(PlanetTransport __instance)
		{
			BlackboxGatewayMethods.GameTick_BeforeStationBeltOutput(__instance.factory);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlanetTransport), "GameTick_OutputToBelt")]
		public static void PlanetTransport__GameTick_OutputToBeltPostfix(PlanetTransport __instance)
		{
			BlackboxGatewayMethods.GameTick_AfterStationBeltOutput(__instance.factory);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameStatData), "PrepareTick")]
		public static void GameStatData_PrepareTick()
		{
			BlackboxGatewayMethods.GameTick_Begin();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameStatData), "GameTick")]
		public static void GameStatData__GameTick()
		{
			BlackboxGatewayMethods.GameTick_End();
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(FactorySystem), "GameTick", new Type[]
		{
			typeof(long),
			typeof(bool)
		})]
		[HarmonyPatch(typeof(FactorySystem), "GameTick", new Type[]
		{
			typeof(long),
			typeof(bool),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static IEnumerable<CodeInstruction> InterceptAssemblerInternalUpdatePatch(IEnumerable<CodeInstruction> code, ILGenerator generator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, generator);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[5]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.Method(typeof(AssemblerComponent), "InternalUpdate", (Type[])null, (Type[])null))), (string)null)
			});
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null)
			});
			val.Advance(4);
			val.SetOperandAndAdvance((object)AccessTools.Method(typeof(BlackboxGatewayMethods), "InterceptAssemblerInternalUpdate", (Type[])null, (Type[])null));
			return val.InstructionEnumeration();
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(FactorySystem), "GameTick", new Type[]
		{
			typeof(long),
			typeof(bool)
		})]
		[HarmonyPatch(typeof(FactorySystem), "GameTick", new Type[]
		{
			typeof(long),
			typeof(bool),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static IEnumerable<CodeInstruction> InterceptFractionatorInternalUpdatePatch(IEnumerable<CodeInstruction> code, ILGenerator generator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, generator);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[11]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.LoadsField(ci, AccessTools.Field(typeof(FactorySystem), "fractionatorPool"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldelema, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.LoadsField(ci, AccessTools.Field(typeof(FactorySystem), "factory"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.Method(typeof(FractionatorComponent), "InternalUpdate", (Type[])null, (Type[])null))), (string)null)
			});
			val.Advance(1);
			val.RemoveInstruction();
			val.Advance(1);
			val.RemoveInstruction();
			val.RemoveInstruction();
			val.RemoveInstruction();
			val.Advance(4);
			val.SetOperandAndAdvance((object)AccessTools.Method(typeof(BlackboxGatewayMethods), "InterceptFractionatorInternalUpdate", (Type[])null, (Type[])null));
			return val.InstructionEnumeration();
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(FactorySystem), "GameTickLabProduceMode", new Type[]
		{
			typeof(long),
			typeof(bool)
		})]
		[HarmonyPatch(typeof(FactorySystem), "GameTickLabProduceMode", new Type[]
		{
			typeof(long),
			typeof(bool),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static IEnumerable<CodeInstruction> InterceptLabInternalUpdateAssemblePatch(IEnumerable<CodeInstruction> code, ILGenerator generator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, generator);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[8]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.LoadsField(ci, AccessTools.Field(typeof(FactorySystem), "labPool"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldelema, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.Method(typeof(LabComponent), "InternalUpdateAssemble", (Type[])null, (Type[])null))), (string)null)
			});
			val.Advance(1);
			val.RemoveInstruction();
			val.Advance(1);
			val.RemoveInstruction();
			val.Advance(3);
			val.SetOperandAndAdvance((object)AccessTools.Method(typeof(BlackboxGatewayMethods), "InterceptLabInternalUpdateAssemble", (Type[])null, (Type[])null));
			return val.InstructionEnumeration();
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(CargoTraffic), "SpraycoaterGameTick")]
		private static IEnumerable<CodeInstruction> InterceptSpraycoaterInternalUpdatePatch(IEnumerable<CodeInstruction> code, ILGenerator generator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, generator);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[8]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.LoadsField(ci, AccessTools.Field(typeof(CargoTraffic), "spraycoaterPool"), false)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldelema, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdarg(ci, (int?)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.Method(typeof(SpraycoaterComponent), "InternalUpdate", (Type[])null, (Type[])null))), (string)null)
			});
			val.Advance(1);
			val.RemoveInstruction();
			val.Advance(1);
			val.RemoveInstruction();
			val.RemoveInstruction();
			val.Advance(2);
			val.SetOperandAndAdvance((object)AccessTools.Method(typeof(BlackboxGatewayMethods), "InterceptSpraycoaterInternalUpdate", (Type[])null, (Type[])null));
			return val.InstructionEnumeration();
		}
	}
	public class BlackboxFingerprint
	{
		private BlackboxSelection selection;

		private BlackboxFingerprint(BlackboxSelection selection)
		{
			this.selection = selection;
		}

		public static BlackboxFingerprint CreateFrom(BlackboxSelection selection)
		{
			return new BlackboxFingerprint(selection);
		}

		public override bool Equals(object obj)
		{
			BlackboxFingerprint blackboxFingerprint = obj as BlackboxFingerprint;
			if (obj == null)
			{
				return false;
			}
			if (selection.factoryIndex == blackboxFingerprint.selection.factoryIndex && selection.entityIds.SetEquals((IEnumerable<int>)blackboxFingerprint.selection.entityIds))
			{
				return true;
			}
			return false;
		}

		public override int GetHashCode()
		{
			return ((object)selection.entityIds).GetHashCode();
		}
	}
	public class BlackboxHighlight
	{
		public int blackboxId;

		public List<int> warningIds = new List<int>();

		public const int blackboxSignalId = 60001;

		public int hoverBlackboxId;

		private List<BoxGizmo> hoverGizmos = new List<BoxGizmo>();

		private const int saveLogicVersion = 1;

		public void RequestHighlight(Blackbox blackbox)
		{
			if (blackbox == null)
			{
				ClearHighlight();
			}
			else if (blackboxId != blackbox.Id)
			{
				if (blackboxId > 0 && blackboxId != blackbox.Id)
				{
					ClearHighlight();
				}
				blackboxId = blackbox.Id;
				DoHighlight(blackbox);
			}
		}

		public void DoHighlight(Blackbox blackbox)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!blackbox.FactoryRef.TryGetTarget(out var target))
			{
				Plugin.Log.LogError((object)"PlanetFactory instance pulled out from under a blackbox simulation in DoHighlight");
				return;
			}
			ImmutableSortedSet<int> entityIds = blackbox.Selection.entityIds;
			WarningSystem warningSystem = GameMain.data.warningSystem;
			EntityData[] entityPool = target.entityPool;
			Enumerator<int> enumerator = entityIds.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					int current = enumerator.Current;
					ref EntityData reference = ref entityPool[current];
					if (reference.beltId <= 0 && reference.inserterId <= 0)
					{
						ref WarningData reference2 = ref warningSystem.NewWarningData(target.index, current, 60001);
						warningIds.Add(reference2.id);
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public void StopHighlight()
		{
			WarningSystem warningSystem = GameMain.data.warningSystem;
			foreach (int warningId in warningIds)
			{
				warningSystem.RemoveWarningData(warningId);
			}
			warningIds.Clear();
		}

		public void ClearHighlight()
		{
			StopHighlight();
			blackboxId = 0;
		}

		public void SetHoverHighlight(Blackbox blackbox)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			int num = blackbox?.Id ?? 0;
			if (num == hoverBlackboxId)
			{
				DoHoverHighlightForBelts(blackbox);
				return;
			}
			hoverBlackboxId = num;
			if (blackbox == null)
			{
				foreach (BoxGizmo hoverGizmo in hoverGizmos)
				{
					if (Object.op_Implicit((Object)(object)hoverGizmo))
					{
						((GizmoBase)hoverGizmo).Close();
					}
				}
				hoverGizmos.Clear();
			}
			else
			{
				if (!blackbox.FactoryRef.TryGetTarget(out var target))
				{
					return;
				}
				EntityData[] entityPool = target.entityPool;
				Enumerator<int> enumerator2 = blackbox.Selection.entityIds.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						int current2 = enumerator2.Current;
						ref EntityData reference = ref entityPool[current2];
						if (reference.inserterId <= 0 && reference.beltId <= 0)
						{
							PrefabDesc prefabDesc = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)reference.protoId).prefabDesc;
							BoxGizmo val = BoxGizmo.Create(reference.pos, reference.rot, prefabDesc.selectCenter, prefabDesc.selectSize);
							val.multiplier = 1f;
							val.alphaMultiplier = prefabDesc.selectAlpha;
							val.fadeInScale = 1.3f;
							val.fadeInTime = 0.05f;
							val.fadeInFalloff = 0.5f;
							val.fadeOutScale = 1.3f;
							val.fadeOutTime = 0.05f;
							val.fadeOutFalloff = 0.5f;
							val.color = Color.white;
							((GizmoBase)val).Open();
							hoverGizmos.Add(val);
						}
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
				DoHoverHighlightForBelts(blackbox);
			}
		}

		private void DoHoverHighlightForBelts(Blackbox blackbox)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (blackbox == null)
			{
				return;
			}
			if (!blackbox.FactoryRef.TryGetTarget(out var target))
			{
				Plugin.Log.LogError((object)"PlanetFactory instance pulled out from under a blackbox simulation in DoHoverHighlightForBelts");
				return;
			}
			EntityData[] entityPool = target.entityPool;
			CargoTraffic cargoTraffic = target.cargoTraffic;
			BeltComponent[] beltPool = cargoTraffic.beltPool;
			CargoPath[] pathPool = cargoTraffic.pathPool;
			Enumerator<int> enumerator = blackbox.Selection.entityIds.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					int current = enumerator.Current;
					int beltId = entityPool[current].beltId;
					if (beltId > 0)
					{
						ref BeltComponent reference = ref beltPool[beltId];
						ref CargoPath reference2 = ref pathPool[reference.segPathId];
						int id = reference.id;
						int id2 = reference2.id;
						reference.id = beltId;
						reference2.id = reference.segPathId;
						cargoTraffic.SetBeltState(beltId, 100);
						reference.id = id;
						reference2.id = id2;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public void PreserveVanillaSaveBefore()
		{
			StopHighlight();
		}

		public void PreserveVanillaSaveAfter()
		{
			if (blackboxId > 0)
			{
				Blackbox blackbox = BlackboxManager.Instance.blackboxes.Find((Blackbox x) => x.Id == blackboxId);
				if (blackbox != null)
				{
					DoHighlight(blackbox);
				}
			}
		}

		public void Export(BinaryWriter w)
		{
			w.Write(1);
			w.Write(blackboxId);
		}

		public void Import(BinaryReader r)
		{
			r.ReadInt32();
			blackboxId = r.ReadInt32();
			PreserveVanillaSaveAfter();
		}
	}
	public class BlackboxManager
	{
		private static int blackboxIdCounter = 1;

		public List<Blackbox> blackboxes = new List<Blackbox>();

		public List<Blackbox> blackboxesMarkedForRemoval = new List<Blackbox>();

		public AutoBlackbox autoBlackbox = new AutoBlackbox();

		public BlackboxHighlight highlight = new BlackboxHighlight();

		private const int saveLogicVersion = 1;

		public static BlackboxManager Instance { get; } = new BlackboxManager();


		public Blackbox CreateForSelection(BlackboxSelection selection)
		{
			lock (Instance)
			{
				int id = blackboxIdCounter;
				blackboxIdCounter++;
				Blackbox blackbox = new Blackbox(id, selection);
				blackboxes.Add(blackbox);
				return blackbox;
			}
		}

		public void MarkBlackboxForRemoval(Blackbox blackbox)
		{
			lock (Instance)
			{
				blackboxesMarkedForRemoval.Add(blackbox);
			}
		}

		public void RemoveMarkedBlackboxes()
		{
			lock (Instance)
			{
				foreach (Blackbox item in blackboxesMarkedForRemoval)
				{
					if (item.Id == highlight.blackboxId)
					{
						highlight.ClearHighlight();
					}
					item.Simulation?.EndBlackboxing();
					item.Analysis?.Free();
					blackboxes.Remove(item);
				}
				blackboxesMarkedForRemoval.Clear();
			}
		}

		public void PauseBlackboxBelts(PlanetFactory factory)
		{
			foreach (Blackbox blackbox in blackboxes)
			{
				BlackboxSimulation simulation = blackbox.Simulation;
				if (simulation != null && simulation.isBlackboxSimulating && blackbox.FactoryRef.TryGetTarget(out var target) && target == factory)
				{
					blackbox.Simulation.PauseBelts();
				}
			}
		}

		public void ResumeBlackboxBelts(PlanetFactory factory)
		{
			foreach (Blackbox blackbox in blackboxes)
			{
				BlackboxSimulation simulation = blackbox.Simulation;
				if (simulation != null && simulation.isBlackboxSimulating && blackbox.FactoryRef.TryGetTarget(out var target) && target == factory)
				{
					blackbox.Simulation.ResumeBelts();
				}
			}
		}

		public void SimulateBlackboxes()
		{
			foreach (Blackbox blackbox in blackboxes)
			{
				blackbox.Simulation?.Simulate();
			}
		}

		public void GameTick()
		{
			foreach (Blackbox blackbox in blackboxes)
			{
				blackbox.GameTick();
			}
			autoBlackbox.GameTick();
		}

		public void ClearAll()
		{
			lock (Instance)
			{
				foreach (Blackbox blackbox in blackboxes)
				{
					blackbox.Simulation?.EndBlackboxing();
					blackbox.Analysis?.Free();
				}
				blackboxes.Clear();
				blackboxesMarkedForRemoval.Clear();
				blackboxIdCounter = 1;
			}
			autoBlackbox.isActive = false;
			highlight.ClearHighlight();
		}

		public void PreserveVanillaSaveBefore()
		{
			RemoveMarkedBlackboxes();
			highlight.PreserveVanillaSaveBefore();
			for (int i = 0; i < blackboxes.Count; i++)
			{
				blackboxes[i].PreserveVanillaSaveBefore();
			}
		}

		public void PreserveVanillaSaveAfter()
		{
			highlight.PreserveVanillaSaveAfter();
			for (int i = 0; i < blackboxes.Count; i++)
			{
				blackboxes[i].PreserveVanillaSaveAfter();
			}
		}

		public void Export(BinaryWriter w)
		{
			w.Write(1);
			w.Write(blackboxIdCounter);
			w.Write(blackboxes.Count);
			for (int i = 0; i < blackboxes.Count; i++)
			{
				blackboxes[i].Export(w);
			}
			w.Write(blackboxesMarkedForRemoval.Count);
			for (int j = 0; j < blackboxesMarkedForRemoval.Count; j++)
			{
				w.Write(blackboxesMarkedForRemoval[j].Id);
			}
			autoBlackbox.Export(w);
			highlight.Export(w);
		}

		public void Import(BinaryReader r)
		{
			r.ReadInt32();
			blackboxIdCounter = r.ReadInt32();
			int num = r.ReadInt32();
			blackboxes.Clear();
			blackboxes.Capacity = num;
			for (int i = 0; i < num; i++)
			{
				blackboxes.Add(Blackbox.Import(r));
			}
			int num2 = r.ReadInt32();
			blackboxesMarkedForRemoval.Clear();
			blackboxesMarkedForRemoval.Capacity = num2;
			for (int j = 0; j < num2; j++)
			{
				int id = r.ReadInt32();
				Blackbox item = blackboxes.Find((Blackbox b) => b.Id == id);
				blackboxesMarkedForRemoval.Add(item);
			}
			autoBlackbox.Import(r);
			highlight.Import(r);
		}
	}
	internal class BlackboxPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameStatData), "GameTick")]
		public static void GameStatData__GameTick()
		{
			BlackboxManager.Instance.RemoveMarkedBlackboxes();
			BlackboxManager.Instance.GameTick();
			BlackboxManager.Instance.SimulateBlackboxes();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameData), "Destroy")]
		public static void GameData__Destroy()
		{
			BlackboxManager.Instance.ClearAll();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "CreateRenderingBatches")]
		public static void BeforeCreateRenderingBatches(CargoTraffic __instance)
		{
			BlackboxManager.Instance.PauseBlackboxBelts(__instance.factory);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CargoTraffic), "CreateRenderingBatches")]
		public static void AfterCreateRenderingBatches(CargoTraffic __instance)
		{
			BlackboxManager.Instance.ResumeBlackboxBelts(__instance.factory);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerAction_Build), "DoDismantleObject")]
		public static void BeforeDismantleObject(PlayerAction_Build __instance, int objId)
		{
			__instance.SetFactoryReferences();
			Blackbox blackbox = BlackboxUtils.QueryEntityForAssociatedBlackbox(__instance.factory, objId);
			if (blackbox != null)
			{
				BlackboxManager.Instance.MarkBlackboxForRemoval(blackbox);
				BlackboxManager.Instance.RemoveMarkedBlackboxes();
			}
		}
	}
	public struct CNT
	{
		public int count;

		public override string ToString()
		{
			return count.ToString();
		}
	}
	public struct CNTINC
	{
		public int count;

		public int inc;

		public override string ToString()
		{
			return $"({count}, {inc})";
		}

		public void Deconstruct(out int count, out int inc)
		{
			count = this.count;
			inc = this.inc;
		}
	}
	public class BlackboxRecipe
	{
		public long idleEnergyPerTick;

		public long workingEnergyPerTick;

		public int timeSpend;

		public Dictionary<int, Dictionary<int, CNT>> inputs;

		public Dictionary<int, Dictionary<int, CNTINC>> outputs;

		public Dictionary<int, int> produces;

		public Dictionary<int, int> consumes;

		private const int saveLogicVersion = 2;

		public void Export(BinaryWriter w)
		{
			w.Write(2);
			w.Write(idleEnergyPerTick);
			w.Write(workingEnergyPerTick);
			w.Write(timeSpend);
			w.Write(inputs.Count);
			foreach (KeyValuePair<int, Dictionary<int, CNT>> input in inputs)
			{
				w.Write(input.Key);
				Dictionary<int, CNT> value = input.Value;
				w.Write(value.Count);
				foreach (KeyValuePair<int, CNT> item in value)
				{
					w.Write(item.Key);
					w.Write(item.Value.count);
				}
			}
			w.Write(outputs.Count);
			foreach (KeyValuePair<int, Dictionary<int, CNTINC>> output in outputs)
			{
				w.Write(output.Key);
				Dictionary<int, CNTINC> value2 = output.Value;
				w.Write(value2.Count);
				foreach (KeyValuePair<int, CNTINC> item2 in value2)
				{
					w.Write(item2.Key);
					w.Write(item2.Value.count);
					w.Write(item2.Value.inc);
				}
			}
			w.Write(produces.Count);
			foreach (KeyValuePair<int, int> produce in produces)
			{
				w.Write(produce.Key);
				w.Write(produce.Value);
			}
			w.Write(consumes.Count);
			foreach (KeyValuePair<int, int> consume in consumes)
			{
				w.Write(consume.Key);
				w.Write(consume.Value);
			}
		}

		public static BlackboxRecipe Import(BinaryReader r)
		{
			int num = r.ReadInt32();
			BlackboxRecipe blackboxRecipe = new BlackboxRecipe();
			blackboxRecipe.idleEnergyPerTick = r.ReadInt64();
			blackboxRecipe.workingEnergyPerTick = r.ReadInt64();
			blackboxRecipe.timeSpend = r.ReadInt32();
			int num2 = r.ReadInt32();
			blackboxRecipe.inputs = new Dictionary<int, Dictionary<int, CNT>>();
			for (int i = 0; i < num2; i++)
			{
				int key = r.ReadInt32();
				int num3 = r.ReadInt32();
				Dictionary<int, CNT> dictionary = new Dictionary<int, CNT>();
				for (int j = 0; j < num3; j++)
				{
					int key2 = r.ReadInt32();
					int count = r.ReadInt32();
					dictionary.Add(key2, new CNT
					{
						count = count
					});
				}
				blackboxRecipe.inputs.Add(key, dictionary);
			}
			int num4 = r.ReadInt32();
			blackboxRecipe.outputs = new Dictionary<int, Dictionary<int, CNTINC>>();
			for (int k = 0; k < num4; k++)
			{
				int key3 = r.ReadInt32();
				int num5 = r.ReadInt32();
				Dictionary<int, CNTINC> dictionary2 = new Dictionary<int, CNTINC>();
				for (int l = 0; l < num5; l++)
				{
					int key4 = r.ReadInt32();
					int count2 = r.ReadInt32();
					int inc = 0;
					if (num >= 2)
					{
						inc = r.ReadInt32();
					}
					dictionary2.Add(key4, new CNTINC
					{
						count = count2,
						inc = inc
					});
				}
				blackboxRecipe.outputs.Add(key3, dictionary2);
			}
			int num6 = r.ReadInt32();
			blackboxRecipe.produces = new Dictionary<int, int>();
			for (int m = 0; m < num6; m++)
			{
				int key5 = r.ReadInt32();
				int value = r.ReadInt32();
				blackboxRecipe.produces.Add(key5, value);
			}
			int num7 = r.ReadInt32();
			blackboxRecipe.consumes = new Dictionary<int, int>();
			for (int n = 0; n < num7; n++)
			{
				int key6 = r.ReadInt32();
				int value2 = r.ReadInt32();
				blackboxRecipe.consumes.Add(key6, value2);
			}
			return blackboxRecipe;
		}
	}
	public class BlackboxSelection
	{
		public readonly int factoryIndex;

		public readonly WeakReference<PlanetFactory> factoryRef;

		public readonly ImmutableSortedSet<int> entityIds;

		public readonly ImmutableSortedSet<int> pcIds;

		public readonly ImmutableSortedSet<int> assemblerIds;

		public readonly ImmutableSortedSet<int> labIds;

		public readonly ImmutableSortedSet<int> inserterIds;

		public readonly ImmutableSortedSet<int> stationIds;

		public readonly ImmutableSortedSet<int> cargoPathIds;

		public readonly ImmutableSortedSet<int> splitterIds;

		public readonly ImmutableSortedSet<int> pilerIds;

		public readonly ImmutableSortedSet<int> spraycoaterIds;

		public readonly ImmutableSortedSet<int> monitorIds;

		public readonly ImmutableSortedSet<int> fractionatorIds;

		public readonly ImmutableSortedSet<int> itemIds;

		private const int saveLogicVersion = 1;

		private BlackboxSelection(PlanetFactory factory, ImmutableSortedSet<int> entityIds, ImmutableSortedSet<int> pcIds, ImmutableSortedSet<int> assemblerIds, ImmutableSortedSet<int> labIds, ImmutableSortedSet<int> inserterIds, ImmutableSortedSet<int> stationIds, ImmutableSortedSet<int> cargoPathIds, ImmutableSortedSet<int> splitterIds, ImmutableSortedSet<int> pilerIds, ImmutableSortedSet<int> spraycoaterIds, ImmutableSortedSet<int> monitorIds, ImmutableSortedSet<int> fractionatorIds, ImmutableSortedSet<int> itemIds)
		{
			factoryIndex = factory.index;
			factoryRef = new WeakReference<PlanetFactory>(factory);
			this.entityIds = entityIds;
			this.pcIds = pcIds;
			this.assemblerIds = assemblerIds;
			this.labIds = labIds;
			this.inserterIds = inserterIds;
			this.stationIds = stationIds;
			this.cargoPathIds = cargoPathIds;
			this.splitterIds = splitterIds;
			this.pilerIds = pilerIds;
			this.spraycoaterIds = spraycoaterIds;
			this.monitorIds = monitorIds;
			this.fractionatorIds = fractionatorIds;
			this.itemIds = itemIds;
		}

		public static BlackboxSelection CreateFrom(PlanetFactory factory, ICollection<int> entityIds)
		{
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			List<int> list = new List<int>();
			List<int> list2 = new List<int>();
			List<int> list3 = new List<int>();
			List<int> list4 = new List<int>();
			List<int> list5 = new List<int>();
			HashSet<int> hashSet = new HashSet<int>();
			HashSet<int> hashSet2 = new HashSet<int>();
			List<int> list6 = new List<int>();
			List<int> list7 = new List<int>();
			Li

Blackbox.UI.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DysonSphereProgram.Modding.Blackbox.UI.Builder;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Blackbox.UI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.7.0")]
[assembly: AssemblyInformationalVersion("0.2.7")]
[assembly: AssemblyProduct("Blackbox.UI")]
[assembly: AssemblyTitle("Blackbox.UI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace System.Runtime.CompilerServices
{
	public record IsExternalInit;
}
namespace DysonSphereProgram.Modding.Blackbox.UI
{
	[HarmonyPatch]
	internal class BlackboxUIPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIEntityBriefInfo), "SetInfo")]
		private static void UIEntityBriefInfo__SetInfo(PlanetFactory _factory, int _entityId, ref bool __runOriginal)
		{
			if (__runOriginal && _factory != null && _entityId > 0 && BlackboxUtils.QueryBlackboxedEntityForBlackboxId(_factory, ref _factory.entityPool[_entityId]) > 0)
			{
				__runOriginal = false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIGame), "OnPlayerInspecteeChange")]
		private static void UIGame__OnPlayerInspecteeChange(EObjectType objType, int objId, ref bool __runOriginal)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!__runOriginal)
			{
				return;
			}
			PlanetFactory factory = GameMain.mainPlayer.factory;
			if (factory == null || (int)objType != 0 || objId <= 0)
			{
				return;
			}
			int stationId = factory.entityPool[objId].stationId;
			Blackbox val = BlackboxUtils.QueryEntityForAssociatedBlackbox(factory, objId);
			if (val != null)
			{
				UIRoot.instance.uiGame.ShutAllFunctionWindow();
				BlackboxUIGateway.InspectBlackbox(val);
				if (stationId > 0)
				{
					UIRoot.instance.uiGame.stationWindow.stationId = stationId;
					UIRoot.instance.uiGame.OpenStationWindow();
					UIRoot.instance.uiGame.inspectStationId = stationId;
				}
				__runOriginal = false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControlGizmo), "SetMouseOverTarget", new Type[]
		{
			typeof(EObjectType),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static void PlayerControlGizmo__SetMouseOverTarget(PlayerControlGizmo __instance, EObjectType tarType, ref int tarId, ref bool __runOriginal)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			BlackboxHighlight highlight = BlackboxManager.Instance.highlight;
			if (__runOriginal && (int)tarType == 0 && tarId != 0)
			{
				PlanetFactory factory = __instance.player.factory;
				if (factory != null)
				{
					Blackbox val = BlackboxUtils.QueryEntityForAssociatedBlackbox(factory, tarId);
					if (val != null)
					{
						highlight.SetHoverHighlight(val);
						tarId = 0;
						return;
					}
				}
			}
			highlight.SetHoverHighlight((Blackbox)null);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIGame), "_OnUpdate")]
		private static void UIGame___OnUpdate()
		{
			BlackboxUIGateway.Update();
			UIBlackboxManagerWindow uIBlackboxManagerWindow = BlackboxUIGateway.BlackboxManagerWindow?.Component;
			if ((Object)(object)uIBlackboxManagerWindow != (Object)null && KeyBinds.BlackboxManagerWindow.IsActive)
			{
				if (((ManualBehaviour)uIBlackboxManagerWindow).active)
				{
					((ManualBehaviour)uIBlackboxManagerWindow)._Close();
				}
				else
				{
					((ManualBehaviour)uIBlackboxManagerWindow)._Open();
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIGame), "_OnFree")]
		private static void UIGame___OnFree()
		{
			BlackboxUIGateway.Free();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIGame), "_OnDestroy")]
		private static void UIGame___OnDestroy()
		{
			BlackboxUIGateway.DestroyUI();
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static void PatchIsAnyBlackboxWindowActive(ref bool __result)
		{
			UIBlackboxInspectWindow component = BlackboxUIGateway.BlackboxInspectWindow.Component;
			UIBlackboxManagerWindow component2 = BlackboxUIGateway.BlackboxManagerWindow.Component;
			__result = __result || (Object.op_Implicit((Object)(object)component) && ((ManualBehaviour)component).active);
			__result = __result || (Object.op_Implicit((Object)(object)component2) && ((ManualBehaviour)component2).active);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIGame), "ShutInventoryConflictsWindows")]
		[HarmonyPatch(typeof(UIGame), "ShutAllFunctionWindow")]
		private static void UIGame__ShutAllFunctionWindow()
		{
			((ManualBehaviour)BlackboxUIGateway.BlackboxInspectWindow.Component)._Close();
			((ManualBehaviour)BlackboxUIGateway.BlackboxInspectWindow.Component)._Free();
			((ManualBehaviour)BlackboxUIGateway.BlackboxManagerWindow.Component)._Close();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SignalProtoSet), "IconSprite")]
		private static void SignalProtoSet__IconSprite(int signalId, ref Sprite __result)
		{
			if (signalId == 60001)
			{
				__result = BlackboxUIGateway.iconSprite;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(WarningSystem), "WarningLogic")]
		private static void WarningSystem__WarningLogic(ref WarningSystem __instance)
		{
			bool flag = __instance.warningCounts[60001] > 0;
			BlackboxHighlight highlight = BlackboxManager.Instance.highlight;
			if (highlight.blackboxId > 0)
			{
				WarningData[] warningPool = __instance.warningPool;
				foreach (int warningId in highlight.warningIds)
				{
					ref WarningData reference = ref warningPool[warningId];
					reference.state = 1;
					reference.signalId = 60001;
					if (reference.detailId == 0)
					{
						reference.detailId = __instance.tmpEntityPools[reference.factoryId][reference.objectId].protoId;
					}
					__instance.warningCounts[60001]++;
				}
			}
			if (!flag && __instance.warningCounts[60001] > 0)
			{
				__instance.warningSignals[__instance.warningSignalCount] = 60001;
				WarningSystem obj = __instance;
				obj.warningSignalCount++;
			}
		}
	}
	public static class BlackboxUIGateway
	{
		private static ModdedUIBlackboxInspectWindow blackboxInspectWindow;

		private static ModdedUIBlackboxManagerWindow blackboxManagerWindow;

		private static List<IModdedUI> moddedUIs;

		public static Sprite iconSprite;

		public static ModdedUIBlackboxInspectWindow BlackboxInspectWindow => blackboxInspectWindow;

		public static ModdedUIBlackboxManagerWindow BlackboxManagerWindow => blackboxManagerWindow;

		static BlackboxUIGateway()
		{
			blackboxInspectWindow = new ModdedUIBlackboxInspectWindow();
			blackboxManagerWindow = new ModdedUIBlackboxManagerWindow();
			moddedUIs = new List<IModdedUI> { blackboxInspectWindow, blackboxManagerWindow };
		}

		public static void InspectBlackbox(Blackbox blackbox)
		{
			UIBlackboxInspectWindow uIBlackboxInspectWindow = BlackboxInspectWindow?.Component;
			if ((Object)(object)uIBlackboxInspectWindow != (Object)null)
			{
				if (((ManualBehaviour)uIBlackboxInspectWindow).inited && ((ManualBehaviour)uIBlackboxInspectWindow).data != blackbox)
				{
					((ManualBehaviour)uIBlackboxInspectWindow)._Close();
					((ManualBehaviour)uIBlackboxInspectWindow)._Free();
				}
				((ManualBehaviour)uIBlackboxInspectWindow)._Init((object)blackbox);
				((ManualBehaviour)uIBlackboxInspectWindow)._Open();
				((Component)uIBlackboxInspectWindow).transform.SetAsLastSibling();
			}
		}

		public static void CreateUI()
		{
			//IL_0002: 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_0028: Expected O, but got Unknown
			//IL_003d: 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_0056: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1);
			byte[] array = File.ReadAllBytes(Path.GetDirectoryName(Plugin.Path) + "\\icon.png");
			ImageConversion.LoadImage(val, array);
			iconSprite = Sprite.Create(val, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f));
			foreach (IModdedUI moddedUI in moddedUIs)
			{
				if ((Object)(object)moddedUI.GameObject != (Object)null)
				{
					throw new Exception("Blackbox UI mod encountered already created objects");
				}
				moddedUI.CreateUI();
			}
		}

		public static void DestroyUI()
		{
			foreach (IModdedUI moddedUI in moddedUIs)
			{
				moddedUI.DestroyUI();
			}
		}

		public static void Free()
		{
			foreach (IModdedUI moddedUI in moddedUIs)
			{
				moddedUI.Free();
			}
		}

		public static void Update()
		{
			foreach (IModdedUI moddedUI in moddedUIs)
			{
				moddedUI.Update();
			}
		}
	}
	public interface IModdedUI
	{
		object Component { get; }

		GameObject GameObject { get; }

		void CreateUI();

		void DestroyUI();

		void Init();

		void Free();

		void Update();
	}
	public interface IModdedUI<T> : IModdedUI where T : MonoBehaviour
	{
		new T Component { get; }
	}
	[BepInProcess("DSPGAME.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("dev.raptor.dsp.Blackbox-UI", "Blackbox-UI", "0.2.7")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		internal static ManualLogSource Log;

		internal static string Path;

		public const string Id = "dev.raptor.dsp.Blackbox-UI";

		public static string Name => "Blackbox-UI";

		public static string Version => "0.2.7";

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Path = ((BaseUnityPlugin)this).Info.Location;
			_harmony = new Harmony("dev.raptor.dsp.Blackbox-UI");
			_harmony.PatchAll(typeof(BlackboxUIPatch));
			UIBuilderPlugin.Create("dev.raptor.dsp.Blackbox-UI", BlackboxUIGateway.CreateUI);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Blackbox-UI Awake() called");
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Blackbox-UI OnDestroy() called");
			BlackboxUIGateway.DestroyUI();
			UIBuilderPlugin.Destroy();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Log = null;
			Path = null;
		}
	}
	public class UIProgressBar : MonoBehaviour
	{
		private float _progress;

		public Text progressText { get; private set; }

		public RectTransform progressPointRect { get; private set; }

		public Image progressImage { get; private set; }

		public float progress
		{
			get
			{
				return _progress;
			}
			set
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				if (_progress != value)
				{
					_progress = value;
					progressImage.fillAmount = value;
					RectTransform obj = progressPointRect;
					Rect rect = ((Graphic)progressImage).rectTransform.rect;
					obj.anchoredPosition = new Vector2(((Rect)(ref rect)).width * value, 0f);
				}
			}
		}

		public void Awake()
		{
			progressText = ((Component)this).gameObject.SelectChild("progress-text").GetComponent<Text>();
			progressPointRect = ((Component)this).gameObject.SelectDescendant("bar-group", "bar-fg", "point").GetComponent<RectTransform>();
			progressImage = ((Component)this).gameObject.SelectDescendant("bar-group", "bar-fg").GetComponent<Image>();
		}
	}
	public class UIBlackboxEntry : ManualBehaviour
	{
		public RectTransform rectTransform;

		public Text nameText;

		public Text statusText;

		public Text pauseResumeBtnText;

		public Text highlightBtnText;

		public Image highlightBtnImage;

		public Button inspectBtn;

		public Button pauseResumeBtn;

		public Button highlightBtn;

		public Button deleteBtn;

		public UIProgressBar progressBar;

		public int index;

		public Blackbox entryData;

		private static Color errorColor = new Color(1f, 0.27f, 0.1934f, 0.7333f);

		private static Color warningColor = new Color(0.9906f, 0.5897f, 0.3691f, 0.7059f);

		private static Color okColor = new Color(0.3821f, 0.8455f, 1f, 0.7059f);

		private static Color idleColor = new Color(0.5882f, 0.5882f, 0.5882f, 0.8196f);

		private static Color highlightColor = new Color(0.2972f, 0.6886f, 1f, 0.8471f);

		private static Color stopHighlightColor = new Color(1f, 0.298f, 0.3697f, 0.8471f);

		public override void _OnCreate()
		{
			rectTransform = ((Component)this).gameObject.GetComponent<RectTransform>();
			nameText = ((Component)this).gameObject.SelectDescendant("name").GetComponent<Text>();
			statusText = ((Component)this).gameObject.SelectDescendant("status-label").GetComponent<Text>();
			inspectBtn = ((Component)this).gameObject.SelectDescendant("inspect-btn").GetComponent<Button>();
			pauseResumeBtn = ((Component)this).gameObject.SelectDescendant("pause-resume-btn").GetComponent<Button>();
			pauseResumeBtnText = ((Component)pauseResumeBtn).gameObject.SelectChild("text").GetComponent<Text>();
			highlightBtn = ((Component)this).gameObject.SelectDescendant("highlight-btn").GetComponent<Button>();
			highlightBtnText = ((Component)highlightBtn).gameObject.SelectChild("text").GetComponent<Text>();
			highlightBtnImage = ((Component)highlightBtn).GetComponent<Image>();
			deleteBtn = ((Component)this).gameObject.SelectDescendant("delete-btn").GetComponent<Button>();
			progressBar = ((Component)this).gameObject.SelectDescendant("progress-bar").GetOrCreateComponent<UIProgressBar>();
		}

		public override void _OnDestroy()
		{
		}

		public override bool _OnInit()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			((UnityEvent)inspectBtn.onClick).AddListener(new UnityAction(OnInspectBtnClick));
			((UnityEvent)pauseResumeBtn.onClick).AddListener(new UnityAction(OnPauseResumeBtnClick));
			((UnityEvent)highlightBtn.onClick).AddListener(new UnityAction(OnHighlightBtnClick));
			((UnityEvent)deleteBtn.onClick).AddListener(new UnityAction(OnDeleteBtnClick));
			return true;
		}

		public override void _OnFree()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			((UnityEvent)inspectBtn.onClick).RemoveListener(new UnityAction(OnInspectBtnClick));
			((UnityEvent)pauseResumeBtn.onClick).RemoveListener(new UnityAction(OnPauseResumeBtnClick));
			((UnityEvent)highlightBtn.onClick).RemoveListener(new UnityAction(OnHighlightBtnClick));
			((UnityEvent)deleteBtn.onClick).RemoveListener(new UnityAction(OnDeleteBtnClick));
		}

		public override void _OnUpdate()
		{
			//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_002b: 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_0047: Expected I4, but got Unknown
			//IL_012f: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if (entryData == null)
			{
				return;
			}
			nameText.text = entryData.Name;
			BlackboxStatus status = entryData.Status;
			switch (status - 4)
			{
			case 1:
				statusText.text = "Analysing";
				((Graphic)statusText).color = idleColor;
				break;
			case 2:
				statusText.text = "Analysis Failed";
				((Graphic)statusText).color = errorColor;
				break;
			case 4:
				if (entryData.Simulation != null)
				{
					statusText.text = (entryData.Simulation.isBlackboxSimulating ? "Simulating" : "Simulation Paused");
					((Graphic)statusText).color = (entryData.Simulation.isBlackboxSimulating ? okColor : warningColor);
				}
				else
				{
					statusText.text = "Blackboxed";
					((Graphic)statusText).color = idleColor;
				}
				break;
			case 0:
				statusText.text = "Invalid";
				((Graphic)statusText).color = errorColor;
				break;
			default:
			{
				Text obj = statusText;
				BlackboxStatus status2 = entryData.Status;
				obj.text = ((object)(BlackboxStatus)(ref status2)).ToString();
				((Graphic)statusText).color = idleColor;
				break;
			}
			}
			((Component)progressBar).gameObject.SetActive(false);
			((Component)pauseResumeBtn).gameObject.SetActive(false);
			if (entryData.Simulation != null)
			{
				((Component)pauseResumeBtn).gameObject.SetActive(true);
				if (entryData.Simulation.isBlackboxSimulating)
				{
					pauseResumeBtnText.text = "Pause";
				}
				else
				{
					pauseResumeBtnText.text = "Resume";
				}
				((Component)progressBar).gameObject.SetActive(true);
				progressBar.progress = entryData.Simulation.CycleProgress;
				progressBar.progressText.text = entryData.Simulation.CycleProgressText;
			}
			if (entryData.Analysis != null)
			{
				((Component)progressBar).gameObject.SetActive(true);
				progressBar.progress = entryData.Analysis.Progress;
				progressBar.progressText.text = entryData.Analysis.ProgressText;
			}
			if (entryData.Id == BlackboxManager.Instance.highlight.blackboxId)
			{
				highlightBtnText.text = "Stop Highlight";
				((Graphic)highlightBtnImage).color = stopHighlightColor;
			}
			else
			{
				highlightBtnText.text = "Highlight";
				((Graphic)highlightBtnImage).color = highlightColor;
			}
		}

		public void SetTrans()
		{
			//IL_000c: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = rectTransform;
			float x = rectTransform.anchoredPosition.x;
			float num = -index;
			Rect rect = rectTransform.rect;
			obj.anchoredPosition = new Vector2(x, num * ((Rect)(ref rect)).height);
		}

		private void OnBtnClick()
		{
			Plugin.Log.LogDebug((object)("Button clicked from UIBlackboxEntry " + nameText.text));
		}

		private void OnInspectBtnClick()
		{
			OnBtnClick();
			if (entryData != null)
			{
				BlackboxUIGateway.InspectBlackbox(entryData);
			}
		}

		private void OnPauseResumeBtnClick()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			OnBtnClick();
			if (entryData != null && (int)entryData.Status == 8 && entryData.Simulation != null)
			{
				if (entryData.Simulation.isBlackboxSimulating)
				{
					entryData.Simulation.PauseBlackboxing();
				}
				else
				{
					entryData.Simulation.ResumeBlackboxing();
				}
			}
		}

		private void OnHighlightBtnClick()
		{
			OnBtnClick();
			if (entryData != null)
			{
				BlackboxHighlight highlight = BlackboxManager.Instance.highlight;
				if (highlight.blackboxId == entryData.Id)
				{
					highlight.ClearHighlight();
				}
				else
				{
					highlight.RequestHighlight(entryData);
				}
			}
		}

		private void OnDeleteBtnClick()
		{
			OnBtnClick();
			if (entryData != null)
			{
				BlackboxManager.Instance.MarkBlackboxForRemoval(entryData);
			}
		}
	}
	public class UIBlackboxInspectWindow : UIModWindowBase
	{
		private Blackbox blackbox;

		private Localizer titleLocalizer;

		private Text statusText;

		private Text pauseResumeBtnText;

		private Text recipeText;

		private Button pauseResumeBtn;

		private Image progressImg;

		private GameObject progressIndicator;

		private static Color errorColor = new Color(1f, 0.27f, 0.1934f, 0.7333f);

		private static Color warningColor = new Color(0.9906f, 0.5897f, 0.3691f, 0.7059f);

		private static Color okColor = new Color(0.3821f, 0.8455f, 1f, 0.7059f);

		private static Color idleColor = new Color(0.5882f, 0.5882f, 0.5882f, 0.8196f);

		private StringBuilder recipeSB = new StringBuilder();

		private StringBuilder powerSB = new StringBuilder("         W", 12);

		public override void _OnCreate()
		{
			GameObject obj = ((Component)this).gameObject.SelectDescendant("panel-bg", "title-text");
			titleLocalizer = ((obj != null) ? obj.GetComponent<Localizer>() : null);
			if ((Object)(object)titleLocalizer != (Object)null)
			{
				titleLocalizer.stringKey = "<Select Blackbox to Inspect>";
			}
			progressIndicator = ((Component)this).gameObject.SelectChild("progress-circle");
			progressIndicator.SetActive(false);
			GameObject obj2 = progressIndicator.SelectDescendant("circle-back", "circle-fg");
			progressImg = ((obj2 != null) ? obj2.GetComponent<Image>() : null);
			if ((Object)(object)progressImg != (Object)null)
			{
				progressImg.fillAmount = 0f;
			}
			statusText = ((Component)this).gameObject.SelectDescendant("status-label").GetComponent<Text>();
			pauseResumeBtn = ((Component)this).gameObject.SelectDescendant("pause-resume-btn").GetComponent<Button>();
			pauseResumeBtnText = ((Component)pauseResumeBtn).gameObject.SelectChild("text").GetComponent<Text>();
			recipeText = ((Component)this).gameObject.SelectDescendant("recipe-box", "scroll-view", "viewport", "content", "recipe-text").GetComponent<Text>();
		}

		public override void _OnDestroy()
		{
			titleLocalizer = null;
			progressImg = null;
			progressIndicator = null;
			statusText = null;
			pauseResumeBtnText = null;
			pauseResumeBtn = null;
		}

		public override bool _OnInit()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			ref Blackbox reference = ref blackbox;
			object data = ((ManualBehaviour)this).data;
			reference = (Blackbox)((data is Blackbox) ? data : null);
			if (blackbox == null)
			{
				return false;
			}
			if ((Object)(object)titleLocalizer != (Object)null)
			{
				titleLocalizer.stringKey = blackbox.Name;
			}
			progressIndicator.SetActive(true);
			((UnityEvent)pauseResumeBtn.onClick).AddListener(new UnityAction(OnPauseResumeBtnClick));
			Debug.Log((object)"Setting produce to Active");
			if (blackbox.Recipe != null)
			{
				BlackboxRecipe recipe = blackbox.Recipe;
				if (!blackbox.FactoryRef.TryGetTarget(out var target))
				{
					Plugin.Log.LogError((object)"PlanetFactory instance pulled out from under UIBlackboxInspectWindow in _OnInit");
					return false;
				}
				recipeSB.Clear();
				recipeSB.AppendLine("Consumes:");
				foreach (KeyValuePair<int, int> consume in recipe.consumes)
				{
					string value = LDB.ItemName(consume.Key);
					recipeSB.Append("- ");
					recipeSB.Append(consume.Value);
					recipeSB.Append(" ");
					recipeSB.AppendLine(value);
				}
				recipeSB.AppendLine();
				recipeSB.AppendLine("Produces:");
				foreach (KeyValuePair<int, int> produce in recipe.produces)
				{
					string value2 = LDB.ItemName(produce.Key);
					recipeSB.Append("- ");
					recipeSB.Append(produce.Value);
					recipeSB.Append(" ");
					recipeSB.AppendLine(value2);
				}
				recipeSB.AppendLine();
				recipeSB.AppendLine("Inputs:");
				foreach (KeyValuePair<int, Dictionary<int, CNT>> input in recipe.inputs)
				{
					int num = blackbox.Selection.stationIds[input.Key];
					StationComponent val = target.transport.stationPool[num];
					string value3 = (val.isStellar ? (Localization.Translate("星际站点号") + val.gid) : (Localization.Translate("本地站点号") + val.id));
					Plugin.Log.LogDebug((object)input.Key);
					recipeSB.Append("- ");
					recipeSB.AppendLine(value3);
					foreach (KeyValuePair<int, CNT> item in input.Value)
					{
						string value4 = LDB.ItemName(item.Key);
						recipeSB.Append("   -- ");
						recipeSB.Append(item.Value);
						recipeSB.Append(" ");
						recipeSB.AppendLine(value4);
					}
				}
				recipeSB.AppendLine();
				recipeSB.AppendLine("Outputs:");
				foreach (KeyValuePair<int, Dictionary<int, CNTINC>> output in recipe.outputs)
				{
					int num2 = blackbox.Selection.stationIds[output.Key];
					StationComponent val2 = target.transport.stationPool[num2];
					string value5 = (val2.isStellar ? (Localization.Translate("星际站点号") + val2.gid) : (Localization.Translate("本地站点号") + val2.id));
					recipeSB.Append("- ");
					recipeSB.AppendLine(value5);
					foreach (KeyValuePair<int, CNTINC> item2 in output.Value)
					{
						string value6 = LDB.ItemName(item2.Key);
						recipeSB.Append("   -- ");
						recipeSB.Append(item2.Value);
						recipeSB.Append(" ");
						recipeSB.AppendLine(value6);
					}
				}
				recipeSB.AppendLine();
				recipeSB.Append("Idle Energy: ");
				StringBuilderUtility.WriteKMG(powerSB, 8, recipe.idleEnergyPerTick * 60, true);
				recipeSB.AppendLine(powerSB.ToString());
				recipeSB.Append("Work Energy: ");
				StringBuilderUtility.WriteKMG(powerSB, 8, recipe.workingEnergyPerTick * 60, true);
				recipeSB.AppendLine(powerSB.ToString());
				recipeSB.Append("Cycle Time: ");
				recipeSB.Append(Math.Round((float)recipe.timeSpend / 60f, 2));
				recipeSB.AppendLine("s");
				recipeText.text = recipeSB.ToString();
			}
			else
			{
				recipeText.text = "";
			}
			return true;
		}

		public override void _OnFree()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			((UnityEvent)pauseResumeBtn.onClick).RemoveListener(new UnityAction(OnPauseResumeBtnClick));
			progressIndicator.SetActive(false);
			blackbox = null;
			titleLocalizer.stringKey = "<Select Blackbox to Inspect>";
		}

		public override void _OnUpdate()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected I4, but got Unknown
			//IL_0119: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			if (blackbox == null)
			{
				return;
			}
			BlackboxStatus status = blackbox.Status;
			switch (status - 4)
			{
			case 1:
				statusText.text = "Analysing";
				((Graphic)statusText).color = idleColor;
				break;
			case 2:
				statusText.text = "Analysis Failed";
				((Graphic)statusText).color = errorColor;
				break;
			case 4:
				if (blackbox.Simulation != null)
				{
					statusText.text = (blackbox.Simulation.isBlackboxSimulating ? "Simulating" : "Simulation Paused");
					((Graphic)statusText).color = (blackbox.Simulation.isBlackboxSimulating ? okColor : warningColor);
				}
				else
				{
					statusText.text = "Blackboxed";
					((Graphic)statusText).color = idleColor;
				}
				break;
			case 0:
				statusText.text = "Invalid";
				((Graphic)statusText).color = errorColor;
				break;
			default:
			{
				Text obj = statusText;
				BlackboxStatus status2 = blackbox.Status;
				obj.text = ((object)(BlackboxStatus)(ref status2)).ToString();
				((Graphic)statusText).color = idleColor;
				break;
			}
			}
			if (blackbox.Simulation == null)
			{
				((Component)pauseResumeBtn).gameObject.SetActive(false);
				progressImg.fillAmount = 0f;
				return;
			}
			((Component)pauseResumeBtn).gameObject.SetActive(true);
			if (blackbox.Simulation.isBlackboxSimulating)
			{
				pauseResumeBtnText.text = "Pause";
			}
			else
			{
				pauseResumeBtnText.text = "Resume";
			}
			progressImg.fillAmount = blackbox.Simulation.CycleProgress;
		}

		private void OnPauseResumeBtnClick()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			if (blackbox != null && (int)blackbox.Status == 8 && blackbox.Simulation != null)
			{
				if (blackbox.Simulation.isBlackboxSimulating)
				{
					blackbox.Simulation.PauseBlackboxing();
				}
				else
				{
					blackbox.Simulation.ResumeBlackboxing();
				}
			}
		}
	}
	public class ModdedUIBlackboxInspectWindow : IModdedUI<UIBlackboxInspectWindow>, IModdedUI
	{
		private GameObject gameObject;

		private UIBlackboxInspectWindow uiBlackboxInspectWindow;

		public UIBlackboxInspectWindow Component => uiBlackboxInspectWindow;

		public GameObject GameObject => gameObject;

		object IModdedUI.Component => uiBlackboxInspectWindow;

		public void CreateUI()
		{
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)UIRoot.instance.uiGame.assemblerWindow).transform.parent;
			UIBuilderDSL.FancyWindowContext fancyWindowContext = UIBuilderDSL.Create.FancyWindow("Blackbox Inspect Window").ChildOf(parent).WithAnchor(Anchor.TopLeft)
				.OfSize(580, 250)
				.At(100, -100)
				.WithScrollCapture()
				.WithTitle("<Select Blackbox To Inspect>");
			gameObject = fancyWindowContext.uiElement;
			UIBuilderDSL.Select.Text(gameObject.SelectDescendant("panel-bg", "title-text").GetComponent<Text>()).WithFontSize(16);
			IGraphicContextExtensions.WithColor(IGraphicContextExtensions.WithMaterial(UIBuilderDSL.Create.Text("status-label").ChildOf((UIElementContext)fancyWindowContext).WithAnchor(Anchor.TopLeft)
				.At(40, -50)
				.OfSize(128, 20)
				.WithFont(UIBuilder.fontSAIRASB)
				.WithFontSize(14), UIBuilder.materialWidgetTextAlpha5x), new Color(0.5882f, 0.5882f, 0.5882f, 1f)).WithAlignment((TextAnchor)0).WithText("Status");
			UIElementContext parent2 = UIBuilderDSL.Create.UIElement("progress-circle").ChildOf((UIElementContext)fancyWindowContext).WithAnchor(Anchor.Left)
				.At(40, 0);
			UIElementContext parent3 = UIBuilderDSL.Create.UIElement("circle-back").ChildOf(parent2).WithAnchor(Anchor.Left)
				.At(0, 0)
				.OfSize(64, 64)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//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_0019: Unknown result type (might be due to invalid IL or missing references)
					x.sprite = UIBuilder.spriteRound64Slice;
					Color black2 = Color.black;
					((Graphic)x).color = ((Color)(ref black2)).AlphaMultiplied(0.4f);
					x.type = (Type)1;
				});
			UIBuilderDSL.Create.UIElement("border").ChildOf(parent3).WithAnchor(Anchor.Stretch)
				.At(0, 0)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//IL_0020: Unknown result type (might be due to invalid IL or missing references)
					x.sprite = UIBuilder.spriteRound64BorderSlice;
					((Graphic)x).color = new Color(0.6557f, 0.9145f, 1f, 0.1569f);
					x.type = (Type)1;
				});
			UIBuilderDSL.Create.UIElement("circle-fg").ChildOf(parent3).WithAnchor(Anchor.Stretch)
				.At(0, 0)
				.OfSize(-4, -4)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//IL_0020: Unknown result type (might be due to invalid IL or missing references)
					x.sprite = UIBuilder.spriteCircleThin;
					((Graphic)x).color = new Color(0.9906f, 0.5897f, 0.3691f, 0.7059f);
					((Graphic)x).material = UIBuilder.materialWidgetAlpha5x;
					x.type = (Type)3;
					x.fillMethod = (FillMethod)4;
					x.fillOrigin = 2;
					x.fillAmount = 0.5f;
				});
			UIBuilderDSL.Create.Button("pause-resume-btn", "Pause / Resume").ChildOf((UIElementContext)fancyWindowContext).WithAnchor(Anchor.BottomLeft)
				.At(40, 40)
				.OfSize(90, 30)
				.WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties)
				.WithFontSize(14);
			UIElementContext parent4 = UIBuilderDSL.Create.UIElement("recipe-box").ChildOf((UIElementContext)fancyWindowContext).WithMinMaxAnchor(new Vector2(0.3f, 0f), new Vector2(0.9f, 0.6f))
				.WithPivot(0.5f, 0f)
				.At(0, 40)
				.OfSize(0, -30);
			UIBuilderDSL.Create.Text("label").ChildOf(parent4).WithAnchor(Anchor.TopLeft)
				.WithPivot(0f, 0f)
				.At(0, 0)
				.WithAlignment((TextAnchor)0)
				.OfSize(100, 30)
				.WithFont(UIBuilder.fontSAIRASB)
				.WithText("Recipe");
			ScrollViewConfiguration scrollViewConfiguration = default(ScrollViewConfiguration);
			scrollViewConfiguration.axis = ScrollViewAxis.VerticalOnly;
			scrollViewConfiguration.scrollBarWidth = 5u;
			ScrollViewConfiguration configuration = scrollViewConfiguration;
			ScrollViewContext scrollViewContext = UIBuilderDSL.Create.ScrollView("scroll-view", configuration).ChildOf(parent4).WithAnchor(Anchor.Stretch)
				.At(0, 0);
			GameObject val = ((Component)scrollViewContext.scrollRect.content).gameObject;
			((Transform)UIBuilderDSL.Create.UIElement("bg").ChildOf((Transform)(object)scrollViewContext.scrollRect.viewport).WithAnchor(Anchor.Stretch)
				.WithPivot(0f, 1f)
				.At(0, 0)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//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_000e: Unknown result type (might be due to invalid IL or missing references)
					Color black = Color.black;
					((Graphic)x).color = ((Color)(ref black)).AlphaMultiplied(0.4f);
				})
				.transform).SetAsFirstSibling();
			UIBuilderDSL.Select.VerticalLayoutGroup(val).WithAnchor(Anchor.Stretch).At(0, 0)
				.WithChildAlignment((TextAnchor)0)
				.ForceExpand(width: true, height: false)
				.ChildControls()
				.WithContentSizeFitter((FitMode)0, (FitMode)2);
			UIBuilderDSL.Create.Text("recipe-text").ChildOf(val).WithAnchor(Anchor.TopLeft)
				.WithPivot(0f, 0f)
				.At(0, 0)
				.WithOverflow((HorizontalWrapMode)0, (VerticalWrapMode)1)
				.WithAlignment((TextAnchor)0)
				.WithLayoutSize(0f, 0f, -1f, -1f, 1f)
				.WithContentSizeFitter((FitMode)2, (FitMode)2);
			fancyWindowContext.InitializeComponent<UIBuilderDSL.FancyWindowContext, UIBlackboxInspectWindow>(out uiBlackboxInspectWindow);
		}

		public void DestroyUI()
		{
			if ((Object)(object)uiBlackboxInspectWindow != (Object)null)
			{
				((ManualBehaviour)uiBlackboxInspectWindow)._OnDestroy();
			}
			uiBlackboxInspectWindow = null;
			if ((Object)(object)gameObject != (Object)null)
			{
				Object.Destroy((Object)(object)gameObject);
			}
			gameObject = null;
		}

		public void Free()
		{
			UIBlackboxInspectWindow uIBlackboxInspectWindow = uiBlackboxInspectWindow;
			if (uIBlackboxInspectWindow != null)
			{
				((ManualBehaviour)uIBlackboxInspectWindow)._OnFree();
			}
		}

		public void Init()
		{
		}

		public void Update()
		{
			UIBlackboxInspectWindow uIBlackboxInspectWindow = uiBlackboxInspectWindow;
			if (uIBlackboxInspectWindow != null)
			{
				((ManualBehaviour)uIBlackboxInspectWindow)._OnUpdate();
			}
		}
	}
	public class TabButton : MonoBehaviour
	{
		public TabBar TabBar;

		public ManualBehaviour TabContent;

		public Button tabButton;

		public UIButton tabUiButton;

		public int index;

		private void Awake()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			if ((Object)(object)tabUiButton == (Object)null)
			{
				tabUiButton = ((Component)this).gameObject.GetOrCreateComponent<UIButton>();
			}
			if ((Object)(object)tabButton == (Object)null)
			{
				tabButton = ((Component)this).gameObject.GetComponent<Button>();
			}
			if (Object.op_Implicit((Object)(object)tabButton))
			{
				((UnityEvent)tabButton.onClick).AddListener(new UnityAction(OnTabBtnClick));
			}
		}

		public void Open()
		{
			TabContent._Open();
			tabUiButton.highlighted = true;
		}

		public void Close()
		{
			tabUiButton.highlighted = false;
			TabContent._Close();
		}

		public void OnTabBtnClick()
		{
			TabBar.SelectTab(index);
		}
	}
	public class TabBar : MonoBehaviour
	{
		public readonly List<TabButton> Tabs = new List<TabButton>();

		private int selectedTabIndex;

		private void Awake()
		{
			Tabs.Clear();
			Tabs.AddRange(((Component)this).gameObject.GetComponentsInChildren<TabButton>());
			for (int i = 0; i < Tabs.Count; i++)
			{
				Tabs[i].TabBar = this;
				Tabs[i].index = i;
			}
			if (Tabs.Count > 0)
			{
				Tabs[0].Open();
			}
		}

		public void SelectTab(int index)
		{
			if (index != selectedTabIndex)
			{
				Tabs[selectedTabIndex].Close();
				selectedTabIndex = index;
				Tabs[selectedTabIndex].Open();
			}
		}
	}
	public class UIBlackboxManagerWindow : UIModWindowBase
	{
		private UIBlackboxOverviewPanel overviewPanel;

		private UIBlackboxSettingsPanel settingsPanel;

		public override void _OnCreate()
		{
			overviewPanel = ((Component)this).gameObject.SelectDescendant("content-bg", "overview-panel").GetOrCreateComponent<UIBlackboxOverviewPanel>();
			((ManualBehaviour)overviewPanel)._Create();
			settingsPanel = ((Component)this).gameObject.SelectDescendant("content-bg", "settings-panel").GetOrCreateComponent<UIBlackboxSettingsPanel>();
			((ManualBehaviour)settingsPanel)._Create();
		}

		public override void _OnDestroy()
		{
		}

		public override bool _OnInit()
		{
			((ManualBehaviour)overviewPanel)._Init((object)null);
			((ManualBehaviour)settingsPanel)._Init((object)null);
			return true;
		}

		public override void _OnFree()
		{
		}

		public override void _OnUpdate()
		{
			if (Object.op_Implicit((Object)(object)overviewPanel))
			{
				((ManualBehaviour)overviewPanel)._Update();
			}
			if (Object.op_Implicit((Object)(object)settingsPanel))
			{
				((ManualBehaviour)settingsPanel)._Update();
			}
		}
	}
	public class ModdedUIBlackboxManagerWindow : IModdedUI<UIBlackboxManagerWindow>, IModdedUI
	{
		private GameObject gameObject;

		private UIBlackboxManagerWindow uiBlackboxManagerWindow;

		private static readonly float epsilon = (float)Math.Pow(2.0, -32.0);

		public UIBlackboxManagerWindow Component => uiBlackboxManagerWindow;

		public GameObject GameObject => gameObject;

		object IModdedUI.Component => uiBlackboxManagerWindow;

		public void CreateUI()
		{
			//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_00d7: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)UIRoot.instance.uiGame.statWindow).transform.parent;
			UIBuilderDSL.PlainWindowContext plainWindowContext = UIBuilderDSL.Create.PlainWindow("Blackbox Manager Window").ChildOf(parent).WithAnchor(Anchor.TopLeft)
				.OfSize(900, 550)
				.At(300, -180)
				.WithScrollCapture()
				.WithTitle("Blackbox Manager");
			gameObject = plainWindowContext.uiElement;
			UIElementContext context = UIBuilderDSL.Create.UIElement("content-bg").ChildOf((UIElementContext)plainWindowContext).WithAnchor(Anchor.Stretch)
				.WithPivot(0.5f, 1f)
				.OfSize(-20, -55)
				.At(0, -45);
			IProperties<Image>[] array = new IProperties<Image>[1];
			ImageProperties obj = new ImageProperties
			{
				raycastTarget = false
			};
			Color black = Color.black;
			obj.color = ((Color)(ref black)).AlphaMultiplied(0.7f);
			array[0] = obj;
			Image component;
			UIElementContext parent2 = context.WithComponent<UIElementContext, Image>(out component, array);
			UIElementContext uIElementContext = UIBuilderDSL.Create.UIElement("overview-panel").ChildOf(parent2).WithAnchor(Anchor.Stretch)
				.At(0, 0);
			UIElementContext uIElementContext2 = UIBuilderDSL.Create.UIElement("settings-panel").ChildOf(parent2).WithAnchor(Anchor.Stretch)
				.At(0, 0);
			InitializeOverviewPanel(uIElementContext);
			uIElementContext.WithComponent<UIElementContext, UIBlackboxOverviewPanel>(out UIBlackboxOverviewPanel component2);
			InitializeSettingsPanel(uIElementContext2);
			uIElementContext2.WithComponent<UIElementContext, UIBlackboxSettingsPanel>(out UIBlackboxSettingsPanel component3);
			TranslucentImage component4;
			VerticalLayoutGroupContext context2 = UIBuilderDSL.Create.VerticalLayoutGroup("tab-bar").ChildOf(plainWindowContext.panelBg).WithAnchor(Anchor.TopLeft)
				.WithPivot(1f, 1f)
				.At(10, -45)
				.WithChildAlignment((TextAnchor)4)
				.ForceExpand(width: true, height: false)
				.ChildControls()
				.WithLayoutSize(100f, 0f)
				.WithContentSizeFitter((FitMode)2, (FitMode)2)
				.WithComponent<VerticalLayoutGroupContext, TranslucentImage>(out component4, new IProperties<TranslucentImage>[1] { UIBuilder.plainWindowPanelBgProperties });
			plainWindowContext.InitializeComponent<UIBuilderDSL.PlainWindowContext, UIBlackboxManagerWindow>(out uiBlackboxManagerWindow);
			context2.AddChildren(CreateTabButton("overview-btn", "Overview", (ManualBehaviour)(object)component2), CreateTabButton("settings-btn", "Settings", (ManualBehaviour)(object)component3)).WithComponent<VerticalLayoutGroupContext, TabBar>(out TabBar _);
			((ManualBehaviour)uiBlackboxManagerWindow)._Close();
			static UIElementContext CreateTabButton(string name, string tabText, ManualBehaviour tabContent)
			{
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				ButtonContext context3 = UIBuilderDSL.Create.Button(name, tabText);
				UIElementContext[] array2 = new UIElementContext[1];
				UIElementContext context4 = UIBuilderDSL.Create.UIElement("col").WithAnchor(Anchor.Stretch);
				IProperties<Image>[] array3 = new IProperties<Image>[1];
				ImageProperties imageProperties = new ImageProperties();
				Color white2 = Color.white;
				imageProperties.color = ((Color)(ref white2)).AlphaMultiplied(0f);
				array3[0] = imageProperties;
				array2[0] = context4.WithComponent<UIElementContext, Image>(out Image component6, array3);
				return context3.AddChildren(array2).WithTransitions(CreateTabButtonTransition((Graphic)(object)component6)).WithInteractionAudios(new AudioSettings
				{
					downName = "ui-click-0"
				})
					.WithLayoutSize(50f, 55f, -1f, -1f, 1f)
					.WithComponent<ButtonContext, TabButton>((Action<TabButton>)delegate(TabButton x)
					{
						x.TabContent = tabContent;
					});
			}
			static Transition CreateTabButtonTransition(Graphic target)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: 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_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: 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)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: 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_00e3: Expected O, but got Unknown
				Transition val = new Transition
				{
					damp = 0.3f,
					disabledColor = new Color(0.6557f, 0.9145f, 1f, 0f),
					highlightAlphaMultiplier = 1f,
					highlightColorMultiplier = 1f,
					highlightColorOverride = new Color(0.6549f, 0.9137f, 1f, 0.3176f),
					highlightSizeMultiplier = 1f,
					mouseoverColor = new Color(0.6557f, 0.9145f, 1f, 0.1882f),
					mouseoverSize = 1f
				};
				Color white = Color.white;
				val.normalColor = ((Color)(ref white)).AlphaMultiplied(0f);
				val.pressedColor = new Color(0.6557f, 0.9145f, 1f, 0.1137f);
				val.pressedSize = 1f;
				val.target = target;
				return val;
			}
		}

		private static void InitializeSettingsPanel(UIElementContext root)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			ScrollViewContext scrollViewContext = UIBuilderDSL.Create.ScrollView("scroll-view", new ScrollViewConfiguration(ScrollViewAxis.BothVerticalAndHorizontal)).ChildOf(root).WithAnchor(Anchor.Stretch)
				.WithPivot(0f, 1f)
				.At(0, 0);
			GameObject obj = ((Component)scrollViewContext.scrollRect.content).gameObject;
			((Transform)UIBuilderDSL.Create.UIElement("bg").ChildOf((Transform)(object)scrollViewContext.scrollRect.viewport).WithAnchor(Anchor.Stretch)
				.At(0, 0)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					((Graphic)x).color = Color.clear;
				})
				.transform).SetAsFirstSibling();
			int num = 10;
			VerticalLayoutGroupContext root2 = UIBuilderDSL.Select.VerticalLayoutGroup(obj).WithPadding(new RectOffset(num, num, num + 10, num + 10)).WithSpacing(10f)
				.WithChildAlignment((TextAnchor)0)
				.ForceExpand(width: false, height: false)
				.ChildControls()
				.WithContentSizeFitter((FitMode)2, (FitMode)2);
			DelegateDataBindSource<bool> binding2 = new DelegateDataBindSource<bool>(() => Blackbox.analyseInBackgroundConfig, delegate(bool value)
			{
				Blackbox.analyseInBackgroundConfig = value;
			});
			CreateEntry(root2, "Analyse in background thread", (RectTransform[])(object)new RectTransform[1] { CreateOnOffToggle(binding2).transform });
			DelegateDataBindSource<bool> enabledBinding2 = new DelegateDataBindSource<bool>(() => BlackboxBenchmark.shouldOverrideCycleLengthConfig, delegate(bool value)
			{
				BlackboxBenchmark.shouldOverrideCycleLengthConfig = value;
			});
			DelegateDataBindSource<int> binding3 = new DelegateDataBindSource<int>(() => BlackboxBenchmark.overrideCycleLengthConfig / 60, delegate(int value)
			{
				BlackboxBenchmark.overrideCycleLengthConfig = Math.Max(value * 60, 60);
			});
			CreateEntry(root2, "Cycle Length Override (in seconds)", CreateCycleLengthOverride(enabledBinding2, binding3));
			DelegateDataBindSource<bool> binding4 = new DelegateDataBindSource<bool>(() => BlackboxManager.Instance.autoBlackbox.isActive, delegate(bool value)
			{
				BlackboxManager.Instance.autoBlackbox.isActive = value;
			});
			CreateEntry(root2, "Auto-blackbox", (RectTransform[])(object)new RectTransform[1] { CreateOnOffToggle(binding4).transform });
			DelegateDataBindSource<bool> binding5 = new DelegateDataBindSource<bool>(() => BlackboxBenchmark.forceNoStackingConfig, delegate(bool value)
			{
				BlackboxBenchmark.forceNoStackingConfig = value;
			});
			CreateEntry(root2, "Force No Stacking", (RectTransform[])(object)new RectTransform[1] { CreateOnOffToggle(binding5).transform });
			DelegateDataBindSource<bool> binding6 = new DelegateDataBindSource<bool>(() => BlackboxBenchmark.logProfiledData, delegate(bool value)
			{
				BlackboxBenchmark.logProfiledData = value;
			});
			CreateEntry(root2, "Log Profiled Data", (RectTransform[])(object)new RectTransform[1] { CreateOnOffToggle(binding6).transform });
			DelegateDataBindSource<bool> binding7 = new DelegateDataBindSource<bool>(() => BlackboxBenchmark.continuousLogging, delegate(bool value)
			{
				BlackboxBenchmark.continuousLogging = value;
			});
			CreateEntry(root2, "Continuous Logging", (RectTransform[])(object)new RectTransform[1] { CreateOnOffToggle(binding7).transform });
			DelegateDataBindSource<int> binding8 = new DelegateDataBindSource<int>(() => BlackboxBenchmark.analysisVerificationCountConfig, delegate(int value)
			{
				BlackboxBenchmark.analysisVerificationCountConfig = value;
			});
			CreateEntry(root2, "Verification Count", CreateSlider(binding8, 1, 20));
			DelegateDataBindSource<int> binding9 = new DelegateDataBindSource<int>(() => BlackboxBenchmark.analysisDurationMultiplierConfig, delegate(int value)
			{
				BlackboxBenchmark.analysisDurationMultiplierConfig = value;
			});
			CreateEntry(root2, "Duration Multiplier", CreateSlider(binding9, 1, 20));
			DelegateDataBindSource<bool> binding10 = new DelegateDataBindSource<bool>(() => BlackboxBenchmark.useItemSaturationPhaseConfig, delegate(bool value)
			{
				BlackboxBenchmark.useItemSaturationPhaseConfig = value;
			});
			CreateEntry(root2, "Use Item Saturation Phase", (RectTransform[])(object)new RectTransform[1] { CreateOnOffToggle(binding10).transform });
			CreateEntry(root2, "Note: For thresholds, 0 -> strictest, takes longer and most accurate ; 100 -> most relaxed criteria, shortest and most inaccurate.", Array.Empty<RectTransform>());
			DelegateDataBindSource<float> binding11 = new DelegateDataBindSource<float>(() => BlackboxBenchmark.stabilityDetectionThresholdConfig, delegate(float value)
			{
				BlackboxBenchmark.stabilityDetectionThresholdConfig = value;
			});
			CreateEntry(root2, "Stability Threshold", CreateSliderFloat(binding11));
			DelegateDataBindSource<float> binding12 = new DelegateDataBindSource<float>(() => BlackboxBenchmark.averagingThresholdPcConfig, delegate(float value)
			{
				BlackboxBenchmark.averagingThresholdPcConfig = value;
			});
			CreateEntry(root2, "Averaging Threshold (Power)", CreateLogSlider(binding12));
			DelegateDataBindSource<float> binding13 = new DelegateDataBindSource<float>(() => BlackboxBenchmark.averagingThresholdItemStatsConfig, delegate(float value)
			{
				BlackboxBenchmark.averagingThresholdItemStatsConfig = value;
			});
			CreateEntry(root2, "Averaging Threshold (Items)", CreateLogSlider(binding13));
			static RectTransform[] CreateCycleLengthOverride(DataBindSourceBase<bool, bool> enabledBinding, DataBindSourceBase<int, int> binding)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Expected O, but got Unknown
				ToggleContext toggleContext = CreateOnOffToggle(enabledBinding);
				ButtonContext buttonContext7 = UIBuilderDSL.Create.Button("btn-minus", "-", (UnityAction)delegate
				{
					binding.Value--;
				}).WithLayoutSize(30f, 30f).WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties)
					.BindInteractive(enabledBinding);
				InputFieldContext inputFieldContext4 = UIBuilderDSL.Create.InputField("input-field").WithLayoutSize(80f, 30f).WithContentType((ContentType)2)
					.WithFont(UIBuilder.fontSAIRAR)
					.WithFontSize(16)
					.Bind(binding.WithTransform((int x) => x.ToString(), int.Parse))
					.BindInteractive(enabledBinding);
				ButtonContext buttonContext8 = UIBuilderDSL.Create.Button("btn-plus", "+", (UnityAction)delegate
				{
					binding.Value++;
				}).WithLayoutSize(30f, 30f).WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties)
					.BindInteractive(enabledBinding);
				return (RectTransform[])(object)new RectTransform[4] { toggleContext.transform, buttonContext7.transform, inputFieldContext4.transform, buttonContext8.transform };
			}
			static HorizontalLayoutGroupContext CreateEntry(VerticalLayoutGroupContext root, string configName, RectTransform[] children)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Expected O, but got Unknown
				int num2 = 8;
				HorizontalLayoutGroupContext horizontalLayoutGroupContext = HorizontalOrVerticalLayoutGroupContextExtensions.WithSpacing(UIBuilderDSL.Create.HorizontalLayoutGroup("config-entry").WithChildAlignment((TextAnchor)3).WithPadding(new RectOffset(num2, num2, 0, 0)), num2).ForceExpand(width: false, height: false).ChildControls()
					.ChildOf((UIElementContext)root);
				UIBuilderDSL.Create.Text("name").WithLocalizer(configName).WithFontSize(16)
					.WithAlignment((TextAnchor)3)
					.WithLayoutSize(250f, 34f)
					.ChildOf((UIElementContext)horizontalLayoutGroupContext);
				horizontalLayoutGroupContext.AddChildren(children);
				return horizontalLayoutGroupContext;
			}
			static RectTransform[] CreateLogSlider(DataBindSourceBase<float, float> binding, float minValue = -32f, float maxValue = 0f)
			{
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Expected O, but got Unknown
				//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c9: Expected O, but got Unknown
				SliderConfiguration configuration = new SliderConfiguration(minValue, maxValue, wholeNumbers: false, (Direction)0);
				SliderContext sliderContext = UIBuilderDSL.Create.Slider("slider", configuration).WithLayoutSize(200f, 12f).Bind(binding.WithTransform((float x) => (float)Math.Log(x, 2.0), (float x) => (float)Math.Pow(2.0, x)));
				ButtonContext buttonContext = UIBuilderDSL.Create.Button("btn-minus", "-", (UnityAction)delegate
				{
					binding.Value = Mathf.Clamp(binding.Value / 2f, 0f, 1f);
				}).WithLayoutSize(30f, 30f).WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties);
				InputFieldContext inputFieldContext = UIBuilderDSL.Create.InputField("input-field").WithLayoutSize(80f, 30f).WithContentType((ContentType)3)
					.WithFont(UIBuilder.fontSAIRAR)
					.WithFontSize(16)
					.Bind(binding.WithTransform((float x) => (x * 100f).ToString("0.#########"), (string x) => float.Parse(x) / 100f));
				ButtonContext buttonContext2 = UIBuilderDSL.Create.Button("btn-plus", "+", (UnityAction)delegate
				{
					binding.Value = Mathf.Clamp(binding.Value * 2f, 0f, 1f);
				}).WithLayoutSize(30f, 30f).WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties);
				return (RectTransform[])(object)new RectTransform[4] { sliderContext.transform, buttonContext.transform, inputFieldContext.transform, buttonContext2.transform };
			}
			static ToggleContext CreateOnOffToggle(IDataBindSource<bool> binding)
			{
				//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_0043: 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_0053: 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_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: 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_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				Color normalColor = default(Color);
				((Color)(ref normalColor))..ctor(0.24f, 0.6f, 0.72f);
				Color val = default(Color);
				((Color)(ref val))..ctor(0.37f, 0.72f, 0.84f);
				ColorBlock val2 = UIBuilder.buttonSelectableProperties.colors.Value;
				((ColorBlock)(ref val2)).normalColor = normalColor;
				((ColorBlock)(ref val2)).highlightedColor = val;
				((ColorBlock)(ref val2)).pressedColor = val;
				((ColorBlock)(ref val2)).fadeDuration = 0.05f;
				ColorBlock val3 = val2;
				val2 = val3;
				Color white = Color.white;
				((ColorBlock)(ref val2)).normalColor = ((Color)(ref white)).RGBMultiplied(0.55f);
				white = Color.white;
				((ColorBlock)(ref val2)).highlightedColor = ((Color)(ref white)).RGBMultiplied(0.6f);
				white = Color.white;
				((ColorBlock)(ref val2)).pressedColor = ((Color)(ref white)).RGBMultiplied(0.6f);
				ColorBlock offState = val2;
				return UIBuilderDSL.Create.Toggle("checkbox").Bind(binding).WithVisuals<ToggleContext, Image>((IProperties<Image>)new ImageProperties
				{
					sprite = UIBuilder.spriteCheckboxOff
				})
					.WithOnOffVisualsAndSprites(val3, offState, UIBuilder.spriteCheckboxOn, UIBuilder.spriteCheckboxOff);
			}
			static RectTransform[] CreateSlider(DataBindSourceBase<int, int> binding, int minValue, int maxValue)
			{
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Expected O, but got Unknown
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01df: Expected O, but got Unknown
				SliderConfiguration configuration3 = new SliderConfiguration(minValue, maxValue, wholeNumbers: true, (Direction)0);
				SliderContext sliderContext3 = UIBuilderDSL.Create.Slider("slider", configuration3).WithLayoutSize(200f, 12f).Bind(binding.WithTransform((int x) => x, (float x) => (int)x));
				ButtonContext buttonContext5 = UIBuilderDSL.Create.Button("btn-minus", "-", (UnityAction)delegate
				{
					binding.Value = Mathf.Clamp(binding.Value - 1, minValue, maxValue);
				}).WithLayoutSize(30f, 30f).WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties);
				InputFieldContext inputFieldContext3 = UIBuilderDSL.Create.InputField("input-field").WithLayoutSize(80f, 30f).WithContentType((ContentType)2)
					.WithFont(UIBuilder.fontSAIRAR)
					.WithFontSize(16)
					.Bind(binding.WithTransform((int x) => x.ToString(), int.Parse));
				ButtonContext buttonContext6 = UIBuilderDSL.Create.Button("btn-plus", "+", (UnityAction)delegate
				{
					binding.Value = Mathf.Clamp(binding.Value + 1, minValue, maxValue);
				}).WithLayoutSize(30f, 30f).WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties);
				return (RectTransform[])(object)new RectTransform[4] { sliderContext3.transform, buttonContext5.transform, inputFieldContext3.transform, buttonContext6.transform };
			}
			static RectTransform[] CreateSliderFloat(DataBindSourceBase<float, float> binding, float minValue = 0f, float maxValue = 1f)
			{
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Expected O, but got Unknown
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: Expected O, but got Unknown
				SliderConfiguration configuration2 = new SliderConfiguration(minValue, maxValue, wholeNumbers: false, (Direction)0);
				SliderContext sliderContext2 = UIBuilderDSL.Create.Slider("slider", configuration2).WithLayoutSize(200f, 12f).Bind(binding);
				ButtonContext buttonContext3 = UIBuilderDSL.Create.Button("btn-minus", "-", (UnityAction)delegate
				{
					binding.Value = Mathf.Clamp(binding.Value - 0.01f, minValue, maxValue);
				}).WithLayoutSize(30f, 30f).WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties);
				InputFieldContext inputFieldContext2 = UIBuilderDSL.Create.InputField("input-field").WithLayoutSize(80f, 30f).WithContentType((ContentType)3)
					.WithFont(UIBuilder.fontSAIRAR)
					.WithFontSize(16)
					.Bind(binding.WithTransform((float x) => (x * 100f).ToString("0.##"), (string x) => float.Parse(x) / 100f));
				ButtonContext buttonContext4 = UIBuilderDSL.Create.Button("btn-plus", "+", (UnityAction)delegate
				{
					binding.Value = Mathf.Clamp(binding.Value + 0.01f, minValue, maxValue);
				}).WithLayoutSize(30f, 30f).WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties);
				return (RectTransform[])(object)new RectTransform[4] { sliderContext2.transform, buttonContext3.transform, inputFieldContext2.transform, buttonContext4.transform };
			}
		}

		private static void InitializeOverviewPanel(UIElementContext root)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			ScrollViewContext scrollViewContext = UIBuilderDSL.Create.ScrollView("scroll-view", new ScrollViewConfiguration(ScrollViewAxis.BothVerticalAndHorizontal)).ChildOf(root).WithAnchor(Anchor.Stretch)
				.At(0, 0);
			GameObject obj = ((Component)scrollViewContext.scrollRect.content).gameObject;
			UIElementContext uIElementContext = UIBuilderDSL.Create.UIElement("bg").ChildOf((Transform)(object)scrollViewContext.scrollRect.viewport).WithAnchor(Anchor.Stretch)
				.WithPivot(0f, 1f)
				.At(0, 0)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					((Graphic)x).color = Color.clear;
				});
			((Transform)uIElementContext.transform).SetAsFirstSibling();
			UIBuilderDSL.Select.UIElement(scrollViewContext.scrollRect.viewport).WithPivot(0f, 1f);
			VerticalLayoutGroupContext context = UIBuilderDSL.Select.VerticalLayoutGroup(obj).WithAnchor(Anchor.TopStretch).WithPivot(0f, 1f)
				.At(0, 0);
			Rect rect = uIElementContext.transform.rect;
			VerticalLayoutGroupContext parent = context.OfSize(0f, ((Rect)(ref rect)).height).ForceExpand(width: true, height: false).ChildControls();
			UIElementContext parent2 = UIBuilderDSL.Create.UIElement("blackbox-entry-prefab").ChildOf((UIElementContext)parent).WithAnchor(Anchor.TopStretch)
				.WithPivot(0f, 1f)
				.At(0, 0)
				.OfSize(0, 120)
				.WithLayoutSize(0f, 120f, -1f, -1f, 1f);
			UIBuilderDSL.Create.Text("name").ChildOf(parent2).WithAnchor(Anchor.TopLeft)
				.OfSize(100, 26)
				.At(30, -15)
				.WithFont(UIBuilder.fontSAIRASB)
				.WithFontSize(16)
				.WithAlignment((TextAnchor)0)
				.WithText("Name");
			TextContext context2 = IGraphicContextExtensions.WithMaterial(UIBuilderDSL.Create.Text("status-label").ChildOf(parent2).WithAnchor(Anchor.TopLeft)
				.OfSize(100, 20)
				.At(30, -40), UIBuilder.materialWidgetTextAlpha5x).WithFont(UIBuilder.fontSAIRASB).WithFontSize(14)
				.WithAlignment((TextAnchor)0);
			Color white = Color.white;
			IGraphicContextExtensions.WithColor(context2, ((Color)(ref white)).AlphaMultiplied(0.5f)).WithText("Status");
			UIElementContext parent3 = UIBuilderDSL.Create.UIElement("progress-bar").ChildOf(parent2).WithAnchor(Anchor.Center)
				.At(0, 0);
			UIElementContext parent4 = UIBuilderDSL.Create.UIElement("bar-group").ChildOf(parent3).WithAnchor(Anchor.Center)
				.At(0, 0)
				.OfSize(250, 8);
			UIBuilderDSL.Create.UIElement("bar-bg").ChildOf(parent4).WithAnchor(Anchor.CenterStretch)
				.At(0, 0)
				.OfSize(-2, 10)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//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_0024: Unknown result type (might be due to invalid IL or missing references)
					x.sprite = UIBuilder.spriteBar4px;
					((Graphic)x).material = UIBuilder.materialWidgetAlpha5x;
					Color black = Color.black;
					((Graphic)x).color = ((Color)(ref black)).AlphaMultiplied(0.7f);
				});
			UIElementContext parent5 = UIBuilderDSL.Create.UIElement("bar-fg").ChildOf(parent4).WithAnchor(Anchor.CenterStretch)
				.At(0, 0)
				.OfSize(-2, 10)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//IL_002b: Unknown result type (might be due to invalid IL or missing references)
					x.sprite = UIBuilder.spriteBar4px;
					((Graphic)x).material = UIBuilder.materialWidgetAlpha5x;
					((Graphic)x).color = new Color(0.9906f, 0.5897f, 0.3691f, 0.5294f);
					x.fillMethod = (FillMethod)0;
					x.fillAmount = 0f;
					x.type = (Type)3;
				});
			UIBuilderDSL.Create.UIElement("point").ChildOf(parent5).WithAnchor(Anchor.Left)
				.WithPivot(0.5f, 0.5f)
				.At(0, 0)
				.OfSize(6, 6)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//IL_002b: Unknown result type (might be due to invalid IL or missing references)
					x.sprite = UIBuilder.spriteRoundBlur256;
					((Graphic)x).material = UIBuilder.materialWidgetAdd5x;
					((Graphic)x).color = new Color(0.9906f, 0.5897f, 0.3691f, 0.5383f);
				});
			IGraphicContextExtensions.WithColor(IGraphicContextExtensions.WithMaterial(UIBuilderDSL.Create.Text("progress-text").ChildOf(parent3).WithAnchor(Anchor.StretchRight)
				.WithPivot(0f, 0.5f)
				.At(130, 0)
				.OfSize(60, 0), UIBuilder.materialWidgetTextAlpha5x), new Color(0.9906f, 0.5897f, 0.3691f, 0.7255f)).WithFont(UIBuilder.fontSAIRASB).WithFontSize(16)
				.WithAlignment((TextAnchor)5)
				.WithText("0 / 100");
			UIBuilderDSL.Create.Button("inspect-btn", "Inspect").ChildOf(parent2).WithAnchor(Anchor.BottomLeft)
				.At(30, 20)
				.OfSize(90, 30)
				.WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties)
				.WithFontSize(14);
			UIBuilderDSL.Create.Button("pause-resume-btn", "Pause / Resume").ChildOf(parent2).WithAnchor(Anchor.BottomLeft)
				.At(150, 20)
				.OfSize(90, 30)
				.WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties)
				.WithFontSize(14);
			UIBuilderDSL.Create.Button("delete-btn", "Delete").ChildOf(parent2).WithAnchor(Anchor.BottomRight)
				.At(-20, 20)
				.OfSize(90, 30)
				.WithVisuals<ButtonContext, Image>((IProperties<Image>)GraphicPropertiesBuilder.WithColor(UIBuilder.buttonImgProperties, UIBuilder.buttonRedColor))
				.WithFontSize(14);
			UIBuilderDSL.Create.Button("highlight-btn", "Highlight").ChildOf(parent2).WithAnchor(Anchor.BottomRight)
				.At(-130, 20)
				.OfSize(90, 30)
				.WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties)
				.WithFontSize(14);
			UIBuilderDSL.Create.UIElement("sep-line-0").ChildOf(parent2).WithAnchor(Anchor.BottomStretch)
				.At(0, 0)
				.OfSize(-2, 2)
				.WithComponent<UIElementContext, Image>((Action<Image>)delegate(Image x)
				{
					//IL_0015: Unknown result type (might be due to invalid IL or missing references)
					((Graphic)x).color = new Color(0.7689f, 0.9422f, 1f, 0.0314f);
				});
		}

		public void DestroyUI()
		{
			if ((Object)(object)uiBlackboxManagerWindow != (Object)null)
			{
				((ManualBehaviour)uiBlackboxManagerWindow)._OnDestroy();
			}
			uiBlackboxManagerWindow = null;
			if ((Object)(object)gameObject != (Object)null)
			{
				Object.Destroy((Object)(object)gameObject);
			}
			gameObject = null;
		}

		public void Free()
		{
			UIBlackboxManagerWindow uIBlackboxManagerWindow = uiBlackboxManagerWindow;
			if (uIBlackboxManagerWindow != null)
			{
				((ManualBehaviour)uIBlackboxManagerWindow)._OnFree();
			}
		}

		public void Init()
		{
		}

		public void Update()
		{
			UIBlackboxManagerWindow uIBlackboxManagerWindow = uiBlackboxManagerWindow;
			if (uIBlackboxManagerWindow != null)
			{
				((ManualBehaviour)uIBlackboxManagerWindow)._OnUpdate();
			}
		}
	}
	public class UIBlackboxOverviewPanel : ManualBehaviour
	{
		private RectTransform scrollContentRect;

		private RectTransform scrollViewportRect;

		private RectTransform scrollVbarRect;

		private UIBlackboxEntry blackboxEntry;

		private int entriesLen;

		private UIBlackboxEntry[] entries;

		public override void _OnCreate()
		{
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = ((Component)this).gameObject.SelectDescendant("scroll-view", "viewport", "content");
			scrollContentRect = ((obj != null) ? obj.GetComponent<RectTransform>() : null);
			GameObject obj2 = ((Component)this).gameObject.SelectDescendant("scroll-view", "viewport");
			scrollViewportRect = ((obj2 != null) ? obj2.GetComponent<RectTransform>() : null);
			GameObject obj3 = ((Component)this).gameObject.SelectDescendant("scroll-view", "v-bar");
			scrollVbarRect = ((obj3 != null) ? obj3.GetComponent<RectTransform>() : null);
			blackboxEntry = ((Component)this).gameObject.SelectDescendant("scroll-view", "viewport", "content", "blackbox-entry-prefab").GetOrCreateComponent<UIBlackboxEntry>();
			((ManualBehaviour)blackboxEntry)._Create();
			Rect rect = scrollContentRect.rect;
			float height = ((Rect)(ref rect)).height;
			rect = blackboxEntry.rectTransform.rect;
			entriesLen = Mathf.CeilToInt(height / ((Rect)(ref rect)).height);
			entries = new UIBlackboxEntry[entriesLen];
			for (int i = 0; i < entriesLen; i++)
			{
				UIBlackboxEntry uIBlackboxEntry = Object.Instantiate<UIBlackboxEntry>(blackboxEntry, ((Component)blackboxEntry).transform.parent);
				((ManualBehaviour)uIBlackboxEntry)._Create();
				entries[i] = uIBlackboxEntry;
			}
		}

		public override void _OnDestroy()
		{
		}

		public override bool _OnInit()
		{
			for (int i = 0; i < entriesLen; i++)
			{
				((ManualBehaviour)entries[i])._Init((object)null);
			}
			return true;
		}

		public override void _OnFree()
		{
		}

		public override void _OnUpdate()
		{
			//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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			int count = BlackboxManager.Instance.blackboxes.Count;
			int num = ((count > entriesLen) ? entriesLen : count);
			Rect rect = blackboxEntry.rectTransform.rect;
			float height = ((Rect)(ref rect)).height;
			if (height * (float)count < scrollContentRect.sizeDelta.y - 1f)
			{
				float num2 = (float)(count - num + 1) * height;
				num2 = ((num2 < 0f) ? 0f : num2);
				if (scrollContentRect.anchoredPosition.y > num2)
				{
					scrollContentRect.anchoredPosition = new Vector2(scrollContentRect.anchoredPosition.x, num2);
				}
			}
			scrollContentRect.sizeDelta = new Vector2(scrollContentRect.sizeDelta.x, height * (float)count);
			scrollContentRect.anchoredPosition = new Vector2(Mathf.Round(scrollContentRect.anchoredPosition.x), Mathf.Round(scrollContentRect.anchoredPosition.y));
			RectTransform obj = scrollViewportRect;
			? sizeDelta;
			if (!((Component)scrollVbarRect).gameObject.activeSelf)
			{
				sizeDelta = Vector2.zero;
			}
			else
			{
				rect = scrollVbarRect.rect;
				sizeDelta = new Vector2(0f - ((Rect)(ref rect)).width, 0f);
			}
			obj.sizeDelta = (Vector2)sizeDelta;
			int num3 = ((count == 0) ? (-1) : ((int)scrollContentRect.anchoredPosition.y / (int)height));
			int num4 = num3 + num - 1;
			for (int i = 0; i < entriesLen; i++)
			{
				UIBlackboxEntry uIBlackboxEntry = entries[i];
				int num5 = num3 + i;
				if (uIBlackboxEntry.index != num5)
				{
					uIBlackboxEntry.index = num5;
					uIBlackboxEntry.SetTrans();
				}
				if (num5 >= 0 && num5 <= num4 && num5 < BlackboxManager.Instance.blackboxes.Count)
				{
					uIBlackboxEntry.entryData = BlackboxManager.Instance.blackboxes[num5];
					((ManualBehaviour)uIBlackboxEntry)._Open();
				}
				else
				{
					((ManualBehaviour)uIBlackboxEntry)._Close();
					uIBlackboxEntry.entryData = null;
				}
				((ManualBehaviour)uIBlackboxEntry)._Update();
			}
		}
	}
	public class UIBlackboxSettingsPanel : ManualBehaviour
	{
	}
}
namespace DysonSphereProgram.Modding.Blackbox.UI.Builder
{
	public abstract class DataBindController<T> : MonoBehaviour
	{
		public IDataBindSource<T> Binding;

		protected bool ChangedFromUI;

		private void LateUpdate()
		{
			if (ChangedFromUI)
			{
				UIToBinding();
				ChangedFromUI = false;
			}
			else
			{
				BindingToUI();
			}
		}

		protected abstract void BindingToUI();

		protected abstract void UIToBinding();
	}
	public class DataBindSlider : DataBindController<float>
	{
		private Slider slider;

		private void Start()
		{
			slider = ((Component)this).GetComponent<Slider>();
			((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)ValueChangedHandler);
		}

		private void ValueChangedHandler(float _)
		{
			ChangedFromUI = true;
		}

		protected override void BindingToUI()
		{
			slider.value = Binding.Value;
		}

		protected override void UIToBinding()
		{
			Binding.Value = slider.value;
		}
	}
	public class DataBindToggleBool : DataBindController<bool>
	{
		private Toggle toggle;

		private void Start()
		{
			toggle = ((Component)this).GetComponent<Toggle>();
			((UnityEvent<bool>)(object)toggle.onValueChanged).AddListener((UnityAction<bool>)ValueChangedHandler);
		}

		private void ValueChangedHandler(bool _)
		{
			ChangedFromUI = true;
		}

		protected override void BindingToUI()
		{
			toggle.isOn = Binding.Value;
		}

		protected override void UIToBinding()
		{
			Binding.Value = toggle.isOn;
		}
	}
	public class DataBindToggleEnum : DataBindController<Enum>
	{
		private Toggle toggle;

		public Enum linkedValue;

		private void Start()
		{
			toggle = ((Component)this).GetComponent<Toggle>();
			((UnityEvent<bool>)(object)toggle.onValueChanged).AddListener((UnityAction<bool>)ValueChangedHandler);
		}

		private void ValueChangedHandler(bool _)
		{
			ChangedFromUI = true;
		}

		protected override void BindingToUI()
		{
			toggle.isOn = Binding.Value.Equals(linkedValue);
		}

		protected override void UIToBinding()
		{
			if (toggle.isOn)
			{
				Binding.Value = linkedValue;
			}
		}
	}
	public class DataBindInputField : DataBindController<string>
	{
		private InputField inputField;

		private bool uiDirty;

		private void Start()
		{
			inputField = ((Component)this).GetComponent<InputField>();
			((UnityEvent<string>)(object)inputField.onValueChanged).AddListener((UnityAction<string>)ValueChangedHandler);
			((UnityEvent<string>)(object)inputField.onEndEdit).AddListener((UnityAction<string>)SubmitHandler);
		}

		private void ValueChangedHandler(string value)
		{
			if (value != Binding.Value)
			{
				uiDirty = true;
			}
		}

		private void SubmitHandler(string _)
		{
			ChangedFromUI = true;
		}

		protected override void BindingToUI()
		{
			if (!uiDirty)
			{
				inputField.text = Binding.Value;
			}
		}

		protected override void UIToBinding()
		{
			Binding.Value = inputField.text;
			uiDirty = false;
		}
	}
	public interface IOneWayDataBindSource
	{
		object Value { get; }
	}
	public interface IOneWayDataBindSource<out TVisual>
	{
		TVisual Value { get; }
	}
	public interface IDataBindSource<TVisual>
	{
		TVisual Value { get; set; }
	}
	public class DataBindTransform<TLogical, TVisual>
	{
		public readonly Func<TLogical, TVisual> LogicalToVisualTransform;

		public readonly Func<TVisual, TLogical> VisualToLogicalTransform;

		public DataBindTransform(Func<TLogical, TVisual> forward, Func<TVisual, TLogical> reverse)
		{
			LogicalToVisualTransform = forward;
			VisualToLogicalTransform = reverse;
		}
	}
	public static class DataBindTransform
	{
		public static DataBindTransform<TLogical, TVisual> From<TLogical, TVisual>(Func<TLogical, TVisual> forward, Func<TVisual, TLogical> reverse)
		{
			return new DataBindTransform<TLogical, TVisual>(forward, reverse);
		}

		public static DataBindTransform<T, T> Identity<T>()
		{
			return From((T x) => x, (T x) => x);
		}
	}
	public abstract class DataBindSourceBase<TLogical, TVisual> : IDataBindSource<TVisual>, IOneWayDataBindSource<TVisual>, IOneWayDataBindSource
	{
		protected readonly DataBindTransform<TLogical, TVisual> transform;

		object IOneWayDataBindSource.Value => Value;

		public virtual TVisual Value
		{
			get
			{
				return transform.LogicalToVisualTransform(Get());
			}
			set
			{
				Set(transform.VisualToLogicalTransform(value));
			}
		}

		protected DataBindSourceBase(DataBindTransform<TLogical, TVisual> transform)
		{
			this.transform = transform;
		}

		protected abstract TLogical Get();

		protected abstract void Set(TLogical value);

		public DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(Func<TLogical, UVisual> forward, Func<UVisual, TLogical> reverse)
		{
			return WithTransform(DataBindTransform.From(forward, reverse));
		}

		public abstract DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(DataBindTransform<TLogical, UVisual> newTransform);
	}
	public class ConfigEntryDataBindSource<TLogical, TVisual> : DataBindSourceBase<TLogical, TVisual>
	{
		private readonly ConfigEntry<TLogical> entry;

		public ConfigEntryDataBindSource(ConfigEntry<TLogical> entry, DataBindTransform<TLogical, TVisual> transform)
			: base(transform)
		{
			this.entry = entry;
		}

		protected override TLogical Get()
		{
			return entry.Value;
		}

		protected override void Set(TLogical value)
		{
			entry.Value = value;
		}

		public override DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(DataBindTransform<TLogical, UVisual> newTransform)
		{
			return new ConfigEntryDataBindSource<TLogical, UVisual>(entry, newTransform);
		}
	}
	public class ConfigEntryDataBindSource<T> : ConfigEntryDataBindSource<T, T>
	{
		public static implicit operator ConfigEntryDataBindSource<T>(ConfigEntry<T> entry)
		{
			return new ConfigEntryDataBindSource<T>(entry);
		}

		public ConfigEntryDataBindSource(ConfigEntry<T> entry)
			: base(entry, DataBindTransform.Identity<T>())
		{
		}
	}
	public class MemberDataBindSource<U, TLogical, TVisual> : DataBindSourceBase<TLogical, TVisual>
	{
		private readonly U obj;

		private readonly Func<U, TLogical> getter;

		private readonly Action<U, TLogical> setter;

		public MemberDataBindSource(U obj, Func<U, TLogical> getter, Action<U, TLogical> setter, DataBindTransform<TLogical, TVisual> transform)
			: base(transform)
		{
			this.obj = obj;
			this.getter = getter;
			this.setter = setter;
		}

		protected override TLogical Get()
		{
			return getter(obj);
		}

		protected override void Set(TLogical value)
		{
			setter(obj, value);
		}

		public override DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(DataBindTransform<TLogical, UVisual> newTransform)
		{
			return new MemberDataBindSource<U, TLogical, UVisual>(obj, getter, setter, newTransform);
		}
	}
	public class MemberDataBindSource<U, T> : MemberDataBindSource<U, T, T>
	{
		public MemberDataBindSource(U obj, Func<U, T> getter, Action<U, T> setter)
			: base(obj, getter, setter, DataBindTransform.Identity<T>())
		{
		}
	}
	public class DelegateDataBindSource<TLogical, TVisual> : DataBindSourceBase<TLogical, TVisual>
	{
		private readonly Func<TLogical> getter;

		private readonly Action<TLogical> setter;

		public DelegateDataBindSource(Func<TLogical> getter, Action<TLogical> setter, DataBindTransform<TLogical, TVisual> transform)
			: base(transform)
		{
			this.getter = getter;
			this.setter = setter;
		}

		protected override TLogical Get()
		{
			return getter();
		}

		protected override void Set(TLogical value)
		{
			setter(value);
		}

		public override DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(DataBindTransform<TLogical, UVisual> newTransform)
		{
			return new DelegateDataBindSource<TLogical, UVisual>(getter, setter, newTransform);
		}
	}
	public class DelegateDataBindSource<T> : DelegateDataBindSource<T, T>
	{
		public DelegateDataBindSource(Func<T> getter, Action<T> setter)
			: base(getter, setter, DataBindTransform.Identity<T>())
		{
		}
	}
	public class UIModWindowBase : ManualBehaviour, IInitializeFromContext<UIBuilderDSL.FancyWindowContext>, IInitializeFromContext<UIBuilderDSL.PlainWindowContext>, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		private bool toCaptureScroll;

		private bool focusPointEnter;

		public void InitializeFromContext(UIBuilderDSL.FancyWindowContext context)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			InitializeFromContext((UIBuilderDSL.WindowContext<UIBuilderDSL.FancyWindowContext>)context.WithCloseButton(new UnityAction(base._Close)));
		}

		public void InitializeFromContext(UIBuilderDSL.PlainWindowContext context)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			InitializeFromContext((UIBuilderDSL.WindowContext<UIBuilderDSL.PlainWindowContext>)context.WithCloseButton(new UnityAction(base._Close)));
		}

		private void InitializeFromContext<T>(UIBuilderDSL.WindowContext<T> context) where T : UIBuilderDSL.WindowContext<T>
		{
			toCaptureScroll = context.scrollCapture;
			((ManualBehaviour)this)._Create();
			((ManualBehaviour)this)._Init((object)null);
			((ManualBehaviour)this)._Open();
		}

		public override void _OnClose()
		{
			if (toCaptureScroll)
			{
				UIBuilder.inScrollView.Remove(this);
			}
			((ManualBehaviour)this)._OnClose();
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			if (toCaptureScroll)
			{
				UIBuilder.inScrollView.Add(this);
			}
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			if (toCaptureScroll)
			{
				UIBuilder.inScrollView.Remove(this);
			}
		}

		private void OnApplicationFocus(bool focus)
		{
			if (!toCaptureScroll)
			{
				return;
			}
			if (!focus)
			{
				focusPointEnter = UIBuilder.inScrollView.Contains(this);
				UIBuilder.inScrollView.Remove(this);
			}
			if (focus)
			{
				if (focusPointEnter)
				{
					UIBuilder.inScrollView.Add(this);
				}
				else
				{
					UIBuilder.inScrollView.Remove(this);
				}
			}
		}
	}
	public class UIWindowResize : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		public EventTrigger resizeTrigger;

		public RectTransform resizeTrans;

		public int resizeThreshold = 4;

		public Vector2 minSize;

		private bool mouseDown;

		private bool mouseOver;

		private Vector2 resizeMouseBegin;

		private Vector2 resizeSizeDeltaBegin;

		private Vector2 resizeSizeDeltaWanted;

		public bool pointerIn;

		public bool resizing { get; private set; }

		private void OnEnable()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0008: 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_003b: Expected O, but got Unknown
			//IL_003d: 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: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			Entry val = new Entry();
			val.eventID = (EventTriggerType)2;
			((UnityEvent<BaseEventData>)(object)val.callback).AddListener((UnityAction<BaseEventData>)OnPointerDown);
			resizeTrigger.triggers.Add(val);
			Entry val2 = new Entry();
			val2.eventID = (EventTriggerType)3;
			((UnityEvent<BaseEventData>)(object)val2.callback).AddListener((UnityAction<BaseEventData>)OnPointerUp);
			resizeTrigger.triggers.Add(val2);
			Entry val3 = new Entry();
			val3.eventID = (EventTriggerType)0;
			((UnityEvent<BaseEventData>)(object)val3.callback).AddListener((UnityAction<BaseEventData>)OnPointerEnterResizeArea);
			resizeTrigger.triggers.Add(val3);
			Entry val4 = new Entry();
			val4.eventID = (EventTriggerType)1;
			((UnityEvent<BaseEventData>)(object)val4.callback).AddListener((UnityAction<BaseEventData>)OnPointerExitResizeArea);
			resizeTrigger.triggers.Add(val4);
			if ((Object)(object)resizeTrans == (Object)null)
			{
				ref RectTransform reference = ref resizeTrans;
				Transform transform = ((Component)this).transform;
				reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			}
			VFAudio.Create("common-popup-3", (Transform)null, Vector3.zero, true, 2, -1, -1L);
		}

		private void OnDisable()
		{
			//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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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)
			resizeTrigger.triggers.Clear();
			mouseDown = false;
			resizeMouseBegin = Vector2.zero;
			resizeSizeDeltaBegin = Vector2.zero;
			if (resizing)
			{
				resizeTrans.sizeDelta = new Vector2(Mathf.Round(resizeSizeDeltaWanted.x), Mathf.Round(resizeSizeDeltaWanted.y));
			}
			pointerIn = false;
		}

		private void OnApplicationFocus(bool focus)
		{
			if (!focus)
			{
				pointerIn = false;
			}
		}

		private void OnPointerDown(BaseEventData eventData)
		{
			//IL_0007: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			mouseDown = true;
			UIRoot.ScreenPointIntoRect(Input.mousePosition, resizeTrans, ref resizeMouseBegin);
			resizeSizeDeltaBegin = resizeTrans.sizeDelta;
			resizeSizeDeltaWanted = resizeTrans.sizeDelta;
			UICursor.SetCursor((ECursor)2);
		}

		private void OnPointerUp(BaseEventData eventData)
		{
			//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_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)
			mouseDown = false;
			resizeMouseBegin = Vector2.zero;
			resizeSizeDeltaBegin = Vector2.zero;
		}

		private void OnPointerEnterResizeArea(BaseEventData eventData)
		{
			mouseOver = true;
		}

		private void OnPointerExitResizeArea(BaseEventData eventData)
		{
			mouseOver = false;
		}

		private void BringToFront()
		{
			int childCount = ((Component)this).transform.parent.childCount;
			if (((Component)this).transform.GetSiblingIndex() < childCount - 1)
			{
				((Component)this).transform.SetAsLastSibling();
			}
		}

		private void Update()
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			if (mouseDown)
			{
				if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1))
				{
					mouseDown = false;
				}
				Vector2 val = default(Vector2);
				UIRoot.ScreenPointIntoRect(Input.mousePosition, resizeTrans, ref val);
				Vector2 val2 = val - resizeMouseBegin;
				if (Mathf.Abs(val2.x) + Mathf.Abs(val2.y) > (float)resizeThreshold)
				{
					resizing = true;
					resizeSizeDeltaWanted = resizeSizeDeltaBegin + new Vector2(val2.x, 0f - val2.y);
					resizeTrans.sizeDelta = new Vector2(Mathf.Round(Mathf.Max(resizeSizeDeltaWanted.x, minSize.x)), Mathf.Round(Mathf.Max(resizeSizeDeltaWanted.y, minSize.y)));
				}
				UICursor.SetCursor((ECursor)2);
			}
			else
			{
				resizing = false;
				resizeMouseBegin = Vector2.zero;
				resizeSizeDeltaBegin = Vector2.zero;
				if (mouseOver)
				{
					UICursor.SetCursor((ECursor)3);
				}
			}
			if (pointerIn && (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)))
			{
				BringToFront();
			}
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			pointerIn = true;
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			pointerIn = false;
		}
	}
	public abstract class ValueChangeHandler<T> : MonoBehaviour
	{
		public Action<T> Handler;

		protected T prevValue;

		protected abstract T CurrentValue { get; }

		private void OnEnable()
		{
			Handler?.Invoke(CurrentValue);
		}

		private void LateUpdate()
		{
			T currentValue;
			T val = (currentValue = CurrentValue);
			if (!val.Equals(prevValue))
			{
				Handler?.Invoke(currentValue);
				prevValue = currentValue;
			}
		}
	}
	public class DataBindValueChangeHandler : ValueChangeHandler<object>
	{
		public IOneWayDataBindSource Binding;

		protected override object CurrentValue => Binding.Value;
	}
	public abstract class DataBindValueChangeHandler<T> : ValueChangeHandler<T>
	{
		public IOneWayDataBindSource<T> Binding;

		protected override T CurrentValue => Binding.Value;
	}
	public class DataBindValueChangedHandlerBool : DataBindValueChangeHandler<bool>
	{
	}
	public class DataBindValueChangedHandlerInt : DataBindValueChangeHandler<int>
	{
	}
	public class DataBindValueChangedHandlerLong : DataBindValueChangeHandler<long>
	{
	}
	public class DataBindValueChangedHandlerFloat : DataBindValueChangeHandler<float>
	{
	}
	public class DataBindValueChangedHandlerDouble : DataBindValueChangeHandler<double>
	{
	}
	public class ToggleValueChangedHandler : ValueChangeHandler<bool>
	{
		public Toggle toggle;

		protected override bool CurrentValue => toggle.isOn;

		private void Start()
		{
			if (!Object.op_Implicit((Object)(object)toggle))
			{
				toggle = ((Component)this).GetComponent<Toggle>();
			}
		}
	}
	public class SliderValueChangedHandler : ValueChangeHandler<float>
	{
		public Slider slider;

		protected override float CurrentValue => slider.value;

		private void Start()
		{
			if (!Object.op_Implicit((Object)(object)slider))
			{
				slider = ((Component)this).GetComponent<Slider>();
			}
		}
	}
	public interface IProperties<T> where T : Component
	{
		void Apply(T component);
	}
	public abstract record GraphicProperties : IProperties<Graphic>
	{
		public Material material { get; init; }

		public Color color { get; init; } = Color.white;


		public bool raycastTarget { get; init; } = true;


		public void Apply(Graphic component)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)material != (Object)null)
			{
				component.material = material;
			}
			component.color = color;
			component.raycastTarget = raycastTarget;
		}

		[CompilerGenerated]
		protected virtual bool PrintMembers(StringBuilder builder)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			RuntimeHelpers.EnsureSufficientExecutionStack();
			builder.Append("material = ");
			builder.Append(material);
			builder.Append(", color = ");
			Color val = color;
			builder.Append(((object)(Color)(ref val)).ToString());
			builder.Append(", raycastTarget = ");
			builder.Append(raycastTarget.ToString());
			return true;
		}
	}
	public abstract record MaskableGraphicProperties : GraphicProperties, IProperties<MaskableGraphic>
	{
		public bool maskable { get; init; } = true;


		public void Apply(MaskableGraphic component)
		{
			base.Apply((Graphic)(object)component);
			component.maskable = maskable;
		}
	}
	public record RawImageProperties : MaskableGraphicProperties, IProperties<RawImage>
	{
		public Texture texture { get; init; }

		public Rect uvRect { get; init; } = new Rect(0f, 0f, 1f, 1f);


		public void Apply(RawImage component)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			base.Apply((MaskableGraphic)(object)component);
			if ((Object)(object)texture != (Object)null)
			{
				component.texture = texture;
			}
			component.uvRect = uvRect;
		}

		[CompilerGenerated]
		protected override bool PrintMembers(StringBuilder builder)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing

System.Buffers.dll

Decompiled 10 months 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.28619.01")]
[assembly: AssemblyInformationalVersion("4.6.28619.01 @BuiltBy: dlab14-DDVSOWINAGE069 @Branch: release/2.1 @SrcCode: https://github.com/dotnet/corefx/tree/7601f4f6225089ffb291dc7d58293c7bbf5c5d4f")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.0.3.0")]
[module: UnverifiableCode]
namespace FxResources.System.Buffers
{
	internal static class SR
	{
	}
}
namespace System
{
	internal static class SR
	{
		private static ResourceManager s_resourceManager;

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

		internal static Type ResourceType { get; } = typeof(SR);


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

		[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.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 = new EventData
			{
				Size = 4,
				DataPointer = (IntPtr)(&bufferId)
			};
			ptr[1] = new EventData
			{
				Size = 4,
				DataPointer = (IntPtr)(&bufferSize)
			};
			ptr[2] = new EventData
			{
				Size = 4,
				DataPointer = (IntPtr)(&poolId)
			};
			ptr[3] = new EventData
			{
				Size = 4,
				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 = new EventData
			{
				Size = 4,
				DataPointer = (IntPtr)(&bufferId)
			};
			ptr[1] = new EventData
			{
				Size = 4,
				DataPointer = (IntPtr)(&bufferSize)
			};
			ptr[2] = new EventData
			{
				Size = 4,
				DataPointer = (IntPtr)(&poolId)
			};
			ptr[3] = new EventData
			{
				Size = 4,
				DataPointer = (IntPtr)(&bucketId)
			};
			ptr[4] = new EventData
			{
				Size = 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;
		}
	}
}

System.Collections.Immutable.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using FxResources.System.Collections.Immutable;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("System.Collections.Immutable.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName = ".NET Framework 4.6.1")]
[assembly: CLSCompliant(true)]
[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.System32 | DllImportSearchPath.AssemblyDirectory)]
[assembly: AssemblyDefaultAlias("System.Collections.Immutable")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: AssemblyMetadata("IsTrimmable", "True")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyDescription("This package provides collections that are thread safe and guaranteed to never change their contents, also known as immutable collections. Like strings, any methods that perform modifications will not change the existing instance but instead return a new instance. For efficiency reasons, the implementation uses a sharing mechanism to ensure that newly created instances share as much data as possible with the previous instance while ensuring that operations have a predictable time complexity.\r\n\r\nCommonly Used Types:\r\nSystem.Collections.Immutable.ImmutableArray\r\nSystem.Collections.Immutable.ImmutableArray<T>\r\nSystem.Collections.Immutable.ImmutableDictionary\r\nSystem.Collections.Immutable.ImmutableDictionary<TKey,TValue>\r\nSystem.Collections.Immutable.ImmutableHashSet\r\nSystem.Collections.Immutable.ImmutableHashSet<T>\r\nSystem.Collections.Immutable.ImmutableList\r\nSystem.Collections.Immutable.ImmutableList<T>\r\nSystem.Collections.Immutable.ImmutableQueue\r\nSystem.Collections.Immutable.ImmutableQueue<T>\r\nSystem.Collections.Immutable.ImmutableSortedDictionary\r\nSystem.Collections.Immutable.ImmutableSortedDictionary<TKey,TValue>\r\nSystem.Collections.Immutable.ImmutableSortedSet\r\nSystem.Collections.Immutable.ImmutableSortedSet<T>\r\nSystem.Collections.Immutable.ImmutableStack\r\nSystem.Collections.Immutable.ImmutableStack<T>")]
[assembly: AssemblyFileVersion("6.0.21.52210")]
[assembly: AssemblyInformationalVersion("6.0.0+4822e3c3aa77eb82b2fb33c9321f923cf11ddde6")]
[assembly: AssemblyProduct("Microsoft® .NET")]
[assembly: AssemblyTitle("System.Collections.Immutable")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/dotnet/runtime")]
[assembly: AssemblyVersion("6.0.0.0")]
[module: System.Runtime.CompilerServices.NullablePublicOnly(true)]
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]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class NullablePublicOnlyAttribute : Attribute
	{
		public readonly bool IncludesInternals;

		public NullablePublicOnlyAttribute(bool P_0)
		{
			IncludesInternals = P_0;
		}
	}
}
namespace FxResources.System.Collections.Immutable
{
	internal static class SR
	{
	}
}
namespace System
{
	internal static class SR
	{
		private static readonly bool s_usingResourceKeys = AppContext.TryGetSwitch("System.Resources.UseSystemResourceKeys", out var isEnabled) && isEnabled;

		private static ResourceManager s_resourceManager;

		internal static ResourceManager ResourceManager => s_resourceManager ?? (s_resourceManager = new ResourceManager(typeof(SR)));

		internal static string Arg_KeyNotFoundWithKey => GetResourceString("Arg_KeyNotFoundWithKey");

		internal static string ArrayInitializedStateNotEqual => GetResourceString("ArrayInitializedStateNotEqual");

		internal static string ArrayLengthsNotEqual => GetResourceString("ArrayLengthsNotEqual");

		internal static string CannotFindOldValue => GetResourceString("CannotFindOldValue");

		internal static string CapacityMustBeGreaterThanOrEqualToCount => GetResourceString("CapacityMustBeGreaterThanOrEqualToCount");

		internal static string CapacityMustEqualCountOnMove => GetResourceString("CapacityMustEqualCountOnMove");

		internal static string CollectionModifiedDuringEnumeration => GetResourceString("CollectionModifiedDuringEnumeration");

		internal static string DuplicateKey => GetResourceString("DuplicateKey");

		internal static string InvalidEmptyOperation => GetResourceString("InvalidEmptyOperation");

		internal static string InvalidOperationOnDefaultArray => GetResourceString("InvalidOperationOnDefaultArray");

		private static bool UsingResourceKeys()
		{
			return s_usingResourceKeys;
		}

		internal static string GetResourceString(string resourceKey)
		{
			if (UsingResourceKeys())
			{
				return resourceKey;
			}
			string result = null;
			try
			{
				result = ResourceManager.GetString(resourceKey);
			}
			catch (MissingManifestResourceException)
			{
			}
			return result;
		}

		internal static string GetResourceString(string resourceKey, string defaultString)
		{
			string resourceString = GetResourceString(resourceKey);
			if (!(resourceKey == resourceString) && resourceString != null)
			{
				return resourceString;
			}
			return defaultString;
		}

		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);
		}

		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(IFormatProvider? provider, string resourceFormat, object? p1)
		{
			if (UsingResourceKeys())
			{
				return string.Join(", ", resourceFormat, p1);
			}
			return string.Format(provider, resourceFormat, p1);
		}

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

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

		internal static string Format(IFormatProvider? provider, string resourceFormat, params object?[]? args)
		{
			if (args != null)
			{
				if (UsingResourceKeys())
				{
					return resourceFormat + ", " + string.Join(", ", args);
				}
				return string.Format(provider, resourceFormat, args);
			}
			return resourceFormat;
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
	internal sealed class AllowNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
	internal sealed class DisallowNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
	internal sealed class MaybeNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
	internal sealed class NotNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	internal sealed class MaybeNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public MaybeNullWhenAttribute(bool returnValue)
		{
			ReturnValue = returnValue;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	internal sealed class NotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public NotNullWhenAttribute(bool returnValue)
		{
			ReturnValue = returnValue;
		}
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
	internal sealed class NotNullIfNotNullAttribute : Attribute
	{
		public string ParameterName { get; }

		public NotNullIfNotNullAttribute(string parameterName)
		{
			ParameterName = parameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Method, Inherited = false)]
	internal sealed class DoesNotReturnAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	internal sealed class DoesNotReturnIfAttribute : Attribute
	{
		public bool ParameterValue { get; }

		public DoesNotReturnIfAttribute(bool parameterValue)
		{
			ParameterValue = parameterValue;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}
namespace System.Runtime.Versioning
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
	internal sealed class NonVersionableAttribute : Attribute
	{
	}
}
namespace System.Linq
{
	public static class ImmutableArrayExtensions
	{
		public static IEnumerable<TResult> Select<T, TResult>(this ImmutableArray<T> immutableArray, Func<T, TResult> selector)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			return immutableArray.array.Select(selector);
		}

		public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this ImmutableArray<TSource> immutableArray, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			if (collectionSelector == null || resultSelector == null)
			{
				return Enumerable.SelectMany(immutableArray, collectionSelector, resultSelector);
			}
			if (immutableArray.Length != 0)
			{
				return immutableArray.SelectManyIterator(collectionSelector, resultSelector);
			}
			return Enumerable.Empty<TResult>();
		}

		public static IEnumerable<T> Where<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			return immutableArray.array.Where(predicate);
		}

		public static bool Any<T>(this ImmutableArray<T> immutableArray)
		{
			return immutableArray.Length > 0;
		}

		public static bool Any<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			Requires.NotNull(predicate, "predicate");
			T[] array = immutableArray.array;
			foreach (T arg in array)
			{
				if (predicate(arg))
				{
					return true;
				}
			}
			return false;
		}

		public static bool All<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			Requires.NotNull(predicate, "predicate");
			T[] array = immutableArray.array;
			foreach (T arg in array)
			{
				if (!predicate(arg))
				{
					return false;
				}
			}
			return true;
		}

		public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, ImmutableArray<TDerived> items, IEqualityComparer<TBase>? comparer = null) where TDerived : TBase
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			items.ThrowNullRefIfNotInitialized();
			if (immutableArray.array == items.array)
			{
				return true;
			}
			if (immutableArray.Length != items.Length)
			{
				return false;
			}
			if (comparer == null)
			{
				comparer = EqualityComparer<TBase>.Default;
			}
			for (int i = 0; i < immutableArray.Length; i++)
			{
				if (!comparer.Equals(immutableArray.array[i], (TBase)(object)items.array[i]))
				{
					return false;
				}
			}
			return true;
		}

		public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, IEnumerable<TDerived> items, IEqualityComparer<TBase>? comparer = null) where TDerived : TBase
		{
			Requires.NotNull(items, "items");
			if (comparer == null)
			{
				comparer = EqualityComparer<TBase>.Default;
			}
			int num = 0;
			int length = immutableArray.Length;
			foreach (TDerived item in items)
			{
				if (num == length)
				{
					return false;
				}
				if (!comparer.Equals(immutableArray[num], (TBase)(object)item))
				{
					return false;
				}
				num++;
			}
			return num == length;
		}

		public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, ImmutableArray<TDerived> items, Func<TBase, TBase, bool> predicate) where TDerived : TBase
		{
			Requires.NotNull(predicate, "predicate");
			immutableArray.ThrowNullRefIfNotInitialized();
			items.ThrowNullRefIfNotInitialized();
			if (immutableArray.array == items.array)
			{
				return true;
			}
			if (immutableArray.Length != items.Length)
			{
				return false;
			}
			int i = 0;
			for (int length = immutableArray.Length; i < length; i++)
			{
				if (!predicate(immutableArray[i], (TBase)(object)items[i]))
				{
					return false;
				}
			}
			return true;
		}

		public static T? Aggregate<T>(this ImmutableArray<T> immutableArray, Func<T, T, T> func)
		{
			Requires.NotNull(func, "func");
			if (immutableArray.Length == 0)
			{
				return default(T);
			}
			T val = immutableArray[0];
			int i = 1;
			for (int length = immutableArray.Length; i < length; i++)
			{
				val = func(val, immutableArray[i]);
			}
			return val;
		}

		public static TAccumulate Aggregate<TAccumulate, T>(this ImmutableArray<T> immutableArray, TAccumulate seed, Func<TAccumulate, T, TAccumulate> func)
		{
			Requires.NotNull(func, "func");
			TAccumulate val = seed;
			T[] array = immutableArray.array;
			foreach (T arg in array)
			{
				val = func(val, arg);
			}
			return val;
		}

		public static TResult Aggregate<TAccumulate, TResult, T>(this ImmutableArray<T> immutableArray, TAccumulate seed, Func<TAccumulate, T, TAccumulate> func, Func<TAccumulate, TResult> resultSelector)
		{
			Requires.NotNull(resultSelector, "resultSelector");
			return resultSelector(immutableArray.Aggregate(seed, func));
		}

		public static T ElementAt<T>(this ImmutableArray<T> immutableArray, int index)
		{
			return immutableArray[index];
		}

		public static T? ElementAtOrDefault<T>(this ImmutableArray<T> immutableArray, int index)
		{
			if (index < 0 || index >= immutableArray.Length)
			{
				return default(T);
			}
			return immutableArray[index];
		}

		public static T First<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			Requires.NotNull(predicate, "predicate");
			T[] array = immutableArray.array;
			foreach (T val in array)
			{
				if (predicate(val))
				{
					return val;
				}
			}
			return Enumerable.Empty<T>().First();
		}

		public static T First<T>(this ImmutableArray<T> immutableArray)
		{
			if (immutableArray.Length <= 0)
			{
				return immutableArray.array.First();
			}
			return immutableArray[0];
		}

		public static T? FirstOrDefault<T>(this ImmutableArray<T> immutableArray)
		{
			if (immutableArray.array.Length == 0)
			{
				return default(T);
			}
			return immutableArray.array[0];
		}

		public static T? FirstOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			Requires.NotNull(predicate, "predicate");
			T[] array = immutableArray.array;
			foreach (T val in array)
			{
				if (predicate(val))
				{
					return val;
				}
			}
			return default(T);
		}

		public static T Last<T>(this ImmutableArray<T> immutableArray)
		{
			if (immutableArray.Length <= 0)
			{
				return immutableArray.array.Last();
			}
			return immutableArray[immutableArray.Length - 1];
		}

		public static T Last<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			Requires.NotNull(predicate, "predicate");
			for (int num = immutableArray.Length - 1; num >= 0; num--)
			{
				if (predicate(immutableArray[num]))
				{
					return immutableArray[num];
				}
			}
			return Enumerable.Empty<T>().Last();
		}

		public static T? LastOrDefault<T>(this ImmutableArray<T> immutableArray)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			return immutableArray.array.LastOrDefault();
		}

		public static T? LastOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			Requires.NotNull(predicate, "predicate");
			for (int num = immutableArray.Length - 1; num >= 0; num--)
			{
				if (predicate(immutableArray[num]))
				{
					return immutableArray[num];
				}
			}
			return default(T);
		}

		public static T Single<T>(this ImmutableArray<T> immutableArray)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			return immutableArray.array.Single();
		}

		public static T Single<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			Requires.NotNull(predicate, "predicate");
			bool flag = true;
			T result = default(T);
			T[] array = immutableArray.array;
			foreach (T val in array)
			{
				if (predicate(val))
				{
					if (!flag)
					{
						ImmutableArray.TwoElementArray.Single();
					}
					flag = false;
					result = val;
				}
			}
			if (flag)
			{
				Enumerable.Empty<T>().Single();
			}
			return result;
		}

		public static T? SingleOrDefault<T>(this ImmutableArray<T> immutableArray)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			return immutableArray.array.SingleOrDefault();
		}

		public static T? SingleOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
		{
			Requires.NotNull(predicate, "predicate");
			bool flag = true;
			T result = default(T);
			T[] array = immutableArray.array;
			foreach (T val in array)
			{
				if (predicate(val))
				{
					if (!flag)
					{
						ImmutableArray.TwoElementArray.Single();
					}
					flag = false;
					result = val;
				}
			}
			return result;
		}

		public static Dictionary<TKey, T> ToDictionary<TKey, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector) where TKey : notnull
		{
			return immutableArray.ToDictionary(keySelector, EqualityComparer<TKey>.Default);
		}

		public static Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, Func<T, TElement> elementSelector) where TKey : notnull
		{
			return immutableArray.ToDictionary(keySelector, elementSelector, EqualityComparer<TKey>.Default);
		}

		public static Dictionary<TKey, T> ToDictionary<TKey, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, IEqualityComparer<TKey>? comparer) where TKey : notnull
		{
			Requires.NotNull(keySelector, "keySelector");
			Dictionary<TKey, T> dictionary = new Dictionary<TKey, T>(immutableArray.Length, comparer);
			ImmutableArray<T>.Enumerator enumerator = immutableArray.GetEnumerator();
			while (enumerator.MoveNext())
			{
				T current = enumerator.Current;
				dictionary.Add(keySelector(current), current);
			}
			return dictionary;
		}

		public static Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, Func<T, TElement> elementSelector, IEqualityComparer<TKey>? comparer) where TKey : notnull
		{
			Requires.NotNull(keySelector, "keySelector");
			Requires.NotNull(elementSelector, "elementSelector");
			Dictionary<TKey, TElement> dictionary = new Dictionary<TKey, TElement>(immutableArray.Length, comparer);
			T[] array = immutableArray.array;
			foreach (T arg in array)
			{
				dictionary.Add(keySelector(arg), elementSelector(arg));
			}
			return dictionary;
		}

		public static T[] ToArray<T>(this ImmutableArray<T> immutableArray)
		{
			immutableArray.ThrowNullRefIfNotInitialized();
			if (immutableArray.array.Length == 0)
			{
				return ImmutableArray<T>.Empty.array;
			}
			return (T[])immutableArray.array.Clone();
		}

		public static T First<T>(this ImmutableArray<T>.Builder builder)
		{
			Requires.NotNull(builder, "builder");
			if (!builder.Any())
			{
				throw new InvalidOperationException();
			}
			return builder[0];
		}

		public static T? FirstOrDefault<T>(this ImmutableArray<T>.Builder builder)
		{
			Requires.NotNull(builder, "builder");
			if (!builder.Any())
			{
				return default(T);
			}
			return builder[0];
		}

		public static T Last<T>(this ImmutableArray<T>.Builder builder)
		{
			Requires.NotNull(builder, "builder");
			if (!builder.Any())
			{
				throw new InvalidOperationException();
			}
			return builder[builder.Count - 1];
		}

		public static T? LastOrDefault<T>(this ImmutableArray<T>.Builder builder)
		{
			Requires.NotNull(builder, "builder");
			if (!builder.Any())
			{
				return default(T);
			}
			return builder[builder.Count - 1];
		}

		public static bool Any<T>(this ImmutableArray<T>.Builder builder)
		{
			Requires.NotNull(builder, "builder");
			return builder.Count > 0;
		}

		private static IEnumerable<TResult> SelectManyIterator<TSource, TCollection, TResult>(this ImmutableArray<TSource> immutableArray, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
		{
			TSource[] array = immutableArray.array;
			foreach (TSource item in array)
			{
				foreach (TCollection item2 in collectionSelector(item))
				{
					yield return resultSelector(item, item2);
				}
			}
		}
	}
}
namespace System.Collections.Immutable
{
	internal static class AllocFreeConcurrentStack<T>
	{
		private const int MaxSize = 35;

		private static readonly Type s_typeOfT = typeof(T);

		private static Stack<RefAsValueType<T>> ThreadLocalStack
		{
			get
			{
				Dictionary<Type, object> dictionary = AllocFreeConcurrentStack.t_stacks;
				if (dictionary == null)
				{
					dictionary = (AllocFreeConcurrentStack.t_stacks = new Dictionary<Type, object>());
				}
				if (!dictionary.TryGetValue(s_typeOfT, out var value))
				{
					value = new Stack<RefAsValueType<T>>(35);
					dictionary.Add(s_typeOfT, value);
				}
				return (Stack<RefAsValueType<T>>)value;
			}
		}

		public static void TryAdd(T item)
		{
			Stack<RefAsValueType<T>> threadLocalStack = ThreadLocalStack;
			if (threadLocalStack.Count < 35)
			{
				threadLocalStack.Push(new RefAsValueType<T>(item));
			}
		}

		public static bool TryTake([MaybeNullWhen(false)] out T item)
		{
			Stack<RefAsValueType<T>> threadLocalStack = ThreadLocalStack;
			if (threadLocalStack != null && threadLocalStack.Count > 0)
			{
				item = threadLocalStack.Pop().Value;
				return true;
			}
			item = default(T);
			return false;
		}
	}
	internal static class AllocFreeConcurrentStack
	{
		[ThreadStatic]
		internal static Dictionary<Type, object>? t_stacks;
	}
	internal sealed class DictionaryEnumerator<TKey, TValue> : IDictionaryEnumerator, IEnumerator where TKey : notnull
	{
		private readonly IEnumerator<KeyValuePair<TKey, TValue>> _inner;

		public DictionaryEntry Entry => new DictionaryEntry(_inner.Current.Key, _inner.Current.Value);

		public object Key => _inner.Current.Key;

		public object? Value => _inner.Current.Value;

		public object Current => Entry;

		internal DictionaryEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> inner)
		{
			Requires.NotNull(inner, "inner");
			_inner = inner;
		}

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

		public void Reset()
		{
			_inner.Reset();
		}
	}
	internal struct DisposableEnumeratorAdapter<T, TEnumerator> : IDisposable where TEnumerator : struct, IEnumerator<T>
	{
		private readonly IEnumerator<T> _enumeratorObject;

		private TEnumerator _enumeratorStruct;

		public T Current
		{
			get
			{
				if (_enumeratorObject == null)
				{
					return _enumeratorStruct.Current;
				}
				return _enumeratorObject.Current;
			}
		}

		internal DisposableEnumeratorAdapter(TEnumerator enumerator)
		{
			_enumeratorStruct = enumerator;
			_enumeratorObject = null;
		}

		internal DisposableEnumeratorAdapter(IEnumerator<T> enumerator)
		{
			_enumeratorStruct = default(TEnumerator);
			_enumeratorObject = enumerator;
		}

		public bool MoveNext()
		{
			if (_enumeratorObject == null)
			{
				return _enumeratorStruct.MoveNext();
			}
			return _enumeratorObject.MoveNext();
		}

		public void Dispose()
		{
			if (_enumeratorObject != null)
			{
				_enumeratorObject.Dispose();
			}
			else
			{
				_enumeratorStruct.Dispose();
			}
		}

		public DisposableEnumeratorAdapter<T, TEnumerator> GetEnumerator()
		{
			return this;
		}
	}
	internal interface IBinaryTree
	{
		int Height { get; }

		bool IsEmpty { get; }

		int Count { get; }

		IBinaryTree? Left { get; }

		IBinaryTree? Right { get; }
	}
	internal interface IBinaryTree<out T> : IBinaryTree
	{
		T Value { get; }

		new IBinaryTree<T>? Left { get; }

		new IBinaryTree<T>? Right { get; }
	}
	internal interface IImmutableArray
	{
		Array? Array { get; }
	}
	public interface IImmutableDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable
	{
		IImmutableDictionary<TKey, TValue> Clear();

		IImmutableDictionary<TKey, TValue> Add(TKey key, TValue value);

		IImmutableDictionary<TKey, TValue> AddRange(IEnumerable<KeyValuePair<TKey, TValue>> pairs);

		IImmutableDictionary<TKey, TValue> SetItem(TKey key, TValue value);

		IImmutableDictionary<TKey, TValue> SetItems(IEnumerable<KeyValuePair<TKey, TValue>> items);

		IImmutableDictionary<TKey, TValue> RemoveRange(IEnumerable<TKey> keys);

		IImmutableDictionary<TKey, TValue> Remove(TKey key);

		bool Contains(KeyValuePair<TKey, TValue> pair);

		bool TryGetKey(TKey equalKey, out TKey actualKey);
	}
	internal interface IImmutableDictionaryInternal<TKey, TValue>
	{
		bool ContainsValue(TValue value);
	}
	public interface IImmutableList<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
	{
		IImmutableList<T> Clear();

		int IndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer);

		int LastIndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer);

		IImmutableList<T> Add(T value);

		IImmutableList<T> AddRange(IEnumerable<T> items);

		IImmutableList<T> Insert(int index, T element);

		IImmutableList<T> InsertRange(int index, IEnumerable<T> items);

		IImmutableList<T> Remove(T value, IEqualityComparer<T>? equalityComparer);

		IImmutableList<T> RemoveAll(Predicate<T> match);

		IImmutableList<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer);

		IImmutableList<T> RemoveRange(int index, int count);

		IImmutableList<T> RemoveAt(int index);

		IImmutableList<T> SetItem(int index, T value);

		IImmutableList<T> Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer);
	}
	internal interface IImmutableListQueries<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
	{
		ImmutableList<TOutput> ConvertAll<TOutput>(Func<T, TOutput> converter);

		void ForEach(Action<T> action);

		ImmutableList<T> GetRange(int index, int count);

		void CopyTo(T[] array);

		void CopyTo(T[] array, int arrayIndex);

		void CopyTo(int index, T[] array, int arrayIndex, int count);

		bool Exists(Predicate<T> match);

		T? Find(Predicate<T> match);

		ImmutableList<T> FindAll(Predicate<T> match);

		int FindIndex(Predicate<T> match);

		int FindIndex(int startIndex, Predicate<T> match);

		int FindIndex(int startIndex, int count, Predicate<T> match);

		T? FindLast(Predicate<T> match);

		int FindLastIndex(Predicate<T> match);

		int FindLastIndex(int startIndex, Predicate<T> match);

		int FindLastIndex(int startIndex, int count, Predicate<T> match);

		bool TrueForAll(Predicate<T> match);

		int BinarySearch(T item);

		int BinarySearch(T item, IComparer<T>? comparer);

		int BinarySearch(int index, int count, T item, IComparer<T>? comparer);
	}
	public interface IImmutableQueue<T> : IEnumerable<T>, IEnumerable
	{
		bool IsEmpty { get; }

		IImmutableQueue<T> Clear();

		T Peek();

		IImmutableQueue<T> Enqueue(T value);

		IImmutableQueue<T> Dequeue();
	}
	public interface IImmutableSet<T> : IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
	{
		IImmutableSet<T> Clear();

		bool Contains(T value);

		IImmutableSet<T> Add(T value);

		IImmutableSet<T> Remove(T value);

		bool TryGetValue(T equalValue, out T actualValue);

		IImmutableSet<T> Intersect(IEnumerable<T> other);

		IImmutableSet<T> Except(IEnumerable<T> other);

		IImmutableSet<T> SymmetricExcept(IEnumerable<T> other);

		IImmutableSet<T> Union(IEnumerable<T> other);

		bool SetEquals(IEnumerable<T> other);

		bool IsProperSubsetOf(IEnumerable<T> other);

		bool IsProperSupersetOf(IEnumerable<T> other);

		bool IsSubsetOf(IEnumerable<T> other);

		bool IsSupersetOf(IEnumerable<T> other);

		bool Overlaps(IEnumerable<T> other);
	}
	public interface IImmutableStack<T> : IEnumerable<T>, IEnumerable
	{
		bool IsEmpty { get; }

		IImmutableStack<T> Clear();

		IImmutableStack<T> Push(T value);

		IImmutableStack<T> Pop();

		T Peek();
	}
	[DebuggerDisplay("Count = {Count}")]
	[DebuggerTypeProxy(typeof(ImmutableEnumerableDebuggerProxy<>))]
	public sealed class ImmutableHashSet<T> : IImmutableSet<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IHashKeyCollection<T>, ICollection<T>, ISet<T>, ICollection, IStrongEnumerable<T, ImmutableHashSet<T>.Enumerator>
	{
		private sealed class HashBucketByValueEqualityComparer : IEqualityComparer<HashBucket>
		{
			private static readonly IEqualityComparer<HashBucket> s_defaultInstance = new HashBucketByValueEqualityComparer(EqualityComparer<T>.Default);

			private readonly IEqualityComparer<T> _valueComparer;

			internal static IEqualityComparer<HashBucket> DefaultInstance => s_defaultInstance;

			internal HashBucketByValueEqualityComparer(IEqualityComparer<T> valueComparer)
			{
				Requires.NotNull(valueComparer, "valueComparer");
				_valueComparer = valueComparer;
			}

			public bool Equals(HashBucket x, HashBucket y)
			{
				return x.EqualsByValue(y, _valueComparer);
			}

			public int GetHashCode(HashBucket obj)
			{
				throw new NotSupportedException();
			}
		}

		private sealed class HashBucketByRefEqualityComparer : IEqualityComparer<HashBucket>
		{
			private static readonly IEqualityComparer<HashBucket> s_defaultInstance = new HashBucketByRefEqualityComparer();

			internal static IEqualityComparer<HashBucket> DefaultInstance => s_defaultInstance;

			private HashBucketByRefEqualityComparer()
			{
			}

			public bool Equals(HashBucket x, HashBucket y)
			{
				return x.EqualsByRef(y);
			}

			public int GetHashCode(HashBucket obj)
			{
				throw new NotSupportedException();
			}
		}

		[DebuggerDisplay("Count = {Count}")]
		public sealed class Builder : IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, ISet<T>, ICollection<T>
		{
			private SortedInt32KeyNode<HashBucket> _root = SortedInt32KeyNode<HashBucket>.EmptyNode;

			private IEqualityComparer<T> _equalityComparer;

			private readonly IEqualityComparer<HashBucket> _hashBucketEqualityComparer;

			private int _count;

			private ImmutableHashSet<T> _immutable;

			private int _version;

			public int Count => _count;

			bool ICollection<T>.IsReadOnly => false;

			public IEqualityComparer<T> KeyComparer
			{
				get
				{
					return _equalityComparer;
				}
				set
				{
					Requires.NotNull(value, "value");
					if (value != _equalityComparer)
					{
						MutationResult mutationResult = ImmutableHashSet<T>.Union((IEnumerable<T>)this, new MutationInput(SortedInt32KeyNode<HashBucket>.EmptyNode, value, _hashBucketEqualityComparer, 0));
						_immutable = null;
						_equalityComparer = value;
						Root = mutationResult.Root;
						_count = mutationResult.Count;
					}
				}
			}

			internal int Version => _version;

			private MutationInput Origin => new MutationInput(Root, _equalityComparer, _hashBucketEqualityComparer, _count);

			private SortedInt32KeyNode<HashBucket> Root
			{
				get
				{
					return _root;
				}
				set
				{
					_version++;
					if (_root != value)
					{
						_root = value;
						_immutable = null;
					}
				}
			}

			internal Builder(ImmutableHashSet<T> set)
			{
				Requires.NotNull(set, "set");
				_root = set._root;
				_count = set._count;
				_equalityComparer = set._equalityComparer;
				_hashBucketEqualityComparer = set._hashBucketEqualityComparer;
				_immutable = set;
			}

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

			public ImmutableHashSet<T> ToImmutable()
			{
				if (_immutable == null)
				{
					_immutable = ImmutableHashSet<T>.Wrap(_root, _equalityComparer, _count);
				}
				return _immutable;
			}

			public bool TryGetValue(T equalValue, out T actualValue)
			{
				int key = ((equalValue != null) ? _equalityComparer.GetHashCode(equalValue) : 0);
				if (_root.TryGetValue(key, out var value))
				{
					return value.TryExchange(equalValue, _equalityComparer, out actualValue);
				}
				actualValue = equalValue;
				return false;
			}

			public bool Add(T item)
			{
				MutationResult result = ImmutableHashSet<T>.Add(item, Origin);
				Apply(result);
				return result.Count != 0;
			}

			public bool Remove(T item)
			{
				MutationResult result = ImmutableHashSet<T>.Remove(item, Origin);
				Apply(result);
				return result.Count != 0;
			}

			public bool Contains(T item)
			{
				return ImmutableHashSet<T>.Contains(item, Origin);
			}

			public void Clear()
			{
				_count = 0;
				Root = SortedInt32KeyNode<HashBucket>.EmptyNode;
			}

			public void ExceptWith(IEnumerable<T> other)
			{
				MutationResult result = ImmutableHashSet<T>.Except(other, _equalityComparer, _hashBucketEqualityComparer, _root);
				Apply(result);
			}

			public void IntersectWith(IEnumerable<T> other)
			{
				MutationResult result = ImmutableHashSet<T>.Intersect(other, Origin);
				Apply(result);
			}

			public bool IsProperSubsetOf(IEnumerable<T> other)
			{
				return ImmutableHashSet<T>.IsProperSubsetOf(other, Origin);
			}

			public bool IsProperSupersetOf(IEnumerable<T> other)
			{
				return ImmutableHashSet<T>.IsProperSupersetOf(other, Origin);
			}

			public bool IsSubsetOf(IEnumerable<T> other)
			{
				return ImmutableHashSet<T>.IsSubsetOf(other, Origin);
			}

			public bool IsSupersetOf(IEnumerable<T> other)
			{
				return ImmutableHashSet<T>.IsSupersetOf(other, Origin);
			}

			public bool Overlaps(IEnumerable<T> other)
			{
				return ImmutableHashSet<T>.Overlaps(other, Origin);
			}

			public bool SetEquals(IEnumerable<T> other)
			{
				if (this == other)
				{
					return true;
				}
				return ImmutableHashSet<T>.SetEquals(other, Origin);
			}

			public void SymmetricExceptWith(IEnumerable<T> other)
			{
				MutationResult result = ImmutableHashSet<T>.SymmetricExcept(other, Origin);
				Apply(result);
			}

			public void UnionWith(IEnumerable<T> other)
			{
				MutationResult result = ImmutableHashSet<T>.Union(other, Origin);
				Apply(result);
			}

			void ICollection<T>.Add(T item)
			{
				Add(item);
			}

			void ICollection<T>.CopyTo(T[] array, int arrayIndex)
			{
				Requires.NotNull(array, "array");
				Requires.Range(arrayIndex >= 0, "arrayIndex");
				Requires.Range(array.Length >= arrayIndex + Count, "arrayIndex");
				using Enumerator enumerator = GetEnumerator();
				while (enumerator.MoveNext())
				{
					T current = enumerator.Current;
					array[arrayIndex++] = current;
				}
			}

			IEnumerator<T> IEnumerable<T>.GetEnumerator()
			{
				return GetEnumerator();
			}

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

			private void Apply(MutationResult result)
			{
				Root = result.Root;
				if (result.CountType == CountType.Adjustment)
				{
					_count += result.Count;
				}
				else
				{
					_count = result.Count;
				}
			}
		}

		public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator, IStrongEnumerator<T>
		{
			private readonly Builder _builder;

			private SortedInt32KeyNode<HashBucket>.Enumerator _mapEnumerator;

			private HashBucket.Enumerator _bucketEnumerator;

			private int _enumeratingBuilderVersion;

			public T Current
			{
				get
				{
					_mapEnumerator.ThrowIfDisposed();
					return _bucketEnumerator.Current;
				}
			}

			object? IEnumerator.Current => Current;

			internal Enumerator(SortedInt32KeyNode<HashBucket> root, Builder? builder = null)
			{
				_builder = builder;
				_mapEnumerator = new SortedInt32KeyNode<HashBucket>.Enumerator(root);
				_bucketEnumerator = default(HashBucket.Enumerator);
				_enumeratingBuilderVersion = builder?.Version ?? (-1);
			}

			public bool MoveNext()
			{
				ThrowIfChanged();
				if (_bucketEnumerator.MoveNext())
				{
					return true;
				}
				if (_mapEnumerator.MoveNext())
				{
					_bucketEnumerator = new HashBucket.Enumerator(_mapEnumerator.Current.Value);
					return _bucketEnumerator.MoveNext();
				}
				return false;
			}

			public void Reset()
			{
				_enumeratingBuilderVersion = ((_builder != null) ? _builder.Version : (-1));
				_mapEnumerator.Reset();
				_bucketEnumerator.Dispose();
				_bucketEnumerator = default(HashBucket.Enumerator);
			}

			public void Dispose()
			{
				_mapEnumerator.Dispose();
				_bucketEnumerator.Dispose();
			}

			private void ThrowIfChanged()
			{
				if (_builder != null && _builder.Version != _enumeratingBuilderVersion)
				{
					throw new InvalidOperationException(System.SR.CollectionModifiedDuringEnumeration);
				}
			}
		}

		internal enum OperationResult
		{
			SizeChanged,
			NoChangeRequired
		}

		internal readonly struct HashBucket
		{
			internal struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
			{
				private enum Position
				{
					BeforeFirst,
					First,
					Additional,
					End
				}

				private readonly HashBucket _bucket;

				private bool _disposed;

				private Position _currentPosition;

				private ImmutableList<T>.Enumerator _additionalEnumerator;

				object? IEnumerator.Current => Current;

				public T Current
				{
					get
					{
						ThrowIfDisposed();
						return _currentPosition switch
						{
							Position.First => _bucket._firstValue, 
							Position.Additional => _additionalEnumerator.Current, 
							_ => throw new InvalidOperationException(), 
						};
					}
				}

				internal Enumerator(HashBucket bucket)
				{
					_disposed = false;
					_bucket = bucket;
					_currentPosition = Position.BeforeFirst;
					_additionalEnumerator = default(ImmutableList<T>.Enumerator);
				}

				public bool MoveNext()
				{
					ThrowIfDisposed();
					if (_bucket.IsEmpty)
					{
						_currentPosition = Position.End;
						return false;
					}
					switch (_currentPosition)
					{
					case Position.BeforeFirst:
						_currentPosition = Position.First;
						return true;
					case Position.First:
						if (_bucket._additionalElements.IsEmpty)
						{
							_currentPosition = Position.End;
							return false;
						}
						_currentPosition = Position.Additional;
						_additionalEnumerator = new ImmutableList<T>.Enumerator(_bucket._additionalElements);
						return _additionalEnumerator.MoveNext();
					case Position.Additional:
						return _additionalEnumerator.MoveNext();
					case Position.End:
						return false;
					default:
						throw new InvalidOperationException();
					}
				}

				public void Reset()
				{
					ThrowIfDisposed();
					_additionalEnumerator.Dispose();
					_currentPosition = Position.BeforeFirst;
				}

				public void Dispose()
				{
					_disposed = true;
					_additionalEnumerator.Dispose();
				}

				private void ThrowIfDisposed()
				{
					if (_disposed)
					{
						Requires.FailObjectDisposed(this);
					}
				}
			}

			private readonly T _firstValue;

			private readonly ImmutableList<T>.Node _additionalElements;

			internal bool IsEmpty => _additionalElements == null;

			private HashBucket(T firstElement, ImmutableList<T>.Node additionalElements = null)
			{
				_firstValue = firstElement;
				_additionalElements = additionalElements ?? ImmutableList<T>.Node.EmptyNode;
			}

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

			public override bool Equals(object? obj)
			{
				throw new NotSupportedException();
			}

			public override int GetHashCode()
			{
				throw new NotSupportedException();
			}

			internal bool EqualsByRef(HashBucket other)
			{
				if ((object)_firstValue == (object)other._firstValue)
				{
					return _additionalElements == other._additionalElements;
				}
				return false;
			}

			internal bool EqualsByValue(HashBucket other, IEqualityComparer<T> valueComparer)
			{
				if (valueComparer.Equals(_firstValue, other._firstValue))
				{
					return _additionalElements == other._additionalElements;
				}
				return false;
			}

			internal HashBucket Add(T value, IEqualityComparer<T> valueComparer, out OperationResult result)
			{
				if (IsEmpty)
				{
					result = OperationResult.SizeChanged;
					return new HashBucket(value);
				}
				if (valueComparer.Equals(value, _firstValue) || _additionalElements.IndexOf(value, valueComparer) >= 0)
				{
					result = OperationResult.NoChangeRequired;
					return this;
				}
				result = OperationResult.SizeChanged;
				return new HashBucket(_firstValue, _additionalElements.Add(value));
			}

			internal bool Contains(T value, IEqualityComparer<T> valueComparer)
			{
				if (IsEmpty)
				{
					return false;
				}
				if (!valueComparer.Equals(value, _firstValue))
				{
					return _additionalElements.IndexOf(value, valueComparer) >= 0;
				}
				return true;
			}

			internal bool TryExchange(T value, IEqualityComparer<T> valueComparer, out T existingValue)
			{
				if (!IsEmpty)
				{
					if (valueComparer.Equals(value, _firstValue))
					{
						existingValue = _firstValue;
						return true;
					}
					int num = _additionalElements.IndexOf(value, valueComparer);
					if (num >= 0)
					{
						existingValue = _additionalElements.ItemRef(num);
						return true;
					}
				}
				existingValue = value;
				return false;
			}

			internal HashBucket Remove(T value, IEqualityComparer<T> equalityComparer, out OperationResult result)
			{
				if (IsEmpty)
				{
					result = OperationResult.NoChangeRequired;
					return this;
				}
				if (equalityComparer.Equals(_firstValue, value))
				{
					if (_additionalElements.IsEmpty)
					{
						result = OperationResult.SizeChanged;
						return default(HashBucket);
					}
					int count = _additionalElements.Left.Count;
					result = OperationResult.SizeChanged;
					return new HashBucket(_additionalElements.Key, _additionalElements.RemoveAt(count));
				}
				int num = _additionalElements.IndexOf(value, equalityComparer);
				if (num < 0)
				{
					result = OperationResult.NoChangeRequired;
					return this;
				}
				result = OperationResult.SizeChanged;
				return new HashBucket(_firstValue, _additionalElements.RemoveAt(num));
			}

			internal void Freeze()
			{
				if (_additionalElements != null)
				{
					_additionalElements.Freeze();
				}
			}
		}

		private readonly struct MutationInput
		{
			private readonly SortedInt32KeyNode<HashBucket> _root;

			private readonly IEqualityComparer<T> _equalityComparer;

			private readonly int _count;

			private readonly IEqualityComparer<HashBucket> _hashBucketEqualityComparer;

			internal SortedInt32KeyNode<HashBucket> Root => _root;

			internal IEqualityComparer<T> EqualityComparer => _equalityComparer;

			internal int Count => _count;

			internal IEqualityComparer<HashBucket> HashBucketEqualityComparer => _hashBucketEqualityComparer;

			internal MutationInput(ImmutableHashSet<T> set)
			{
				Requires.NotNull(set, "set");
				_root = set._root;
				_equalityComparer = set._equalityComparer;
				_count = set._count;
				_hashBucketEqualityComparer = set._hashBucketEqualityComparer;
			}

			internal MutationInput(SortedInt32KeyNode<HashBucket> root, IEqualityComparer<T> equalityComparer, IEqualityComparer<HashBucket> hashBucketEqualityComparer, int count)
			{
				Requires.NotNull(root, "root");
				Requires.NotNull(equalityComparer, "equalityComparer");
				Requires.Range(count >= 0, "count");
				Requires.NotNull(hashBucketEqualityComparer, "hashBucketEqualityComparer");
				_root = root;
				_equalityComparer = equalityComparer;
				_count = count;
				_hashBucketEqualityComparer = hashBucketEqualityComparer;
			}
		}

		private enum CountType
		{
			Adjustment,
			FinalValue
		}

		private readonly struct MutationResult
		{
			private readonly SortedInt32KeyNode<HashBucket> _root;

			private readonly int _count;

			private readonly CountType _countType;

			internal SortedInt32KeyNode<HashBucket> Root => _root;

			internal int Count => _count;

			internal CountType CountType => _countType;

			internal MutationResult(SortedInt32KeyNode<HashBucket> root, int count, CountType countType = CountType.Adjustment)
			{
				Requires.NotNull(root, "root");
				_root = root;
				_count = count;
				_countType = countType;
			}

			internal ImmutableHashSet<T> Finalize(ImmutableHashSet<T> priorSet)
			{
				Requires.NotNull(priorSet, "priorSet");
				int num = Count;
				if (CountType == CountType.Adjustment)
				{
					num += priorSet._count;
				}
				return priorSet.Wrap(Root, num);
			}
		}

		private readonly struct NodeEnumerable : IEnumerable<T>, IEnumerable
		{
			private readonly SortedInt32KeyNode<HashBucket> _root;

			internal NodeEnumerable(SortedInt32KeyNode<HashBucket> root)
			{
				Requires.NotNull(root, "root");
				_root = root;
			}

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

			[ExcludeFromCodeCoverage]
			IEnumerator<T> IEnumerable<T>.GetEnumerator()
			{
				return GetEnumerator();
			}

			[ExcludeFromCodeCoverage]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return GetEnumerator();
			}
		}

		public static readonly ImmutableHashSet<T> Empty = new ImmutableHashSet<T>(SortedInt32KeyNode<HashBucket>.EmptyNode, EqualityComparer<T>.Default, 0);

		private static readonly Action<KeyValuePair<int, HashBucket>> s_FreezeBucketAction = delegate(KeyValuePair<int, HashBucket> kv)
		{
			kv.Value.Freeze();
		};

		private readonly IEqualityComparer<T> _equalityComparer;

		private readonly int _count;

		private readonly SortedInt32KeyNode<HashBucket> _root;

		private readonly IEqualityComparer<HashBucket> _hashBucketEqualityComparer;

		public int Count => _count;

		public bool IsEmpty => Count == 0;

		public IEqualityComparer<T> KeyComparer => _equalityComparer;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		object ICollection.SyncRoot => this;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		bool ICollection.IsSynchronized => true;

		internal IBinaryTree Root => _root;

		private MutationInput Origin => new MutationInput(this);

		bool ICollection<T>.IsReadOnly => true;

		internal ImmutableHashSet(IEqualityComparer<T> equalityComparer)
			: this(SortedInt32KeyNode<HashBucket>.EmptyNode, equalityComparer, 0)
		{
		}

		private ImmutableHashSet(SortedInt32KeyNode<HashBucket> root, IEqualityComparer<T> equalityComparer, int count)
		{
			Requires.NotNull(root, "root");
			Requires.NotNull(equalityComparer, "equalityComparer");
			root.Freeze(s_FreezeBucketAction);
			_root = root;
			_count = count;
			_equalityComparer = equalityComparer;
			_hashBucketEqualityComparer = GetHashBucketEqualityComparer(equalityComparer);
		}

		public ImmutableHashSet<T> Clear()
		{
			if (!IsEmpty)
			{
				return Empty.WithComparer(_equalityComparer);
			}
			return this;
		}

		IImmutableSet<T> IImmutableSet<T>.Clear()
		{
			return Clear();
		}

		public Builder ToBuilder()
		{
			return new Builder(this);
		}

		public ImmutableHashSet<T> Add(T item)
		{
			return Add(item, Origin).Finalize(this);
		}

		public ImmutableHashSet<T> Remove(T item)
		{
			return Remove(item, Origin).Finalize(this);
		}

		public bool TryGetValue(T equalValue, out T actualValue)
		{
			int key = ((equalValue != null) ? _equalityComparer.GetHashCode(equalValue) : 0);
			if (_root.TryGetValue(key, out var value))
			{
				return value.TryExchange(equalValue, _equalityComparer, out actualValue);
			}
			actualValue = equalValue;
			return false;
		}

		public ImmutableHashSet<T> Union(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return Union(other, avoidWithComparer: false);
		}

		public ImmutableHashSet<T> Intersect(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return Intersect(other, Origin).Finalize(this);
		}

		public ImmutableHashSet<T> Except(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return Except(other, _equalityComparer, _hashBucketEqualityComparer, _root).Finalize(this);
		}

		public ImmutableHashSet<T> SymmetricExcept(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return SymmetricExcept(other, Origin).Finalize(this);
		}

		public bool SetEquals(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			if (this == other)
			{
				return true;
			}
			return SetEquals(other, Origin);
		}

		public bool IsProperSubsetOf(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return IsProperSubsetOf(other, Origin);
		}

		public bool IsProperSupersetOf(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return IsProperSupersetOf(other, Origin);
		}

		public bool IsSubsetOf(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return IsSubsetOf(other, Origin);
		}

		public bool IsSupersetOf(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return IsSupersetOf(other, Origin);
		}

		public bool Overlaps(IEnumerable<T> other)
		{
			Requires.NotNull(other, "other");
			return Overlaps(other, Origin);
		}

		IImmutableSet<T> IImmutableSet<T>.Add(T item)
		{
			return Add(item);
		}

		IImmutableSet<T> IImmutableSet<T>.Remove(T item)
		{
			return Remove(item);
		}

		IImmutableSet<T> IImmutableSet<T>.Union(IEnumerable<T> other)
		{
			return Union(other);
		}

		IImmutableSet<T> IImmutableSet<T>.Intersect(IEnumerable<T> other)
		{
			return Intersect(other);
		}

		IImmutableSet<T> IImmutableSet<T>.Except(IEnumerable<T> other)
		{
			return Except(other);
		}

		IImmutableSet<T> IImmutableSet<T>.SymmetricExcept(IEnumerable<T> other)
		{
			return SymmetricExcept(other);
		}

		public bool Contains(T item)
		{
			return Contains(item, Origin);
		}

		public ImmutableHashSet<T> WithComparer(IEqualityComparer<T>? equalityComparer)
		{
			if (equalityComparer == null)
			{
				equalityComparer = EqualityComparer<T>.Default;
			}
			if (equalityComparer == _equalityComparer)
			{
				return this;
			}
			ImmutableHashSet<T> immutableHashSet = new ImmutableHashSet<T>(equalityComparer);
			return immutableHashSet.Union(this, avoidWithComparer: true);
		}

		bool ISet<T>.Add(T item)
		{
			throw new NotSupportedException();
		}

		void ISet<T>.ExceptWith(IEnumerable<T> other)
		{
			throw new NotSupportedException();
		}

		void ISet<T>.IntersectWith(IEnumerable<T> other)
		{
			throw new NotSupportedException();
		}

		void ISet<T>.SymmetricExceptWith(IEnumerable<T> other)
		{
			throw new NotSupportedException();
		}

		void ISet<T>.UnionWith(IEnumerable<T> other)
		{
			throw new NotSupportedException();
		}

		void ICollection<T>.CopyTo(T[] array, int arrayIndex)
		{
			Requires.NotNull(array, "array");
			Requires.Range(arrayIndex >= 0, "arrayIndex");
			Requires.Range(array.Length >= arrayIndex + Count, "arrayIndex");
			using Enumerator enumerator = GetEnumerator();
			while (enumerator.MoveNext())
			{
				T current = enumerator.Current;
				array[arrayIndex++] = current;
			}
		}

		void ICollection<T>.Add(T item)
		{
			throw new NotSupportedException();
		}

		void ICollection<T>.Clear()
		{
			throw new NotSupportedException();
		}

		bool ICollection<T>.Remove(T item)
		{
			throw new NotSupportedException();
		}

		void ICollection.CopyTo(Array array, int arrayIndex)
		{
			Requires.NotNull(array, "array");
			Requires.Range(arrayIndex >= 0, "arrayIndex");
			Requires.Range(array.Length >= arrayIndex + Count, "arrayIndex");
			using Enumerator enumerator = GetEnumerator();
			while (enumerator.MoveNext())
			{
				T current = enumerator.Current;
				array.SetValue(current, arrayIndex++);
			}
		}

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

		IEnumerator<T> IEnumerable<T>.GetEnumerator()
		{
			if (!IsEmpty)
			{
				return GetEnumerator();
			}
			return Enumerable.Empty<T>().GetEnumerator();
		}

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

		private static bool IsSupersetOf(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			foreach (T item in other.GetEnumerableDisposable<T, Enumerator>())
			{
				if (!Contains(item, origin))
				{
					return false;
				}
			}
			return true;
		}

		private static MutationResult Add(T item, MutationInput origin)
		{
			int num = ((item != null) ? origin.EqualityComparer.GetHashCode(item) : 0);
			OperationResult result;
			HashBucket newBucket = origin.Root.GetValueOrDefault(num).Add(item, origin.EqualityComparer, out result);
			if (result == OperationResult.NoChangeRequired)
			{
				return new MutationResult(origin.Root, 0);
			}
			SortedInt32KeyNode<HashBucket> root = UpdateRoot(origin.Root, num, origin.HashBucketEqualityComparer, newBucket);
			return new MutationResult(root, 1);
		}

		private static MutationResult Remove(T item, MutationInput origin)
		{
			OperationResult result = OperationResult.NoChangeRequired;
			int num = ((item != null) ? origin.EqualityComparer.GetHashCode(item) : 0);
			SortedInt32KeyNode<HashBucket> root = origin.Root;
			if (origin.Root.TryGetValue(num, out var value))
			{
				HashBucket newBucket = value.Remove(item, origin.EqualityComparer, out result);
				if (result == OperationResult.NoChangeRequired)
				{
					return new MutationResult(origin.Root, 0);
				}
				root = UpdateRoot(origin.Root, num, origin.HashBucketEqualityComparer, newBucket);
			}
			return new MutationResult(root, (result == OperationResult.SizeChanged) ? (-1) : 0);
		}

		private static bool Contains(T item, MutationInput origin)
		{
			int key = ((item != null) ? origin.EqualityComparer.GetHashCode(item) : 0);
			if (origin.Root.TryGetValue(key, out var value))
			{
				return value.Contains(item, origin.EqualityComparer);
			}
			return false;
		}

		private static MutationResult Union(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			int num = 0;
			SortedInt32KeyNode<HashBucket> sortedInt32KeyNode = origin.Root;
			foreach (T item in other.GetEnumerableDisposable<T, Enumerator>())
			{
				int num2 = ((item != null) ? origin.EqualityComparer.GetHashCode(item) : 0);
				OperationResult result;
				HashBucket newBucket = sortedInt32KeyNode.GetValueOrDefault(num2).Add(item, origin.EqualityComparer, out result);
				if (result == OperationResult.SizeChanged)
				{
					sortedInt32KeyNode = UpdateRoot(sortedInt32KeyNode, num2, origin.HashBucketEqualityComparer, newBucket);
					num++;
				}
			}
			return new MutationResult(sortedInt32KeyNode, num);
		}

		private static bool Overlaps(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			if (origin.Root.IsEmpty)
			{
				return false;
			}
			foreach (T item in other.GetEnumerableDisposable<T, Enumerator>())
			{
				if (Contains(item, origin))
				{
					return true;
				}
			}
			return false;
		}

		private static bool SetEquals(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			HashSet<T> hashSet = new HashSet<T>(other, origin.EqualityComparer);
			if (origin.Count != hashSet.Count)
			{
				return false;
			}
			foreach (T item in hashSet)
			{
				if (!Contains(item, origin))
				{
					return false;
				}
			}
			return true;
		}

		private static SortedInt32KeyNode<HashBucket> UpdateRoot(SortedInt32KeyNode<HashBucket> root, int hashCode, IEqualityComparer<HashBucket> hashBucketEqualityComparer, HashBucket newBucket)
		{
			bool mutated;
			if (newBucket.IsEmpty)
			{
				return root.Remove(hashCode, out mutated);
			}
			bool replacedExistingValue;
			return root.SetItem(hashCode, newBucket, hashBucketEqualityComparer, out replacedExistingValue, out mutated);
		}

		private static MutationResult Intersect(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			SortedInt32KeyNode<HashBucket> root = SortedInt32KeyNode<HashBucket>.EmptyNode;
			int num = 0;
			foreach (T item in other.GetEnumerableDisposable<T, Enumerator>())
			{
				if (Contains(item, origin))
				{
					MutationResult mutationResult = Add(item, new MutationInput(root, origin.EqualityComparer, origin.HashBucketEqualityComparer, num));
					root = mutationResult.Root;
					num += mutationResult.Count;
				}
			}
			return new MutationResult(root, num, CountType.FinalValue);
		}

		private static MutationResult Except(IEnumerable<T> other, IEqualityComparer<T> equalityComparer, IEqualityComparer<HashBucket> hashBucketEqualityComparer, SortedInt32KeyNode<HashBucket> root)
		{
			Requires.NotNull(other, "other");
			Requires.NotNull(equalityComparer, "equalityComparer");
			Requires.NotNull(root, "root");
			int num = 0;
			SortedInt32KeyNode<HashBucket> sortedInt32KeyNode = root;
			foreach (T item in other.GetEnumerableDisposable<T, Enumerator>())
			{
				int num2 = ((item != null) ? equalityComparer.GetHashCode(item) : 0);
				if (sortedInt32KeyNode.TryGetValue(num2, out var value))
				{
					OperationResult result;
					HashBucket newBucket = value.Remove(item, equalityComparer, out result);
					if (result == OperationResult.SizeChanged)
					{
						num--;
						sortedInt32KeyNode = UpdateRoot(sortedInt32KeyNode, num2, hashBucketEqualityComparer, newBucket);
					}
				}
			}
			return new MutationResult(sortedInt32KeyNode, num);
		}

		private static MutationResult SymmetricExcept(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			ImmutableHashSet<T> immutableHashSet = ImmutableHashSet.CreateRange(origin.EqualityComparer, other);
			int num = 0;
			SortedInt32KeyNode<HashBucket> root = SortedInt32KeyNode<HashBucket>.EmptyNode;
			foreach (T item in new NodeEnumerable(origin.Root))
			{
				if (!immutableHashSet.Contains(item))
				{
					MutationResult mutationResult = Add(item, new MutationInput(root, origin.EqualityComparer, origin.HashBucketEqualityComparer, num));
					root = mutationResult.Root;
					num += mutationResult.Count;
				}
			}
			foreach (T item2 in immutableHashSet)
			{
				if (!Contains(item2, origin))
				{
					MutationResult mutationResult2 = Add(item2, new MutationInput(root, origin.EqualityComparer, origin.HashBucketEqualityComparer, num));
					root = mutationResult2.Root;
					num += mutationResult2.Count;
				}
			}
			return new MutationResult(root, num, CountType.FinalValue);
		}

		private static bool IsProperSubsetOf(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			if (origin.Root.IsEmpty)
			{
				return other.Any();
			}
			HashSet<T> hashSet = new HashSet<T>(other, origin.EqualityComparer);
			if (origin.Count >= hashSet.Count)
			{
				return false;
			}
			int num = 0;
			bool flag = false;
			foreach (T item in hashSet)
			{
				if (Contains(item, origin))
				{
					num++;
				}
				else
				{
					flag = true;
				}
				if (num == origin.Count && flag)
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsProperSupersetOf(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			if (origin.Root.IsEmpty)
			{
				return false;
			}
			int num = 0;
			foreach (T item in other.GetEnumerableDisposable<T, Enumerator>())
			{
				num++;
				if (!Contains(item, origin))
				{
					return false;
				}
			}
			return origin.Count > num;
		}

		private static bool IsSubsetOf(IEnumerable<T> other, MutationInput origin)
		{
			Requires.NotNull(other, "other");
			if (origin.Root.IsEmpty)
			{
				return true;
			}
			HashSet<T> hashSet = new HashSet<T>(other, origin.EqualityComparer);
			int num = 0;
			foreach (T item in hashSet)
			{
				if (Contains(item, origin))
				{
					num++;
				}
			}
			return num == origin.Count;
		}

		private static ImmutableHashSet<T> Wrap(SortedInt32KeyNode<HashBucket> root, IEqualityComparer<T> equalityComparer, int count)
		{
			Requires.NotNull(root, "root");
			Requires.NotNull(equalityComparer, "equalityComparer");
			Requires.Range(count >= 0, "count");
			return new ImmutableHashSet<T>(root, equalityComparer, count);
		}

		private static IEqualityComparer<HashBucket> GetHashBucketEqualityComparer(IEqualityComparer<T> valueComparer)
		{
			if (!ImmutableExtensions.IsValueType<T>())
			{
				return HashBucketByRefEqualityComparer.DefaultInstance;
			}
			if (valueComparer == EqualityComparer<T>.Default)
			{
				return HashBucketByValueEqualityComparer.DefaultInstance;
			}
			return new HashBucketByValueEqualityComparer(valueComparer);
		}

		private ImmutableHashSet<T> Wrap(SortedInt32KeyNode<HashBucket> root, int adjustedCountIfDifferentRoot)
		{
			if (root == _root)
			{
				return this;
			}
			return new ImmutableHashSet<T>(root, _equalityComparer, adjustedCountIfDifferentRoot);
		}

		private ImmutableHashSet<T> Union(IEnumerable<T> items, bool avoidWithComparer)
		{
			Requires.NotNull(items, "items");
			if (IsEmpty && !avoidWithComparer && items is ImmutableHashSet<T> immutableHashSet)
			{
				return immutableHashSet.WithComparer(KeyComparer);
			}
			return Union(items, Origin).Finalize(this);
		}
	}
	internal interface IStrongEnumerable<out T, TEnumerator> where TEnumerator : struct, IStrongEnumerator<T>
	{
		TEnumerator GetEnumerator();
	}
	internal interface IStrongEnumerator<T>
	{
		T Current { get; }

		bool MoveNext();
	}
	internal interface IOrderedCollection<out T> : IEnumerable<T>, IEnumerable
	{
		int Count { get; }

		T this[int index] { get; }
	}
	public static class ImmutableArray
	{
		internal static readonly byte[] TwoElementArray = new byte[2];

		public static ImmutableArray<T> Create<T>()
		{
			return ImmutableArray<T>.Empty;
		}

		public static ImmutableArray<T> Create<T>(T item)
		{
			T[] items = new T[1] { item };
			return new ImmutableArray<T>(items);
		}

		public static ImmutableArray<T> Create<T>(T item1, T item2)
		{
			T[] items = new T[2] { item1, item2 };
			return new ImmutableArray<T>(items);
		}

		public static ImmutableArray<T> Create<T>(T item1, T item2, T item3)
		{
			T[] items = new T[3] { item1, item2, item3 };
			return new ImmutableArray<T>(items);
		}

		public static ImmutableArray<T> Create<T>(T item1, T item2, T item3, T item4)
		{
			T[] items = new T[4] { item1, item2, item3, item4 };
			return new ImmutableArray<T>(items);
		}

		public static ImmutableArray<T> CreateRange<T>(IEnumerable<T> items)
		{
			Requires.NotNull(items, "items");
			if (items is IImmutableArray immutableArray)
			{
				Array array = immutableArray.Array;
				if (array == null)
				{
					throw new InvalidOperationException(System.SR.InvalidOperationOnDefaultArray);
				}
				return new ImmutableArray<T>((T[])array);
			}
			if (items.TryGetCount(out var count))
			{
				return new ImmutableArray<T>(items.ToArray(count));
			}
			return new ImmutableArray<T>(items.ToArray());
		}

		public static ImmutableArray<T> Create<T>(params T[]? items)
		{
			if (items == null || items.Length == 0)
			{
				return ImmutableArray<T>.Empty;
			}
			T[] array = new T[items.Length];
			Array.Copy(items, array, items.Length);
			return new ImmutableArray<T>(array);
		}

		public static ImmutableArray<T> Create<T>(T[] items, int start, int length)
		{
			Requires.NotNull(items, "items");
			Requires.Range(start >= 0 && start <= items.Length, "start");
			Requires.Range(length >= 0 && start + length <= items.Length, "length");
			if (length == 0)
			{
				return Create<T>();
			}
			T[] array = new T[length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = items[start + i];
			}
			return new ImmutableArray<T>(array);
		}

		public static ImmutableArray<T> Create<T>(ImmutableArray<T> items, int start, int length)
		{
			Requires.Range(start >= 0 && start <= items.Length, "start");
			Requires.Range(length >= 0 && start + length <= items.Length, "length");
			if (length == 0)
			{
				return Create<T>();
			}
			if (start == 0 && length == items.Length)
			{
				return items;
			}
			T[] array = new T[length];
			Array.Copy(items.array, start, array, 0, length);
			return new ImmutableArray<T>(array);
		}

		public static ImmutableArray<TResult> CreateRange<TSource, TResult>(ImmutableArray<TSource> items, Func<TSource, TResult> selector)
		{
			Requires.NotNull(selector, "selector");
			int length = items.Length;
			if (length == 0)
			{
				return Create<TResult>();
			}
			TResult[] array = new TResult[length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = selector(items[i]);
			}
			return new ImmutableArray<TResult>(array);
		}

		public static ImmutableArray<TResult> CreateRange<TSource, TResult>(ImmutableArray<TSource> items, int start, int length, Func<TSource, TResult> selector)
		{
			int length2 = items.Length;
			Requires.Range(start >= 0 && start <= length2, "start");
			Requires.Range(length >= 0 && start + length <= length2, "length");
			Requires.NotNull(selector, "selector");
			if (length == 0)
			{
				return Create<TResult>();
			}
			TResult[] array = new TResult[length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = selector(items[i + start]);
			}
			return new ImmutableArray<TResult>(array);
		}

		public static ImmutableArray<TResult> CreateRange<TSource, TArg, TResult>(ImmutableArray<TSource> items, Func<TSource, TArg, TResult> selector, TArg arg)
		{
			Requires.NotNull(selector, "selector");
			int length = items.Length;
			if (length == 0)
			{
				return Create<TResult>();
			}
			TResult[] array = new TResult[length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = selector(items[i], arg);
			}
			return new ImmutableArray<TResult>(array);
		}

		public static ImmutableArray<TResult> CreateRange<TSource, TArg, TResult>(ImmutableArray<TSource> items, int start, int length, Func<TSource, TArg, TResult> selector, TArg arg)
		{
			int length2 = items.Length;
			Requires.Range(start >= 0 && start <= length2, "start");
			Requires.Range(length >= 0 && start + length <= length2, "length");
			Requires.NotNull(selector, "selector");
			if (length == 0)
			{
				return Create<TResult>();
			}
			TResult[] array = new TResult[length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = selector(items[i + start], arg);
			}
			return new ImmutableArray<TResult>(array);
		}

		public static ImmutableArray<T>.Builder CreateBuilder<T>()
		{
			return Create<T>().ToBuilder();
		}

		public static ImmutableArray<T>.Builder CreateBuilder<T>(int initialCapacity)
		{
			return new ImmutableArray<T>.Builder(initialCapacity);
		}

		public static ImmutableArray<TSource> ToImmutableArray<TSource>(this IEnumerable<TSource> items)
		{
			if (items is ImmutableArray<TSource>)
			{
				return (ImmutableArray<TSource>)(object)items;
			}
			return CreateRange(items);
		}

		public static ImmutableArray<TSource> ToImmutableArray<TSource>(this ImmutableArray<TSource>.Builder builder)
		{
			Requires.NotNull(builder, "builder");
			return builder.ToImmutable();
		}

		public static int BinarySearch<T>(this ImmutableArray<T> array, T value)
		{
			return Array.BinarySearch(array.array, value);
		}

		public static int BinarySearch<T>(this ImmutableArray<T> array, T value, IComparer<T>? comparer)
		{
			return Array.BinarySearch(array.array, value, comparer);
		}

		public static int BinarySearch<T>(this ImmutableArray<T> array, int index, int length, T value)
		{
			return Array.BinarySearch(array.array, index, length, value);
		}

		public static int BinarySearch<T>(this ImmutableArray<T> array, int index, int length, T value, IComparer<T>? comparer)
		{
			return Array.BinarySearch(array.array, index, length, value, comparer);
		}
	}
	[DebuggerDisplay("{DebuggerDisplay,nq}")]
	[System.Runtime.Versioning.NonVersionable]
	public readonly struct ImmutableArray<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IList<T>, ICollection<T>, IEquatable<ImmutableArray<T>>, IList, ICollection, IImmutableArray, IStructuralComparable, IStructuralEquatable, IImmutableList<T>
	{
		[DebuggerDisplay("Count = {Count}")]
		[DebuggerTypeProxy(typeof(ImmutableArrayBuilderDebuggerProxy<>))]
		public sealed class Builder : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IReadOnlyList<T>, IReadOnlyCollection<T>
		{
			private T[] _elements;

			private int _count;

			public int Capacity
			{
				get
				{
					return _elements.Length;
				}
				set
				{
					if (value < _count)
					{
						throw new ArgumentException(System.SR.CapacityMustBeGreaterThanOrEqualToCount, "value");
					}
					if (value == _elements.Length)
					{
						return;
					}
					if (value > 0)
					{
						T[] array = new T[value];
						if (_count > 0)
						{
							Array.Copy(_elements, array, _count);
						}
						_elements = array;
					}
					else
					{
						_elements = ImmutableArray<T>.Empty.array;
					}
				}
			}

			public int Count
			{
				get
				{
					return _count;
				}
				set
				{
					Requires.Range(value >= 0, "value");
					if (value < _count)
					{
						if (_count - value > 64)
						{
							Array.Clear(_elements, value, _count - value);
						}
						else
						{
							for (int i = value; i < Count; i++)
							{
								_elements[i] = default(T);
							}
						}
					}
					else if (value > _count)
					{
						EnsureCapacity(value);
					}
					_count = value;
				}
			}

			public T this[int index]
			{
				get
				{
					if (index >= Count)
					{
						ThrowIndexOutOfRangeException();
					}
					return _elements[index];
				}
				set
				{
					if (index >= Count)
					{
						ThrowIndexOutOfRangeException();
					}
					_elements[index] = value;
				}
			}

			bool ICollection<T>.IsReadOnly => false;

			internal Builder(int capacity)
			{
				Requires.Range(capacity >= 0, "capacity");
				_elements = new T[capacity];
				_count = 0;
			}

			internal Builder()
				: this(8)
			{
			}

			private static void ThrowIndexOutOfRangeException()
			{
				throw new IndexOutOfRangeException();
			}

			public ref readonly T ItemRef(int index)
			{
				if (index >= Count)
				{
					ThrowIndexOutOfRangeException();
				}
				return ref _elements[index];
			}

			public ImmutableArray<T> ToImmutable()
			{
				return new ImmutableArray<T>(ToArray());
			}

			public ImmutableArray<T> MoveToImmutable()
			{
				if (Capacity != Count)
				{
					throw new InvalidOperationException(System.SR.CapacityMustEqualCountOnMove);
				}
				T[] elements = _elements;
				_elements = ImmutableArray<T>.Empty.array;
				_count = 0;
				return new ImmutableArray<T>(elements);
			}

			public void Clear()
			{
				Count = 0;
			}

			public void Insert(int index, T item)
			{
				Requires.Range(index >= 0 && index <= Count, "index");
				EnsureCapacity(Count + 1);
				if (index < Count)
				{
					Array.Copy(_elements, index, _elements, index + 1, Count - index);
				}
				_count++;
				_elements[index] = item;
			}

			public void Add(T item)
			{
				int num = _count + 1;
				EnsureCapacity(num);
				_elements[_count] = item;
				_count = num;
			}

			public void AddRange(IEnumerable<T> items)
			{
				Requires.NotNull(items, "items");
				if (items.TryGetCount(out var count))
				{
					EnsureCapacity(Count + count);
					if (items.TryCopyTo(_elements, _count))
					{
						_count += count;
						return;
					}
				}
				foreach (T item in items)
				{
					Add(item);
				}
			}

			public void AddRange(params T[] items)
			{
				Requires.NotNull(items, "items");
				int count = Count;
				Count += items.Length;
				Array.Copy(items, 0, _elements, count, items.Length);
			}

			public void AddRange<TDerived>(TDerived[] items) where TDerived : T
			{
				Requires.NotNull(items, "items");
				int count = Count;
				Count += items.Length;
				Array.Copy(items, 0, _elements, count, items.Length);
			}

			public void AddRange(T[] items, int length)
			{
				Requires.NotNull(items, "items");
				Requires.Range(length >= 0 && length <= items.Length, "length");
				int count = Count;
				Count += length;
				Array.Copy(items, 0, _elements, count, length);
			}

			public void AddRange(ImmutableArray<T> items)
			{
				AddRange(items, items.Length);
			}

			public void AddRange(ImmutableArray<T> items, int length)
			{
				Requires.Range(length >= 0, "length");
				if (items.array != null)
				{
					AddRange(items.array, length);
				}
			}

			public void AddRange<TDerived>(ImmutableArray<TDerived> items) where TDerived : T
			{
				if (items.array != null)
				{
					this.AddRange<TDerived>(items.array);
				}
			}

			public void AddRange(Builder items)
			{
				Requires.NotNull(items, "items");
				AddRange(items._elements, items.Count);
			}

			public void AddRange<TDerived>(ImmutableArray<TDerived>.Builder items) where TDerived : T
			{
				Requires.NotNull(items, "items");
				AddRange<TDerived>(items._elements, items.Count);
			}

			public bool Remove(T element)
			{
				int num = IndexOf(element);
				if (num >= 0)
				{
					RemoveAt(num);
					return true;
				}
				return false;
			}

			public void RemoveAt(int index)
			{
				Requires.Range(index >= 0 && index < Count, "index");
				if (index < Count - 1)
				{
					Array.Copy(_elements, index + 1, _elements, index, Count - index - 1);
				}
				Count--;
			}

			public bool Contains(T item)
			{
				return IndexOf(item) >= 0;
			}

			public T[] ToArray()
			{
				if (Count == 0)
				{
					return ImmutableArray<T>.Empty.array;
				}
				T[] array = new T[Count];
				Array.Copy(_elements, array, Count);
				return array;
			}

			public void CopyTo(T[] array, int index)
			{
				Requires.NotNull(array, "array");
				Requires.Range(index >= 0 && index + Count <= array.Length, "index");
				Array.Copy(_elements, 0, array, index, Count);
			}

			private void EnsureCapacity(int capacity)
			{
				if (_elements.Length < capacity)
				{
					int newSize = Math.Max(_elements.Length * 2, capacity);
					Array.Resize(ref _elements, newSize);
				}
			}

			public int IndexOf(T item)
			{
				return IndexOf(item, 0, _count, EqualityComparer<T>.Default);
			}

			public int IndexOf(T item, int startIndex)
			{
				return IndexOf(item, startIndex, Count - startIndex, EqualityComparer<T>.Default);
			}

			public int IndexOf(T item, int startIndex, int count)
			{
				return IndexOf(item, startIndex, count, EqualityComparer<T>.Default);
			}

			public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer)
			{
				if (count == 0 && startIndex == 0)
				{
					return -1;
				}
				Requires.Range(startIndex >= 0 && startIndex < Count, "startIndex");
				Requires.Range(count >= 0 && startIndex + count <= Count, "count");
				equalityComparer = equalityComparer ?? EqualityComparer<T>.Default;
				if (equalityComparer == EqualityComparer<T>.Default)
				{
					return Array.IndexOf(_elements, item, startIndex, count);
				}
				for (int i = startIndex; i < startIndex + count; i++)
				{
					if (equalityComparer.Equals(_elements[i], item))
					{
						return i;
					}
				}
				return -1;
			}

			public int LastIndexOf(T item)
			{
				if (Count == 0)
				{
					return -1;
				}
				return LastIndexOf(item, Count - 1, Count, EqualityComparer<T>.Default);
			}

			public int LastIndexOf(T item, int startIndex)
			{
				if (Count == 0 && startIndex == 0)
				{
					return -1;
				}
				Requires.Range(startIndex >= 0 && startIndex < Count, "startIndex");
				return LastIndexOf(item, startIndex, startIndex + 1, EqualityComparer<T>.Default);
			}

			public int LastIndexOf(T item, int startIndex, int count)
			{
				return LastIndexOf(item, startIndex, count, EqualityComparer<T>.Default);
			}

			public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer)
			{
				if (count == 0 && startIndex == 0)
				{
					return -1;
				}
				Requires.Range(startIndex >= 0 && startIndex < Count, "startIndex");
				Requires.Range(count >= 0 && startIndex - count + 1 >= 0, "count");
				equalityComparer = equalityComparer ?? EqualityComparer<T>.Default;
				if (equalityComparer == EqualityComparer<T>.Default)
				{
					return Array.LastIndexOf(_elements, item, startIndex, count);
				}
				for (int num = startIndex; num >= startIndex - count + 1; num--)
				{
					if (equalityComparer.Equals(item, _elements[num]))
					{
						return num;
					}
				}
				return -1;
			}

			public void Reverse()
			{
				int num = 0;
				int num2 = _count - 1;
				T[] elements = _elements;
				while (num < num2)
				{
					T val = elements[num];
					elements[num] = elements[num2];
					elements[num2] = val;
					num++;
					num2--;
				}
			}

			public void Sort()
			{
				if (Count > 1)
				{
					Array.Sort(_elements, 0, Count, Comparer<T>.Default);
				}
			}

			public void Sort(Comparison<T> comparison)
			{
				Requires.NotNull(comparison, "comparison");
				if (Count > 1)
				{
					Array.Sort(_elements, 0, _count, Comparer<T>.Create(comparison));
				}
			}

			public void Sort(IComparer<T>? comparer)
			{
				if (Count > 1)
				{
					Array.Sort(_elements, 0, _count, comparer);
				}
			}

			public void Sort(int index, int count, IComparer<T>? comparer)
			{
				Requires.Range(index >= 0, "index");
				Requires.Range(count >= 0 && index + count <= Count, "count");
				if (count > 1)
				{
					Array.Sort(_elements, index, count, comparer);
				}
			}

			public IEnumerator<T> GetEnumerator()
			{
				for (int i = 0; i < Count; i++)
				{
					yield return this[i];
				}
			}

			IEnumerator<T> IEnumerable<T>.GetEnumerator()
			{
				return GetEnumerator();
			}

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

			private void AddRange<TDerived>(TDerived[] items, int length) where TDerived : T
			{
				EnsureCapacity(Count + length);
				int count = Count;
				Count += length;
				T[] elements = _elements;
				for (int i = 0; i < length; i++)
				{
					elements[count + i] = (T)(object)items[i];
				}
			}
		}

		public struct Enumerator
		{
			private readonly T[] _array;

			private int _index;

			public T Current => _array[_index];

			internal Enumerator(T[] array)
			{
				_array = array;
				_index = -1;
			}

			public bool MoveNext()
			{
				return ++_index < _array.Length;
			}
		}

		private sealed class EnumeratorObject : IEnumerator<T>, IDisposable, IEnumerator
		{
			private static readonly IEnumerator<T> s_EmptyEnumerator = new EnumeratorObject(ImmutableArray<T>.Empty.array);

			private readonly T[] _array;

			private int _index;

			public T Current
			{
				get
				{
					if ((uint)_index < (uint)_array.Length)
					{
						return _array[_index];
					}
					throw new InvalidOperationException();
				}
			}

			object IEnumerator.Current => Current;

			private EnumeratorObject(T[] array)
			{
				_index = -1;
				_array = array;
			}

			public bool MoveNext()
			{
				int num = _index + 1;
				int num2 = _array.Length;
				if ((uint)num <= (uint)num2)
				{
					_index = num;
					return (uint)num < (uint)num2;
				}
				return false;
			}

			void IEnumerator.Reset()
			{
				_index = -1;
			}

			public void Dispose()
			{
			}

			internal static IEnumerator<T> Create(T[] array)
			{
				if (array.Length != 0)
				{
					return new EnumeratorObject(array);
				}
				return s_EmptyEnumerator;
			}
		}

		public static readonly ImmutableArray<T> Empty = new ImmutableArray<T>(new T[0]);

		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
		internal readonly T[]? array;

		T IList<T>.this[int index]
		{
			get
			{
				ImmutableArray<T> immutableArray = this;
				immutableArray.ThrowInvalidOperationIfNotInitialized();
				return immutableArray[index];
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		bool ICollection<T>.IsReadOnly => true;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		int ICollection<T>.Count
		{
			get
			{
				ImmutableArray<T> immutableArray = this;
				immutableArray.ThrowInvalidOperationIfNotInitialized();
				return immutableArray.Length;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		int IReadOnlyCollection<T>.Count
		{
			get
			{
				ImmutableArray<T> immutableArray = this;
				immutableArray.ThrowInvalidOperationIfNotInitialized();
				return immutableArray.Length;
			}
		}

		T IReadOnlyList<T>.this[int index]
		{
			get
			{
				ImmutableArray<T> immutableArray = this;
				immutableArray.ThrowInvalidOperationIfNotInitialized();
				return immutableArray[index];
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		bool IList.IsFixedSize => true;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		bool IList.IsReadOnly => true;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		int ICollection.Count
		{
			get
			{
				ImmutableArray<T> immutableArray = this;
				immutableArray.ThrowInvalidOperationIfNotInitialized();
				return immutableArray.Length;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		bool ICollection.IsSynchronized => true;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		object ICollection.SyncRoot
		{
			get
			{
				throw new NotSupportedException();
			}
		}

		object? IList.this[int index]
		{
			get
			{
				ImmutableArray<T> immutableArray = this;
				immutableArray.ThrowInvalidOperationIfNotInitialized();
				return immutableArray[index];
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		public T this[int index]
		{
			[System.Runtime.Versioning.NonVersionable]
			get
			{
				return array[index];
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public bool IsEmpty
		{
			[System.Runtime.Versioning.NonVersionable]
			get
			{
				return array.Length == 0;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public int Length
		{
			[System.Runtime.Versioning.NonVersionable]
			get
			{
				return array.Length;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public bool IsDefault => array == null;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public bool IsDefaultOrEmpty
		{
			get
			{
				ImmutableArray<T> immutableArray = this;
				if (immutableArray.array != null)
				{
					return immutableArray.array.Length == 0;
				}
				return true;
			}
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		Array? IImmutableArray.Array => array;

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private string DebuggerDisplay
		{
			get
			{
				ImmutableArray<T> immutableArray = this;
				if (!immutableArray.IsDefault)
				{
					return $"Length = {immutableArray.Length}";
				}
				return "Uninitialized";
			}
		}

		public ReadOnlySpan<T> AsSpan()
		{
			return new ReadOnlySpan<T>(array);
		}

		public ReadOnlyMemory<T> AsMemory()
		{
			return new ReadOnlyMemory<T>(array);
		}

		public int IndexOf(T item)
		{
			ImmutableArray<T> immutableArray = this;
			return immutableArray.IndexOf(item, 0, immutableArray.Length, EqualityComparer<T>.Default);
		}

		public int IndexOf(T item, int startIndex, IEqualityComparer<T>? equalityComparer)
		{
			ImmutableArray<T> immutableArray = this;
			return immutableArray.IndexOf(item, startIndex, immutableArray.Length - startIndex, equalityComparer);
		}

		public int IndexOf(T item, int startIndex)
		{
			ImmutableArray<T> immutableArray = this;
			return immutableArray.IndexOf(item, startIndex, immutableArray.Length - startIndex, EqualityComparer<T>.Default);
		}

		public int IndexOf(T item, int startIndex, int count)
		{
			return IndexOf(item, startIndex, count, EqualityComparer<T>.Default);
		}

		public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowNullRefIfNotInitialized();
			if (count == 0 && startIndex == 0)
			{
				return -1;
			}
			Requires.Range(startIndex >= 0 && startIndex < immutableArray.Length, "startIndex");
			Requires.Range(count >= 0 && startIndex + count <= immutableArray.Length, "count");
			equalityComparer = equalityComparer ?? EqualityComparer<T>.Default;
			if (equalityComparer == EqualityComparer<T>.Default)
			{
				return Array.IndexOf(immutableArray.array, item, startIndex, count);
			}
			for (int i = startIndex; i < startIndex + count; i++)
			{
				if (equalityComparer.Equals(immutableArray.array[i], item))
				{
					return i;
				}
			}
			return -1;
		}

		public int LastIndexOf(T item)
		{
			ImmutableArray<T> immutableArray = this;
			if (immutableArray.Length == 0)
			{
				return -1;
			}
			return immutableArray.LastIndexOf(item, immutableArray.Length - 1, immutableArray.Length, EqualityComparer<T>.Default);
		}

		public int LastIndexOf(T item, int startIndex)
		{
			ImmutableArray<T> immutableArray = this;
			if (immutableArray.Length == 0 && startIndex == 0)
			{
				return -1;
			}
			return immutableArray.LastIndexOf(item, startIndex, startIndex + 1, EqualityComparer<T>.Default);
		}

		public int LastIndexOf(T item, int startIndex, int count)
		{
			return LastIndexOf(item, startIndex, count, EqualityComparer<T>.Default);
		}

		public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowNullRefIfNotInitialized();
			if (startIndex == 0 && count == 0)
			{
				return -1;
			}
			Requires.Range(startIndex >= 0 && startIndex < immutableArray.Length, "startIndex");
			Requires.Range(count >= 0 && startIndex - count + 1 >= 0, "count");
			equalityComparer = equalityComparer ?? EqualityComparer<T>.Default;
			if (equalityComparer == EqualityComparer<T>.Default)
			{
				return Array.LastIndexOf(immutableArray.array, item, startIndex, count);
			}
			for (int num = startIndex; num >= startIndex - count + 1; num--)
			{
				if (equalityComparer.Equals(item, immutableArray.array[num]))
				{
					return num;
				}
			}
			return -1;
		}

		public bool Contains(T item)
		{
			return IndexOf(item) >= 0;
		}

		public ImmutableArray<T> Insert(int index, T item)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowNullRefIfNotInitialized();
			Requires.Range(index >= 0 && index <= immutableArray.Length, "index");
			if (immutableArray.Length == 0)
			{
				return ImmutableArray.Create(item);
			}
			T[] array = new T[immutableArray.Length + 1];
			array[index] = item;
			if (index != 0)
			{
				Array.Copy(immutableArray.array, array, index);
			}
			if (index != immutableArray.Length)
			{
				Array.Copy(immutableArray.array, index, array, index + 1, immutableArray.Length - index);
			}
			return new ImmutableArray<T>(array);
		}

		public ImmutableArray<T> InsertRange(int index, IEnumerable<T> items)
		{
			ImmutableArray<T> result = this;
			result.ThrowNullRefIfNotInitialized();
			Requires.Range(index >= 0 && index <= result.Length, "index");
			Requires.NotNull(items, "items");
			if (result.Length == 0)
			{
				return ImmutableArray.CreateRange(items);
			}
			int count = ImmutableExtensions.GetCount(ref items);
			if (count == 0)
			{
				return result;
			}
			T[] array = new T[result.Length + count];
			if (index != 0)
			{
				Array.Copy(result.array, array, index);
			}
			if (index != result.Length)
			{
				Array.Copy(result.array, index, array, index + count, result.Length - index);
			}
			if (!items.TryCopyTo(array, index))
			{
				int num = index;
				foreach (T item in items)
				{
					array[num++] = item;
				}
			}
			return new ImmutableArray<T>(array);
		}

		public ImmutableArray<T> InsertRange(int index, ImmutableArray<T> items)
		{
			ImmutableArray<T> result = this;
			result.ThrowNullRefIfNotInitialized();
			items.ThrowNullRefIfNotInitialized();
			Requires.Range(index >= 0 && index <= result.Length, "index");
			if (result.IsEmpty)
			{
				return items;
			}
			if (items.IsEmpty)
			{
				return result;
			}
			T[] array = new T[result.Length + items.Length];
			if (index != 0)
			{
				Array.Copy(result.array, array, index);
			}
			if (index != result.Length)
			{
				Array.Copy(result.array, index, array, index + items.Length, result.Length - index);
			}
			Array.Copy(items.array, 0, array, index, items.Length);
			return new ImmutableArray<T>(array);
		}

		public ImmutableArray<T> Add(T item)
		{
			ImmutableArray<T> immutableArray = this;
			if (immutableArray.Length == 0)
			{
				return ImmutableArray.Create(item);
			}
			return immutableArray.Insert(immutableArray.Length, item);
		}

		public ImmutableArray<T> AddRange(IEnumerable<T> items)
		{
			ImmutableArray<T> immutableArray = this;
			return immutableArray.InsertRange(immutableArray.Length, items);
		}

		public ImmutableArray<T> AddRange(ImmutableArray<T> items)
		{
			ImmutableArray<T> immutableArray = this;
			return immutableArray.InsertRange(immutableArray.Length, items);
		}

		public ImmutableArray<T> SetItem(int index, T item)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowNullRefIfNotInitialized();
			Requires.Range(index >= 0 && index < immutableArray.Length, "index");
			T[] array = new T[immutableArray.Length];
			Array.Copy(immutableArray.array, array, immutableArray.Length);
			array[index] = item;
			return new ImmutableArray<T>(array);
		}

		public ImmutableArray<T> Replace(T oldValue, T newValue)
		{
			return Replace(oldValue, newValue, EqualityComparer<T>.Default);
		}

		public ImmutableArray<T> Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer)
		{
			ImmutableArray<T> immutableArray = this;
			int num = immutableArray.IndexOf(oldValue, 0, immutableArray.Length, equalityComparer);
			if (num < 0)
			{
				throw new ArgumentException(System.SR.CannotFindOldValue, "oldValue");
			}
			return immutableArray.SetItem(num, newValue);
		}

		public ImmutableArray<T> Remove(T item)
		{
			return Remove(item, EqualityComparer<T>.Default);
		}

		public ImmutableArray<T> Remove(T item, IEqualityComparer<T>? equalityComparer)
		{
			ImmutableArray<T> result = this;
			result.ThrowNullRefIfNotInitialized();
			int num = result.IndexOf(item, 0, result.Length, equalityComparer);
			if (num >= 0)
			{
				return result.RemoveAt(num);
			}
			return result;
		}

		public ImmutableArray<T> RemoveAt(int index)
		{
			return RemoveRange(index, 1);
		}

		public ImmutableArray<T> RemoveRange(int index, int length)
		{
			ImmutableArray<T> result = this;
			result.ThrowNullRefIfNotInitialized();
			Requires.Range(index >= 0 && index <= result.Length, "index");
			Requires.Range(length >= 0 && index + length <= result.Length, "length");
			if (length == 0)
			{
				return result;
			}
			T[] array = new T[result.Length - length];
			Array.Copy(result.array, array, index);
			Array.Copy(result.array, index + length, array, index, result.Length - index - length);
			return new ImmutableArray<T>(array);
		}

		public ImmutableArray<T> RemoveRange(IEnumerable<T> items)
		{
			return RemoveRange(items, EqualityComparer<T>.Default);
		}

		public ImmutableArray<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowNullRefIfNotInitialized();
			Requires.NotNull(items, "items");
			SortedSet<int> sortedSet = new SortedSet<int>();
			foreach (T item in items)
			{
				int num = immutableArray.IndexOf(item, 0, immutableArray.Length, equalityComparer);
				while (num >= 0 && !sortedSet.Add(num) && num + 1 < immutableArray.Length)
				{
					num = immutableArray.IndexOf(item, num + 1, equalityComparer);
				}
			}
			return immutableArray.RemoveAtRange(sortedSet);
		}

		public ImmutableArray<T> RemoveRange(ImmutableArray<T> items)
		{
			return RemoveRange(items, EqualityComparer<T>.Default);
		}

		public ImmutableArray<T> RemoveRange(ImmutableArray<T> items, IEqualityComparer<T>? equalityComparer)
		{
			ImmutableArray<T> result = this;
			Requires.NotNull(items.array, "items");
			if (items.IsEmpty)
			{
				result.ThrowNullRefIfNotInitialized();
				return result;
			}
			if (items.Length == 1)
			{
				return result.Remove(items[0], equalityComparer);
			}
			return result.RemoveRange(items.array, equalityComparer);
		}

		public ImmutableArray<T> RemoveAll(Predicate<T> match)
		{
			ImmutableArray<T> result = this;
			result.ThrowNullRefIfNotInitialized();
			Requires.NotNull(match, "match");
			if (result.IsEmpty)
			{
				return result;
			}
			List<int> list = null;
			for (int i = 0; i < result.array.Length; i++)
			{
				if (match(result.array[i]))
				{
					if (list == null)
					{
						list = new List<int>();
					}
					list.Add(i);
				}
			}
			if (list == null)
			{
				return result;
			}
			return result.RemoveAtRange(list);
		}

		public ImmutableArray<T> Clear()
		{
			return Empty;
		}

		public ImmutableArray<T> Sort()
		{
			ImmutableArray<T> immutableArray = this;
			return immutableArray.Sort(0, immutableArray.Length, Comparer<T>.Default);
		}

		public ImmutableArray<T> Sort(Comparison<T> comparison)
		{
			Requires.NotNull(comparison, "comparison");
			ImmutableArray<T> immutableArray = this;
			return immutableArray.Sort(Comparer<T>.Create(comparison));
		}

		public ImmutableArray<T> Sort(IComparer<T>? comparer)
		{
			ImmutableArray<T> immutableArray = this;
			return immutableArray.Sort(0, immutableArray.Length, comparer);
		}

		public ImmutableArray<T> Sort(int index, int count, IComparer<T>? comparer)
		{
			ImmutableArray<T> result = this;
			result.ThrowNullRefIfNotInitialized();
			Requires.Range(index >= 0, "index");
			Requires.Range(count >= 0 && index + count <= result.Length, "count");
			if (count > 1)
			{
				if (comparer == null)
				{
					comparer = Comparer<T>.Default;
				}
				bool flag = false;
				for (int i = index + 1; i < index + count; i++)
				{
					if (comparer.Compare(result.array[i - 1], result.array[i]) > 0)
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					T[] array = new T[result.Length];
					Array.Copy(result.array, array, result.Length);
					Array.Sort(array, index, count, comparer);
					return new ImmutableArray<T>(array);
				}
			}
			return result;
		}

		public IEnumerable<TResult> OfType<TResult>()
		{
			ImmutableArray<T> immutableArray = this;
			if (immutableArray.array == null || immutableArray.array.Length == 0)
			{
				return Enumerable.Empty<TResult>();
			}
			return immutableArray.array.OfType<TResult>();
		}

		void IList<T>.Insert(int index, T item)
		{
			throw new NotSupportedException();
		}

		void IList<T>.RemoveAt(int index)
		{
			throw new NotSupportedException();
		}

		void ICollection<T>.Add(T item)
		{
			throw new NotSupportedException();
		}

		void ICollection<T>.Clear()
		{
			throw new NotSupportedException();
		}

		bool ICollection<T>.Remove(T item)
		{
			throw new NotSupportedException();
		}

		IImmutableList<T> IImmutableList<T>.Clear()
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.Clear();
		}

		IImmutableList<T> IImmutableList<T>.Add(T value)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.Add(value);
		}

		IImmutableList<T> IImmutableList<T>.AddRange(IEnumerable<T> items)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.AddRange(items);
		}

		IImmutableList<T> IImmutableList<T>.Insert(int index, T element)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.Insert(index, element);
		}

		IImmutableList<T> IImmutableList<T>.InsertRange(int index, IEnumerable<T> items)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.InsertRange(index, items);
		}

		IImmutableList<T> IImmutableList<T>.Remove(T value, IEqualityComparer<T> equalityComparer)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.Remove(value, equalityComparer);
		}

		IImmutableList<T> IImmutableList<T>.RemoveAll(Predicate<T> match)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.RemoveAll(match);
		}

		IImmutableList<T> IImmutableList<T>.RemoveRange(IEnumerable<T> items, IEqualityComparer<T> equalityComparer)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.RemoveRange(items, equalityComparer);
		}

		IImmutableList<T> IImmutableList<T>.RemoveRange(int index, int count)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.RemoveRange(index, count);
		}

		IImmutableList<T> IImmutableList<T>.RemoveAt(int index)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.RemoveAt(index);
		}

		IImmutableList<T> IImmutableList<T>.SetItem(int index, T value)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.SetItem(index, value);
		}

		IImmutableList<T> IImmutableList<T>.Replace(T oldValue, T newValue, IEqualityComparer<T> equalityComparer)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.Replace(oldValue, newValue, equalityComparer);
		}

		int IList.Add(object value)
		{
			throw new NotSupportedException();
		}

		void IList.Clear()
		{
			throw new NotSupportedException();
		}

		bool IList.Contains(object value)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.Contains((T)value);
		}

		int IList.IndexOf(object value)
		{
			ImmutableArray<T> immutableArray = this;
			immutableArray.ThrowInvalidOperationIfNotInitialized();
			return immutableArray.IndexOf((T)value);
		}

		void IList.Insert(int index, object val

System.Memory.dll

Decompiled 10 months 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.28619.01")]
[assembly: AssemblyInformationalVersion("4.6.28619.01 @BuiltBy: dlab14-DDVSOWINAGE069 @Branch: release/2.1 @SrcCode: https://github.com/dotnet/corefx/tree/7601f4f6225089ffb291dc7d58293c7bbf5c5d4f")]
[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 value2 = 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)) && (value2.High < 429496729 || (value2.High == 429496729 && (value2.Mid < 2576980377u || (value2.Mid == 2576980377u && (value2.Low < 2576980377u || (value2.Low == 2576980377u && *ptr <= 53)))))))
				{
					DecimalDecCalc.DecMul10(ref value2);
					if (*ptr != 0)
					{
						DecimalDecCalc.DecAddInt32(ref value2, (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 value2, 1u);
						if ((value2.High | value2.Mid | value2.Low) == 0)
						{
							value2.High = 429496729u;
							value2.Mid = 2576980377u;
							value2.Low = 2576980378u;
							num++;
						}
					}
				}
			}
			if (num > 0)
			{
				return false;
			}
			if (num <= -29)
			{
				value2.High = 0u;
				value2.Low = 0u;
				value2.Mid = 0u;
				value2.Scale = 28;
			}
			else
			{
				value2.Scale = -num;
			}
			value2.IsNegative = number.IsNegative;
			value = System.Runtime.CompilerServices.Unsafe.As<MutableDecimal, decimal>(ref value2);
			return true;
		}

		public static void DecimalToNumber(decimal value, ref NumberBuffer number)
		{
			ref MutableDecimal reference = ref System.Runtime.CompilerServices.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>(System.Runtime.CompilerServices.Unsafe.AsPointer<byte>(ref _b0), 51);

		public unsafe byte* UnsafeDigits => (byte*)System.Runtime.CompilerServices.Unsafe.AsPointer<byte>(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>(System.Runtime.CompilerServices.Unsafe.As<Pinnable<T>>((object)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 System.Runtime.CompilerServices.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 = System.Runtime.CompilerServices.Unsafe.Add<T>((void*)handle.AddrOfPinnedObject(), _index);
				return new MemoryHandle(pointer, handle);
			}
			if (_object is T[] array)
			{
				if (_length < 0)
				{
					void* pointer2 = System.Runtime.CompilerServices.Unsafe.Add<T>(System.Runtime.CompilerServices.Unsafe.AsPointer<T>(ref MemoryMarshal.GetReference<T>(array)), _index);
					return new MemoryHandle(pointer2);
				}
				GCHandle handle2 = GCHandle.Alloc(array, GCHandleType.Pinned);
				void* pointer3 = System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value), span.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.IndexOf(ref System.Runtime.CompilerServices.Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value), span.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.LastIndexOf(ref System.Runtime.CompilerServices.Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)), other.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.SequenceCompareTo(ref System.Runtime.CompilerServices.Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value), span.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.IndexOf(ref System.Runtime.CompilerServices.Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value), span.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.LastIndexOf(ref System.Runtime.CompilerServices.Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value0), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value0), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value1), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value0), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value0), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value1), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value0), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value0), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value1), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value0), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value0), System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value1), System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)), other.Length);
			}
			if (typeof(T) == typeof(char))
			{
				return System.SpanHelpers.SequenceCompareTo(ref System.Runtime.CompilerServices.Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)), span.Length, ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), ref System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref System.Runtime.CompilerServices.Unsafe.Add<T>(ref MemoryMarshal.GetReference(span), length - length2)), ref System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), (NUInt)length2 * size);
				}
				return false;
			}
			if (length2 <= length)
			{
				return System.SpanHelpers.SequenceEqual(ref System.Runtime.CompilerServices.Unsafe.Add<T>(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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref System.Runtime.CompilerServices.Unsafe.Add<T>(ref MemoryMarshal.GetReference(span), length - length2)), ref System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)), (NUInt)length2 * size);
				}
				return false;
			}
			if (length2 <= length)
			{
				return System.SpanHelpers.SequenceEqual(ref System.Runtime.CompilerServices.Unsafe.Add<T>(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 = System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, num);
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, num) = System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, num2);
				System.Runtime.CompilerServices.Unsafe.Add<T>(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 = System.Runtime.CompilerServices.Unsafe.ByteOffset<T>(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other));
			if (System.Runtime.CompilerServices.Unsafe.SizeOf<IntPtr>() == 4)
			{
				if ((uint)(int)intPtr >= (uint)(span.Length * System.Runtime.CompilerServices.Unsafe.SizeOf<T>()))
				{
					return (uint)(int)intPtr > (uint)(-(other.Length * System.Runtime.CompilerServices.Unsafe.SizeOf<T>()));
				}
				return true;
			}
			if ((ulong)(long)intPtr >= (ulong)((long)span.Length * (long)System.Runtime.CompilerServices.Unsafe.SizeOf<T>()))
			{
				return (ulong)(long)intPtr > (ulong)(-((long)other.Length * (long)System.Runtime.CompilerServices.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 = System.Runtime.CompilerServices.Unsafe.ByteOffset<T>(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other));
			if (System.Runtime.CompilerServices.Unsafe.SizeOf<IntPtr>() == 4)
			{
				if ((uint)(int)intPtr < (uint)(span.Length * System.Runtime.CompilerServices.Unsafe.SizeOf<T>()) || (uint)(int)intPtr > (uint)(-(other.Length * System.Runtime.CompilerServices.Unsafe.SizeOf<T>())))
				{
					if ((int)intPtr % System.Runtime.CompilerServices.Unsafe.SizeOf<T>() != 0)
					{
						System.ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch();
					}
					elementOffset = (int)intPtr / System.Runtime.CompilerServices.Unsafe.SizeOf<T>();
					return true;
				}
				elementOffset = 0;
				return false;
			}
			if ((ulong)(long)intPtr < (ulong)((long)span.Length * (long)System.Runtime.CompilerServices.Unsafe.SizeOf<T>()) || (ulong)(long)intPtr > (ulong)(-((long)other.Length * (long)System.Runtime.CompilerServices.Unsafe.SizeOf<T>())))
			{
				if ((long)intPtr % System.Runtime.CompilerServices.Unsafe.SizeOf<T>() != 0L)
				{
					System.ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch();
				}
				elementOffset = (int)((long)intPtr / System.Runtime.CompilerServices.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>(System.Runtime.CompilerServices.Unsafe.As<Pinnable<char>>((object)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>(System.Runtime.CompilerServices.Unsafe.As<Pinnable<char>>((object)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>(System.Runtime.CompilerServices.Unsafe.As<Pinnable<char>>((object)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* ptr = text)
			{
				return System.Runtime.CompilerServices.Unsafe.ByteOffset<char>(ref System.Runtime.CompilerServices.Unsafe.As<Pinnable<char>>((object)text).Data, ref System.Runtime.CompilerServices.Unsafe.AsRef<char>((void*)ptr));
			}
		}
	}
	[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>(System.Runtime.CompilerServices.Unsafe.As<Pinnable<T>>((object)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 = System.Runtime.CompilerServices.Unsafe.Add<T>((void*)handle.AddrOfPinnedObject(), _index);
				return new MemoryHandle(pointer, handle);
			}
			if (_object is T[] array)
			{
				if (_length < 0)
				{
					void* pointer2 = System.Runtime.CompilerServices.Unsafe.Add<T>(System.Runtime.CompilerServices.Unsafe.AsPointer<T>(ref MemoryMarshal.GetReference<T>(array)), _index);
					return new MemoryHandle(pointer2);
				}
				GCHandle handle2 = GCHandle.Alloc(array, GCHandleType.Pinned);
				void* pointer3 = System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.Add<T>(ref System.Runtime.CompilerServices.Unsafe.AsRef<T>(byteOffset.ToPointer()), index);
				}
				return ref System.Runtime.CompilerServices.Unsafe.Add<T>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset<T>(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 = System.Runtime.CompilerServices.Unsafe.As<Pinnable<T>>((object)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 = System.Runtime.CompilerServices.Unsafe.As<Pinnable<T>>((object)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 System.Runtime.CompilerServices.Unsafe.AsRef<T>(byteOffset.ToPointer());
				}
				return ref System.Runtime.CompilerServices.Unsafe.AddByteOffset<T>(ref _pinnable.Data, _byteOffset);
			}
			return ref System.Runtime.CompilerServices.Unsafe.AsRef<T>((void*)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 System.Runtime.CompilerServices.Unsafe.AreSame<T>(ref left.DangerousGetPinnableReference(), ref right.DangerousGetPinnableReference());
			}
			return false;
		}

		public unsafe override string ToString()
		{
			if (typeof(T) == typeof(char))
			{
				if (_byteOffset == MemoryExtensions.StringAdjustment)
				{
					object obj = System.Runtime.CompilerServices.Unsafe.As<object>((object)_pinnable);
					if (obj is string text && _length == text.Length)
					{
						return text;
					}
				}
				fixed (char* value = &System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.AsRef<T>(byteOffset.ToPointer());
			}
			return ref System.Runtime.CompilerServices.Unsafe.AddByteOffset<T>(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 System.Runtime.CompilerServices.Unsafe.Add<T>(ref System.Runtime.CompilerServices.Unsafe.AsRef<T>(byteOffset.ToPointer()), index);
				}
				return ref System.Runtime.CompilerServices.Unsafe.Add<T>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset<T>(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 = System.Runtime.CompilerServices.Unsafe.As<Pinnable<T>>((object)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>(System.Runtime.CompilerServices.Unsafe.As<Pinnable<T>>((object)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 = System.Runtime.CompilerServices.Unsafe.As<Pinnable<T>>((object)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 System.Runtime.CompilerServices.Unsafe.AsRef<T>(byteOffset.ToPointer());
				}
				return ref System.Runtime.CompilerServices.Unsafe.AddByteOffset<T>(ref _pinnable.Data, _byteOffset);
			}
			return ref System.Runtime.CompilerServices.Unsafe.AsRef<T>((void*)null);
		}

		public unsafe void Clear()
		{
			int length = _length;
			if (length == 0)
			{
				return;
			}
			UIntPtr byteLength = (UIntPtr)(ulong)((uint)length * System.Runtime.CompilerServices.Unsafe.SizeOf<T>());
			if ((System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset<T>(ref _pinnable.Data, _byteOffset)), byteLength);
				}
			}
			else if (System.SpanHelpers.IsReferenceOrContainsReferences<T>())
			{
				UIntPtr pointerSizeLength = (UIntPtr)(ulong)(length * System.Runtime.CompilerServices.Unsafe.SizeOf<T>() / sizeof(IntPtr));
				System.SpanHelpers.ClearPointerSizedWithReferences(ref System.Runtime.CompilerServices.Unsafe.As<T, IntPtr>(ref DangerousGetPinnableReference()), pointerSizeLength);
			}
			else
			{
				System.SpanHelpers.ClearPointerSizedWithoutReferences(ref System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref DangerousGetPinnableReference()), byteLength);
			}
		}

		public unsafe void Fill(T value)
		{
			int length = _length;
			if (length == 0)
			{
				return;
			}
			if (System.Runtime.CompilerServices.Unsafe.SizeOf<T>() == 1)
			{
				byte b = System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref value);
				if (_pinnable == null)
				{
					IntPtr byteOffset = _byteOffset;
					System.Runtime.CompilerServices.Unsafe.InitBlockUnaligned(byteOffset.ToPointer(), b, (uint)length);
				}
				else
				{
					System.Runtime.CompilerServices.Unsafe.InitBlockUnaligned(ref System.Runtime.CompilerServices.Unsafe.As<T, byte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset<T>(ref _pinnable.Data, _byteOffset)), b, (uint)length);
				}
				return;
			}
			ref T reference = ref DangerousGetPinnableReference();
			int i;
			for (i = 0; i < (length & -8); i += 8)
			{
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 1) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 2) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 3) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 4) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 5) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 6) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 7) = value;
			}
			if (i < (length & -4))
			{
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 1) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 2) = value;
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, i + 3) = value;
				i += 4;
			}
			for (; i < length; i++)
			{
				System.Runtime.CompilerServices.Unsafe.Add<T>(ref reference, 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 System.Runtime.CompilerServices.Unsafe.AreSame<T>(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 = &System.Runtime.CompilerServices.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 System.Runtime.CompilerServices.Unsafe.AsRef<T>(byteOffset.ToPointer());
			}
			return ref System.Runtime.CompilerServices.Unsafe.AddByteOffset<T>(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 System.Runtime.CompilerServices.Unsafe.ByteOffset<T>(ref System.Runtime.CompilerServices.Unsafe.As<Pinnable<T>>((object)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(System.Runtime.CompilerServices.Unsafe.Add<T>(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 System.Runtime.CompilerServices.Unsafe.Add<byte>(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 System.Runtime.CompilerServices.Unsafe.Add<byte>(ref searchSpace, num2), value2, num3);
				if (num4 == -1)
				{
					break;
				}
				num2 += num4;
				if (SequenceEqual(ref System.Runtime.CompilerServices.Unsafe.Add<byte>(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, System.Runtime.CompilerServices.Unsafe.Add<byte>(ref value, i), searchSpaceLength);
				if ((uint)num2 < (uint)num)
				{
					num = num2;
					searchSpaceLength = num2;
					if (num == 0)
					{
						break;
					}
				}

System.Numerics.Vectors.dll

Decompiled 10 months 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.26515.06")]
[assembly: AssemblyInformationalVersion("4.6.26515.06 @BuiltBy: dlab-DDVSOWINAGE059 @Branch: release/2.1 @SrcCode: https://github.com/dotnet/corefx/tree/30ab651fcb4354552bd4891619a0bdd81e0ebdbf")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("PreferInbox", "True")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.1.4.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 Pow(float x, float y)
		{
			return (float)Math.Pow(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 static ResourceManager ResourceManager => s_resourceManager ?? (s_resourceManager = new ResourceManager(ResourceType));

		internal static Type ResourceType { get; } = typeof(SR);


		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 string Arg_InsufficientNumberOfElements => GetResourceString("Arg_InsufficientNumberOfElements", null);

		[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.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Field, Inherited = false)]
	internal sealed class IntrinsicAttribute : Attribute
	{
	}
}
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;
		}
	}
	[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;
	}
	[System.Runtime.CompilerServices.Intrinsic]
	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> s_zero = default(Vector<T>);

		private static readonly Vector<T> s_one = new Vector<T>(GetOneValue());

		private static readonly Vector<T> s_allOnes = new Vector<T>(GetAllBitsSetValue());

		public static int Count
		{
			[System.Runtime.CompilerServices.Intrinsic]
			get
			{
				return s_count;
			}
		}

		public static Vector<T> Zero
		{
			[System.Runtime.CompilerServices.Intrinsic]
			get
			{
				return s_zero;
			}
		}

		public static Vector<T> One
		{
			[System.Runtime.CompilerServices.Intrinsic]
			get
			{
				return s_one;
			}
		}

		internal static Vector<T> AllOnes => s_allOnes;

		public unsafe T this[int index]
		{
			[System.Runtime.CompilerServices.Intrinsic]
			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;
		}

		[System.Runtime.CompilerServices.Intrinsic]
		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;
			}
		}

		[System.Runtime.CompilerServices.Intrinsic]
		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(System.SR.Format(System.SR.Arg_InsufficientNumberOfElements, Count, "values"));
			}
			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;
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public void CopyTo(T[] destination)
		{
			CopyTo(destination, 0);
		}

		[System.Runtime.CompilerServices.Intrinsic]
		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);
		}

		[System.Runtime.CompilerServices.Intrinsic]
		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)(uint)Count];
					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)(uint)Count];
					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)(uint)Count];
					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)(uint)Count];
					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)(uint)Count];
					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)(uint)Count];
					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)(uint)Count];
					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)(uint)Count];
					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;
		}

		[System.Runtime.CompilerServices.Intrinsic]
		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;
		}

		[System.Runtime.CompilerServices.Intrinsic]
		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;
		}

		[System.Runtime.CompilerServices.Intrinsic]
		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 s_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);
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<byte>(Vector<T> value)
		{
			return new Vector<byte>(ref value.register);
		}

		[CLSCompliant(false)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<sbyte>(Vector<T> value)
		{
			return new Vector<sbyte>(ref value.register);
		}

		[CLSCompliant(false)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<ushort>(Vector<T> value)
		{
			return new Vector<ushort>(ref value.register);
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<short>(Vector<T> value)
		{
			return new Vector<short>(ref value.register);
		}

		[CLSCompliant(false)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<uint>(Vector<T> value)
		{
			return new Vector<uint>(ref value.register);
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<int>(Vector<T> value)
		{
			return new Vector<int>(ref value.register);
		}

		[CLSCompliant(false)]
		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<ulong>(Vector<T> value)
		{
			return new Vector<ulong>(ref value.register);
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<long>(Vector<T> value)
		{
			return new Vector<long>(ref value.register);
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<float>(Vector<T> value)
		{
			return new Vector<float>(ref value.register);
		}

		[System.Runtime.CompilerServices.Intrinsic]
		public static explicit operator Vector<double>(Vector<T> value)
		{
			return new Vector<double>(ref value.register);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Compile

System.Runtime.CompilerServices.Unsafe.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Microsoft.CodeAnalysis;

[assembly: AssemblyProduct("Microsoft® .NET Framework")]
[assembly: CLSCompliant(false)]
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyDescription("System.Runtime.CompilerServices.Unsafe")]
[assembly: AssemblyFileVersion("6.0.21.52210")]
[assembly: AssemblyInformationalVersion("6.0.0")]
[assembly: AssemblyTitle("System.Runtime.CompilerServices.Unsafe")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyMetadata("IsTrimmable", "True")]
[assembly: AssemblyCopyright("© Microsoft Corporation.  All rights reserved.")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyVersion("6.0.0.0")]
namespace System.Runtime.CompilerServices
{
	public static class Unsafe
	{
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static T Read<T>(void* source)
		{
			return Unsafe.Read<T>(source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static T ReadUnaligned<T>(void* source)
		{
			return Unsafe.ReadUnaligned<T>(source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static T ReadUnaligned<T>(ref byte source)
		{
			return Unsafe.ReadUnaligned<T>(ref source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void Write<T>(void* destination, T value)
		{
			Unsafe.Write(destination, value);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void WriteUnaligned<T>(void* destination, T value)
		{
			Unsafe.WriteUnaligned(destination, value);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void WriteUnaligned<T>(ref byte destination, T value)
		{
			Unsafe.WriteUnaligned(ref destination, value);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void Copy<T>(void* destination, ref T source)
		{
			Unsafe.Write(destination, source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void Copy<T>(ref T destination, void* source)
		{
			destination = Unsafe.Read<T>(source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void* AsPointer<T>(ref T value)
		{
			return Unsafe.AsPointer(ref value);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void SkipInit<T>(out T value)
		{
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static int SizeOf<T>()
		{
			return Unsafe.SizeOf<T>();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void CopyBlock(void* destination, void* source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlock(destination, source, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void CopyBlock(ref byte destination, ref byte source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlock(ref destination, ref source, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void CopyBlockUnaligned(void* destination, void* source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlockUnaligned(destination, source, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void CopyBlockUnaligned(ref byte destination, ref byte source, uint byteCount)
		{
			// IL cpblk instruction
			Unsafe.CopyBlockUnaligned(ref destination, ref source, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void InitBlock(void* startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlock(startAddress, value, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void InitBlock(ref byte startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlock(ref startAddress, value, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void InitBlockUnaligned(void* startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlockUnaligned(startAddress, value, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static void InitBlockUnaligned(ref byte startAddress, byte value, uint byteCount)
		{
			// IL initblk instruction
			Unsafe.InitBlockUnaligned(ref startAddress, value, byteCount);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static T As<T>(object o) where T : class
		{
			return (T)o;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static ref T AsRef<T>(void* source)
		{
			return ref *(T*)source;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T AsRef<T>(in T source)
		{
			return ref source;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref TTo As<TFrom, TTo>(ref TFrom source)
		{
			return ref Unsafe.As<TFrom, TTo>(ref source);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Unbox<T>(object box) where T : struct
		{
			return ref (T)box;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Add<T>(ref T source, int elementOffset)
		{
			return ref Unsafe.Add(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void* Add<T>(void* source, int elementOffset)
		{
			return (byte*)source + (nint)elementOffset * (nint)Unsafe.SizeOf<T>();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Add<T>(ref T source, IntPtr elementOffset)
		{
			return ref Unsafe.Add(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ref T Add<T>(ref T source, [System.Runtime.Versioning.NonVersionable] nuint elementOffset)
		{
			return ref Unsafe.Add(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T AddByteOffset<T>(ref T source, IntPtr byteOffset)
		{
			return ref Unsafe.AddByteOffset(ref source, byteOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ref T AddByteOffset<T>(ref T source, [System.Runtime.Versioning.NonVersionable] nuint byteOffset)
		{
			return ref Unsafe.AddByteOffset(ref source, byteOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Subtract<T>(ref T source, int elementOffset)
		{
			return ref Unsafe.Subtract(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static void* Subtract<T>(void* source, int elementOffset)
		{
			return (byte*)source - (nint)elementOffset * (nint)Unsafe.SizeOf<T>();
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T Subtract<T>(ref T source, IntPtr elementOffset)
		{
			return ref Unsafe.Subtract(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ref T Subtract<T>(ref T source, [System.Runtime.Versioning.NonVersionable] nuint elementOffset)
		{
			return ref Unsafe.Subtract(ref source, elementOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static ref T SubtractByteOffset<T>(ref T source, IntPtr byteOffset)
		{
			return ref Unsafe.SubtractByteOffset(ref source, byteOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static ref T SubtractByteOffset<T>(ref T source, [System.Runtime.Versioning.NonVersionable] nuint byteOffset)
		{
			return ref Unsafe.SubtractByteOffset(ref source, byteOffset);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static IntPtr ByteOffset<T>(ref T origin, ref T target)
		{
			return Unsafe.ByteOffset(target: ref target, origin: ref origin);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static bool AreSame<T>(ref T left, ref T right)
		{
			return Unsafe.AreSame(ref left, ref right);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static bool IsAddressGreaterThan<T>(ref T left, ref T right)
		{
			return Unsafe.IsAddressGreaterThan(ref left, ref right);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public static bool IsAddressLessThan<T>(ref T left, ref T right)
		{
			return Unsafe.IsAddressLessThan(ref left, ref right);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static bool IsNullRef<T>(ref T source)
		{
			return Unsafe.AsPointer(ref source) == null;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[System.Runtime.Versioning.NonVersionable]
		public unsafe static ref T NullRef<T>()
		{
			return ref *(T*)null;
		}
	}
}
namespace System.Runtime.Versioning
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
	internal sealed class NonVersionableAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	[Microsoft.CodeAnalysis.Embedded]
	[CompilerGenerated]
	internal sealed class NativeIntegerAttribute : Attribute
	{
		public readonly bool[] TransformFlags;

		public NativeIntegerAttribute()
		{
			TransformFlags = new bool[1] { true };
		}

		public NativeIntegerAttribute(bool[] A_0)
		{
			TransformFlags = A_0;
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}